Пример #1
0
 def test_camel(self):
     from stringbender import String
     assert String("abc deF_ghi jKl").camel() == "abcDefGhiJkl"
     assert String("abc.deF_ghi jKl").camel() == "abcDefGhiJkl"
     assert String("abc-deF_ghi jKl").camel() == "abcDefGhiJkl"
     assert String("abc deF\\ghi jKl").camel() == "abcDefGhiJkl"
     assert String("abc deF:ghi jKl").camel() == "abcDefGhiJkl"
Пример #2
0
    def test_as_str(self):
        from stringbender import String
        s = String("abc_def")
        s_str = s.as_str()

        assert s_str == "abc_def"
        assert type(s_str) is not String
Пример #3
0
 def test_pascal(self):
     from stringbender import String
     assert String("abc deF_ghi jKl").pascal() == "AbcDeFGhiJKl"
     assert String("abc.deF_ghi jKl").pascal() == "AbcDeFGhiJKl"
     assert String("abc-deF_ghi jKl").pascal() == "AbcDeFGhiJKl"
     assert String("abc deF\\ghi jKl").pascal() == "AbcDeFGhiJKl"
     assert String("abc deF:ghi jKl").pascal() == "AbcDeFGhiJKl"
Пример #4
0
 def test_snake(self):
     from stringbender import String
     assert String("abc deF_ghi jKl").snake() == "abc_de_f_ghi_j_kl"
     assert String("abc.deF_ghi jKl").snake() == "abc_de_f_ghi_j_kl"
     assert String("abc d-eF_ghi jKl").snake() == "abc_d_e_f_ghi_j_kl"
     assert String("abc deF\\ghi jKl").snake() == "abc_de_f_ghi_j_kl"
     assert String("abc deF:ghi jKl").snake() == "abc_de_f_ghi_j_kl"
Пример #5
0
 def test_kebob(self):
     from stringbender import String
     assert String("abc deF_ghi jKl").kebob() == "abc-def-ghi-jkl"
     assert String("abc.deF_ghi jKl").kebob() == "abc-def-ghi-jkl"
     assert String("abc d-eF_ghi jKl").kebob() == "abc-d-ef-ghi-jkl"
     assert String("abc deF\\ghi jKl").kebob() == "abc-def-ghi-jkl"
     assert String("abc deF:ghi jKl").kebob() == "abc-def-ghi-jkl"
Пример #6
0
 def test_removesuffix(self):
     # TODO Install Python 3.9 and test
     import sys
     if sys.version_info >= (3, 9):
         s = String("Say 'hello' to mhy little friend! --Scarface")
         assert s.removeprefix(
             " --Scarface") == "Say 'hello' to my little friend!"
     else:
         assert True
Пример #7
0
 def test_splitlines(self):
     s = String(
         ("Cinderella story. Outta nowhere. A former greenskeeper, now,\n"
          "about to become the Masters champion. It looks like a mirac...\n"
          "It's in the hole! It's in the hole! It's in the hole!"))
     s_splitlines = s.splitlines()
     assert s_splitlines[
         0] == "Cinderella story. Outta nowhere. A former greenskeeper, now,"
     assert s_splitlines[
         1] == "about to become the Masters champion. It looks like a mirac..."
     assert s_splitlines[
         2] == "It's in the hole! It's in the hole! It's in the hole!"
Пример #8
0
 def test_join(self):
     s = String(" ")
     s_joined = s.join(
         ("No", "matter", "where", "you", "go,", "there", "you", "are."))
     assert s_joined == "No matter where you go, there you are."
Пример #9
0
 def test_format_map(self):
     map = {"stooge1": "Larry", "stooge2": "Moe", "stooge3": "Curly"}
     s = String("{stooge1} {stooge2} {stooge3}")
     assert "Larry Moe Curly" == s.format_map(map)
Пример #10
0
 def test_format(self):
     s = String("I want my {price} dollars!")
     assert s.format(price=2) == "I want my 2 dollars!"
Пример #11
0
 def test_expandtabs(self):
     s = String("Bond.\tJames Bond.")
     assert s.expandtabs(10) == "Bond.     James Bond."
Пример #12
0
 def test_lstrip(self):
     s = String("          You talking to me?")
     assert s.lstrip() == "You talking to me?"
Пример #13
0
 def test_capitalize(self):
     s = String("i LOVE the Smell of Napalm in the mOrning.")
     assert s.capitalize() == "I love the smell of napalm in the morning."
Пример #14
0
 def test_zfill(self):
     s = String("3.1417")
     assert s.zfill(10) == "00003.1417"
Пример #15
0
 def test_replace(self):
     s = String("What*we've*got*here*is*a*failure*to*communicate.")
     assert s.replace(
         "*", " ") == "What we've got here is a failure to communicate."
Пример #16
0
 def test_translate(self):
     s = String("God is my copilot")
     assert s.translate({71: 68, 100: 103}) == "Dog is my copilot"
Пример #17
0
 def test_upper(self):
     s = String("They're here!")
     assert s.upper() == "THEY'RE HERE!"
Пример #18
0
 def test_title(self):
     s = String("Is it safe?")
     assert s.title() == "Is It Safe?"
Пример #19
0
 def test_swapcase(self):
     s = String("You're gonna need a bigger boat.")
     assert s.swapcase() == "yOU'RE GONNA NEED A BIGGER BOAT."
Пример #20
0
 def test_strip(self):
     s = String(
         "   I'll get you, my pretty, and your little dog, too!          ")
     assert s.strip(
     ) == "I'll get you, my pretty, and your little dog, too!"
Пример #21
0
 def test_ljust(self):
     s = String("There's no crying in baseball!")
     assert s.ljust(50, "*") == f"{s}********************"
Пример #22
0
 def test_casefold(self):
     s = String("gENTLEMEN, YOU CaN'T FigHT IN HErE! tHIS IS ThE wAR rOOM!")
     assert s.casefold(
     ) == "gentlemen, you can't fight in here! this is the war room!"
Пример #23
0
 def test_lower(self):
     s = String("May the Force be with you.")
     assert s.lower() == "may the force be with you."
Пример #24
0
 def test__mul__(self):
     s = String("*")
     s_1 = s * 10
     assert s_1 == "**********"
Пример #25
0
 def test_partition(self):
     s = String("You've gotta ask yourself a question: 'Do I feel lucky?'")
     s_1, s_2, s_3 = s.partition(": ")
     assert s_1 == "You've gotta ask yourself a question"
     assert s_2 == ": "
     assert s_3 == "'Do I feel lucky?'"
Пример #26
0
 def test__rmul__(self):
     s = String("*")
     s_1 = 10 * s
     assert s_1 == "**********"
Пример #27
0
 def test__add__(self):
     s = String("One plus one")
     assert s.__add__(" does not always equal two."
                      ) == "One plus one does not always equal two."
Пример #28
0
 def test_split(self):
     s = String("I feel the need--the need for speed!")
     s_split = s.split("--")
     assert s_split[0] == "I feel the need"
     assert s_split[1] == "the need for speed!"
Пример #29
0
 def test_rjust(self):
     s = String("Here's Johnny!")
     assert s.rjust(30, "*") == f"****************{s}"
Пример #30
0
 def test_center(self):
     s = String("I'll be back")
     assert s.center(20, "*") == "****I'll be back****"