Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 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"
Exemplo n.º 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"
Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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."
Exemplo n.º 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)
Exemplo n.º 10
0
 def test_format(self):
     s = String("I want my {price} dollars!")
     assert s.format(price=2) == "I want my 2 dollars!"
Exemplo n.º 11
0
 def test_expandtabs(self):
     s = String("Bond.\tJames Bond.")
     assert s.expandtabs(10) == "Bond.     James Bond."
Exemplo n.º 12
0
 def test_lstrip(self):
     s = String("          You talking to me?")
     assert s.lstrip() == "You talking to me?"
Exemplo n.º 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."
Exemplo n.º 14
0
 def test_zfill(self):
     s = String("3.1417")
     assert s.zfill(10) == "00003.1417"
Exemplo n.º 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."
Exemplo n.º 16
0
 def test_translate(self):
     s = String("God is my copilot")
     assert s.translate({71: 68, 100: 103}) == "Dog is my copilot"
Exemplo n.º 17
0
 def test_upper(self):
     s = String("They're here!")
     assert s.upper() == "THEY'RE HERE!"
Exemplo n.º 18
0
 def test_title(self):
     s = String("Is it safe?")
     assert s.title() == "Is It Safe?"
Exemplo n.º 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."
Exemplo n.º 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!"
Exemplo n.º 21
0
 def test_ljust(self):
     s = String("There's no crying in baseball!")
     assert s.ljust(50, "*") == f"{s}********************"
Exemplo n.º 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!"
Exemplo n.º 23
0
 def test_lower(self):
     s = String("May the Force be with you.")
     assert s.lower() == "may the force be with you."
Exemplo n.º 24
0
 def test__mul__(self):
     s = String("*")
     s_1 = s * 10
     assert s_1 == "**********"
Exemplo n.º 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?'"
Exemplo n.º 26
0
 def test__rmul__(self):
     s = String("*")
     s_1 = 10 * s
     assert s_1 == "**********"
Exemplo n.º 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."
Exemplo n.º 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!"
Exemplo n.º 29
0
 def test_rjust(self):
     s = String("Here's Johnny!")
     assert s.rjust(30, "*") == f"****************{s}"
Exemplo n.º 30
0
 def test_center(self):
     s = String("I'll be back")
     assert s.center(20, "*") == "****I'll be back****"