#157 #165
@ -37,9 +37,19 @@ class String:
|
|||||||
String converted to snake_case
|
String converted to snake_case
|
||||||
"""
|
"""
|
||||||
# convert to train-case to CamelCase
|
# convert to train-case to CamelCase
|
||||||
|
if "_" in chars:
|
||||||
|
chars = chars.replace("_", "-")
|
||||||
|
|
||||||
if "-" in chars:
|
if "-" in chars:
|
||||||
chars = "".join(word.title() for word in chars.split("-"))
|
chars = "".join(word.title() for word in chars.split("-"))
|
||||||
|
|
||||||
|
if " " in chars:
|
||||||
|
new_chars = ""
|
||||||
|
for word in chars.split(" "):
|
||||||
|
new_chars += String.first_to_upper(word)
|
||||||
|
|
||||||
|
chars = new_chars
|
||||||
|
|
||||||
pattern1 = re.compile(r"(.)([A-Z][a-z]+)")
|
pattern1 = re.compile(r"(.)([A-Z][a-z]+)")
|
||||||
pattern2 = re.compile(r"([a-z0-9])([A-Z])")
|
pattern2 = re.compile(r"([a-z0-9])([A-Z])")
|
||||||
file_name = re.sub(pattern1, r"\1_\2", chars)
|
file_name = re.sub(pattern1, r"\1_\2", chars)
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
|
||||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
|
||||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
|
||||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
|
||||||
|
|
||||||
|
|
||||||
class TestStartup_extension(StartupExtensionABC):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
|
||||||
pass
|
|
@ -1,10 +1,58 @@
|
|||||||
|
import string
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from cpl_core.utils import String
|
||||||
|
|
||||||
|
|
||||||
class StringTestCase(unittest.TestCase):
|
class StringTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_equal(self):
|
def test_convert_to_camel_case(self):
|
||||||
pass
|
expected = "HelloWorld"
|
||||||
|
|
||||||
|
self.assertEqual(expected, String.convert_to_camel_case("hello-world"))
|
||||||
|
self.assertEqual(expected, String.convert_to_camel_case("hello_world"))
|
||||||
|
self.assertEqual("helloWorld", String.convert_to_camel_case("helloWorld"))
|
||||||
|
self.assertEqual(expected, String.convert_to_camel_case("Hello_world"))
|
||||||
|
self.assertEqual(expected, String.convert_to_camel_case("Hello_World"))
|
||||||
|
self.assertEqual(expected, String.convert_to_camel_case("hello world"))
|
||||||
|
|
||||||
|
def test_convert_to_snake_case(self):
|
||||||
|
expected = "hello_world"
|
||||||
|
|
||||||
|
self.assertEqual(expected, String.convert_to_snake_case("Hello World"))
|
||||||
|
self.assertEqual(expected, String.convert_to_snake_case("hello-world"))
|
||||||
|
self.assertEqual(expected, String.convert_to_snake_case("hello_world"))
|
||||||
|
self.assertEqual(expected, String.convert_to_snake_case("helloWorld"))
|
||||||
|
self.assertEqual(expected, String.convert_to_snake_case("Hello_world"))
|
||||||
|
self.assertEqual(expected, String.convert_to_snake_case("Hello_World"))
|
||||||
|
self.assertEqual(expected, String.convert_to_snake_case("hello world"))
|
||||||
|
|
||||||
|
def test_first_to_upper(self):
|
||||||
|
expected = "HelloWorld"
|
||||||
|
|
||||||
|
self.assertEqual(expected, String.first_to_upper("helloWorld"))
|
||||||
|
self.assertEqual(expected, String.first_to_upper("HelloWorld"))
|
||||||
|
|
||||||
|
def test_first_to_lower(self):
|
||||||
|
expected = "helloWorld"
|
||||||
|
|
||||||
|
self.assertEqual(expected, String.first_to_lower("helloWorld"))
|
||||||
|
self.assertEqual(expected, String.first_to_lower("HelloWorld"))
|
||||||
|
|
||||||
|
def test_random_string(self):
|
||||||
|
expected = ""
|
||||||
|
|
||||||
|
for x in range(0, 100):
|
||||||
|
rstr = String.random_string(string.ascii_letters, 4)
|
||||||
|
self.assertNotEqual(expected, rstr)
|
||||||
|
self.assertEqual(4, len(rstr))
|
||||||
|
expected = rstr
|
||||||
|
|
||||||
|
for x in range(0, 100):
|
||||||
|
rstr = String.random_string(string.ascii_letters, 16)
|
||||||
|
self.assertNotEqual(expected, rstr)
|
||||||
|
self.assertEqual(16, len(rstr))
|
||||||
|
expected = rstr
|
||||||
|
Loading…
Reference in New Issue
Block a user