Some checks failed
Test before pr merge / test-lint (pull_request) Failing after 9s
74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
import pytest
|
|
from cpl.core.utils import String
|
|
|
|
|
|
def test_to_camel_case():
|
|
assert String.to_camel_case("hello world") == "helloWorld"
|
|
assert String.to_camel_case("hello-world") == "helloWorld"
|
|
assert String.to_camel_case("hello_world") == "helloWorld"
|
|
assert String.to_camel_case("HelloWorld") == "helloWorld"
|
|
assert String.to_camel_case("hello world") == "helloWorld"
|
|
assert String.to_camel_case("") == ""
|
|
assert String.to_camel_case(" ") == ""
|
|
assert String.to_camel_case("123-abc") == "123Abc"
|
|
|
|
|
|
def test_to_pascal_case():
|
|
assert String.to_pascal_case("hello world") == "HelloWorld"
|
|
assert String.to_pascal_case("hello-world") == "HelloWorld"
|
|
assert String.to_pascal_case("hello_world") == "HelloWorld"
|
|
assert String.to_pascal_case("helloWorld") == "HelloWorld"
|
|
assert String.to_pascal_case("") == ""
|
|
assert String.to_pascal_case(" ") == ""
|
|
assert String.to_pascal_case("123-abc") == "123Abc"
|
|
|
|
|
|
def test_to_snake_case():
|
|
assert String.to_snake_case("HelloWorld") == "hello_world"
|
|
assert String.to_snake_case("helloWorld") == "hello_world"
|
|
assert String.to_snake_case("hello-world") == "hello_world"
|
|
assert String.to_snake_case("hello_world") == "hello_world"
|
|
assert String.to_snake_case("hello world") == "hello_world"
|
|
assert String.to_snake_case("ABC123") == "abc123"
|
|
|
|
|
|
def test_first_to_upper():
|
|
assert String.first_to_upper("hello") == "Hello"
|
|
assert String.first_to_upper("Hello") == "Hello"
|
|
assert String.first_to_upper("") == ""
|
|
assert String.first_to_upper("a") == "A"
|
|
assert String.first_to_upper("123abc") == "123abc"
|
|
|
|
|
|
def test_first_to_lower():
|
|
assert String.first_to_lower("Hello") == "hello"
|
|
assert String.first_to_lower("hello") == "hello"
|
|
assert String.first_to_lower("") == ""
|
|
assert String.first_to_lower("A") == "a"
|
|
assert String.first_to_lower("123ABC") == "123ABC"
|
|
|
|
|
|
def test_random_length():
|
|
random_str = String.random(10)
|
|
assert len(random_str) == 10
|
|
|
|
|
|
def test_random_only_letters():
|
|
random_str = String.random(20, letters=True, digits=False, special_characters=False)
|
|
assert all(c.isalpha() for c in random_str)
|
|
|
|
|
|
def test_random_only_digits():
|
|
random_str = String.random(20, letters=False, digits=True, special_characters=False)
|
|
assert all(c.isdigit() for c in random_str)
|
|
|
|
|
|
def test_random_letters_and_digits():
|
|
random_str = String.random(20, letters=True, digits=True, special_characters=False)
|
|
assert all(c.isalnum() for c in random_str)
|
|
|
|
|
|
def test_random_no_characters():
|
|
with pytest.raises(Exception):
|
|
String.random(10, letters=False, digits=False, special_characters=False)
|