コード例 #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****"