コード例 #1
0
    def test_should_return_false_for_non_string_objects(self):
        # noinspection PyTypeChecker
        self.assertFalse(is_camel_case(None))

        # noinspection PyTypeChecker
        self.assertFalse(is_camel_case(False))

        # noinspection PyTypeChecker
        self.assertFalse(is_camel_case(0))

        # noinspection PyTypeChecker
        self.assertFalse(is_camel_case([]))

        # noinspection PyTypeChecker
        self.assertFalse(is_camel_case({'a': 1}))
コード例 #2
0
def generate_aliases(strings: List[str]) -> Dict[str, str]:
    """
    generate a set of aliases from the given set of strings.



    :param strings:
    :return:
    """
    result = {}
    for option in strings:
        if string_utils.is_camel_case(option):
            # fetch the first an all the uppercase characters to generate the alias
            alias: str = option[0] + ''.join(filter(lambda x: x.isupper(), option))
        elif string_utils.is_snake_case(option, "_"):
            # TODO implement
            raise NotImplementedError()
        elif option.islower() and re.match(r"^[a-z0-9]+$", option):
            # ok maybe it's camel case of snake case but it contains only one word (e.g., run), HENCE
            # we need to handle words like "algorithm" or "run" which are special case
            # of camel case (they do not have upper letters)
            alias: str = option.lower()[0]
        else:
            raise ValueError(f"option \"{option}\" is not neither camelcase nor snakecase!")
        alias = alias.lower()
        result[option] = alias
    return result
コード例 #3
0
ファイル: __init__.py プロジェクト: simonemmott/k2_util
def to_camel_case(s):
    if not su.is_string(s):
        return s
    if not su.is_full_string(s):
        return s
    if su.is_camel_case(s):
        return s[0].lower()+s[1:]
    return su.snake_case_to_camel(re.sub('^[0-9_]+', '', to_snake_case(s)), upper_case_first=False)
コード例 #4
0
def to_class_case(s):
    if not su.is_string(s):
        return s
    if not su.is_full_string(s):
        return s
    if su.is_camel_case(s):
        return s[0].upper() + s[1:]
    sub = re.sub('^[0-9_]+', '', to_snake_case(s))
    camel = su.snake_case_to_camel(sub)
    return camel[0].upper() + camel[1:]
コード例 #5
0
 def test_should_accept_valid_camel_case_string(self):
     self.assertTrue(is_camel_case('Camel'))
     self.assertTrue(is_camel_case('CamelCase'))
     self.assertTrue(is_camel_case('camelCase'))
     self.assertTrue(is_camel_case('CamelCaseTOO'))
     self.assertTrue(is_camel_case('ACamelCaseIsAlsoAStringLikeThis1'))
     self.assertTrue(is_camel_case('camelCaseStartingLowerEndingUPPER'))
コード例 #6
0
ファイル: __init__.py プロジェクト: simonemmott/k2_util
def to_class_case(s):
    if not su.is_string(s):
        logger.debug('{s} is not a string'.format(s=s))
        return s
    if not su.is_full_string(s):
        logger.debug('string is blank'.format(s=s))
        return s
    if su.is_camel_case(s):
        logger.debug('string is already camel case'.format(s=s))
        return s[0].upper()+s[1:]
    sub = re.sub('^[0-9_]+', '', to_snake_case(s))
    logger.debug('sub = {sub}'.format(sub=sub))
    camel = su.snake_case_to_camel(sub)
    return camel[0].upper()+camel[1:]
コード例 #7
0
def get_valid_class_name(name: str):
    name = name.replace(" ", "_")
    name = string_utils.snake_case_to_camel(name)
    if not string_utils.is_camel_case(name):
        name = name.capitalize()

    # SADL function name fix
    if name == 'sum':
        name = 'c_' + name

    first_char_ord = ord(name[0])
    if 48 <= first_char_ord <= 57:
        name = "c_" + name

    return name
コード例 #8
0
 def test_string_cannot_contain_invalid_chars(self):
     self.assertFalse(is_camel_case('<#NotCamelCaseHere!?>'))
コード例 #9
0
 def test_string_cannot_start_with_number(self):
     self.assertFalse(is_camel_case('1000Times'))
コード例 #10
0
 def test_string_cannot_contain_spaces(self):
     self.assertFalse(is_camel_case(' CamelCase '))
コード例 #11
0
 def test_string_cannot_be_all_uppercase(self):
     self.assertFalse(is_camel_case('UPPERCASE'))
コード例 #12
0
 def test_string_cannot_be_all_lowercase(self):
     self.assertFalse(is_camel_case('lowercase'))
コード例 #13
0
 def test_string_cannot_be_empty(self):
     self.assertFalse(is_camel_case(''))
     self.assertFalse(is_camel_case(' '))