@@ -35,3 +35,159 @@ func Test_in_slice_with_multiple_one_matched_parameters(t *testing.T) {
3535func Test_in_slice_with_integer (t * testing.T ) {
3636 require .True (t , str .InSlice (1 , 0 , 1 ))
3737}
38+
39+ func Test_After (t * testing.T ) {
40+ // TODO: What if nothing is found?
41+ require .Equal (t , "" , str .After ("" , "" ))
42+ require .Equal (t , "" , str .After ("" , "han" ))
43+ require .Equal (t , "hannah" , str .After ("hannah" , "" ))
44+ require .Equal (t , "nah" , str .After ("hannah" , "han" ))
45+ require .Equal (t , "nah" , str .After ("hannah" , "n" ))
46+ require .Equal (t , "nah" , str .After ("eee hannah" , "han" ))
47+ require .Equal (t , "nah" , str .After ("ééé hannah" , "han" ))
48+ require .Equal (t , "hannah" , str .After ("hannah" , "xxxx" ))
49+ require .Equal (t , "nah" , str .After ("han0nah" , "0" ))
50+ require .Equal (t , "nah" , str .After ("han2nah" , "2" ))
51+ }
52+
53+ func Test_AfterLast (t * testing.T ) {
54+ // TODO: What if nothing is found?
55+ require .Equal (t , "" , str .After ("" , "" ))
56+ require .Equal (t , "" , str .After ("" , "han" ))
57+ require .Equal (t , "hannah" , str .After ("hannah" , "" ))
58+ require .Equal (t , "tte" , str .AfterLast ("yvette" , "yve" ))
59+ require .Equal (t , "e" , str .AfterLast ("yvette" , "t" ))
60+ require .Equal (t , "e" , str .AfterLast ("ééé yvette" , "t" ))
61+ require .Equal (t , "" , str .AfterLast ("yvette" , "tte" ))
62+ require .Equal (t , "yvette" , str .AfterLast ("yvette" , "xxxx" ))
63+ require .Equal (t , "te" , str .AfterLast ("yv0et0te" , "0" ))
64+ require .Equal (t , "te" , str .AfterLast ("yv0et0te" , "0" ))
65+ require .Equal (t , "te" , str .AfterLast ("yv2et2te" , "2" ))
66+ require .Equal (t , "foo" , str .AfterLast ("----foo" , "---" ))
67+ }
68+
69+ func Test_Before (t * testing.T ) {
70+ require .Equal (t , "hannah" , str .Before ("hannah" , "" ))
71+ require .Equal (t , "han" , str .Before ("hannah" , "nah" ))
72+ require .Equal (t , "ha" , str .Before ("hannah" , "n" ))
73+ require .Equal (t , "ééé " , str .Before ("ééé hannah" , "han" ))
74+ require .Equal (t , "hannah" , str .Before ("hannah" , "xxxx" ))
75+ require .Equal (t , "han" , str .Before ("han0nah" , "0" ))
76+ require .Equal (t , "han" , str .Before ("han0nah" , "0" ))
77+ require .Equal (t , "han" , str .Before ("han2nah" , "2" ))
78+ }
79+
80+ func Test_BeforeLast (t * testing.T ) {
81+ require .Equal (t , "yve" , str .BeforeLast ("yvette" , "tte" ))
82+ require .Equal (t , "yvet" , str .BeforeLast ("yvette" , "t" ))
83+ require .Equal (t , "ééé " , str .BeforeLast ("ééé yvette" , "yve" ))
84+ require .Equal (t , "" , str .BeforeLast ("yvette" , "yve" ))
85+ require .Equal (t , "yvette" , str .BeforeLast ("yvette" , "xxxx" ))
86+ require .Equal (t , "yvette" , str .BeforeLast ("yvette" , "" ))
87+ require .Equal (t , "yv0et" , str .BeforeLast ("yv0et0te" , "0" ))
88+ require .Equal (t , "yv0et" , str .BeforeLast ("yv0et0te" , "0" ))
89+ require .Equal (t , "yv2et" , str .BeforeLast ("yv2et2te" , "2" ))
90+ }
91+
92+ func Test_Between (t * testing.T ) {
93+ require .Equal (t , "abc" , str .Between ("abc" , "" , "c" ))
94+ require .Equal (t , "abc" , str .Between ("abc" , "a" , "" ))
95+ require .Equal (t , "abc" , str .Between ("abc" , "" , "" ))
96+ require .Equal (t , "b" , str .Between ("abc" , "a" , "c" ))
97+ require .Equal (t , "b" , str .Between ("dddabc" , "a" , "c" ))
98+ require .Equal (t , "b" , str .Between ("abcddd" , "a" , "c" ))
99+ require .Equal (t , "b" , str .Between ("dddabcddd" , "a" , "c" ))
100+ require .Equal (t , "nn" , str .Between ("hannah" , "ha" , "ah" ))
101+ require .Equal (t , "a]ab[b" , str .Between ("[a]ab[b]" , "[" , "]" ))
102+ require .Equal (t , "foo" , str .Between ("foofoobar" , "foo" , "bar" ))
103+ require .Equal (t , "bar" , str .Between ("foobarbar" , "foo" , "bar" ))
104+ }
105+
106+ func Test_Contains (t * testing.T ) {
107+ require .True (t , str .Contains ("taylor" , "ylo" ))
108+ require .True (t , str .Contains ("taylor" , "taylor" ))
109+ require .False (t , str .Contains ("taylor" , "xxx" ))
110+ require .False (t , str .Contains ("taylor" , "" ))
111+ require .False (t , str .Contains ("" , "" ))
112+ }
113+
114+ func Test_ContainsFromSlice (t * testing.T ) {
115+ require .True (t , str .ContainsFromSlice ("taylor" , []string {"ylo" }))
116+ require .True (t , str .ContainsFromSlice ("taylor" , []string {"xxx" , "ylo" }))
117+ require .False (t , str .ContainsFromSlice ("taylor" , []string {"xxx" }))
118+ require .False (t , str .ContainsFromSlice ("taylor" , []string {}))
119+ require .False (t , str .ContainsFromSlice ("taylor" , []string {"" }))
120+ }
121+
122+ func Test_ContainsAllFromSlice (t * testing.T ) {
123+ require .True (t , str .ContainsAllFromSlice ("This is my name" , []string {"This" , "is" }))
124+ require .True (t , str .ContainsAllFromSlice ("This is my name" , []string {"my" , "ame" }))
125+ require .True (t , str .ContainsAllFromSlice ("taylor" , []string {"tay" , "ylo" }))
126+ require .False (t , str .ContainsAllFromSlice ("taylor" , []string {"xxx" , "ylo" }))
127+ require .False (t , str .ContainsAllFromSlice ("taylor" , []string {"xxx" , "tay" }))
128+ require .False (t , str .ContainsAllFromSlice ("This is my name" , []string {"are" , "name" }))
129+ require .False (t , str .ContainsAllFromSlice ("taylor" , []string {}))
130+ require .False (t , str .ContainsAllFromSlice ("taylor" , []string {"" , "" }))
131+ }
132+
133+ func Test_EndsWith (t * testing.T ) {
134+ require .True (t , str .EndsWith ("This is my name" , "name" ))
135+ require .True (t , str .EndsWith ("This is my name" , "e" ))
136+ require .True (t , str .EndsWith ("jason" , "on" ))
137+ require .True (t , str .EndsWith ("7" , "7" ))
138+ require .True (t , str .EndsWith ("a7" , "7" ))
139+ require .False (t , str .EndsWith ("jason" , "no" ))
140+ require .False (t , str .EndsWith ("jason" , "" ))
141+ require .False (t , str .EndsWith ("" , "" ))
142+ // Test for multibyte string support
143+ require .True (t , str .EndsWith ("Jönköping" , "öping" ))
144+ require .True (t , str .EndsWith ("Malmö" , "mö" ))
145+ require .True (t , str .EndsWith ("Malmö" , "mö" ))
146+ require .False (t , str .EndsWith ("Jönköping" , "oping" ))
147+ require .False (t , str .EndsWith ("Malmö" , "mo" ))
148+ require .True (t , str .EndsWith ("你好" , "好" ))
149+ require .False (t , str .EndsWith ("你好" , "你" ))
150+ require .False (t , str .EndsWith ("你好" , "a" ))
151+ }
152+
153+ func Test_StartsWith (t * testing.T ) {
154+ require .True (t , str .StartsWith ("jason" , "jas" ))
155+ require .True (t , str .StartsWith ("jason" , "jason" ))
156+ require .True (t , str .StartsWith ("7a" , "7" ))
157+ require .True (t , str .StartsWith ("7" , "7" ))
158+ require .False (t , str .StartsWith ("jason" , "J" ))
159+ require .False (t , str .StartsWith ("jason" , "" ))
160+ require .False (t , str .StartsWith ("" , "" ))
161+ // Test for multibyte string support
162+ require .True (t , str .StartsWith ("Jönköping" , "Jö" ))
163+ require .True (t , str .StartsWith ("Malmö" , "Malmö" ))
164+ require .True (t , str .StartsWith ("你好" , "你" ))
165+ require .False (t , str .StartsWith ("Jönköping" , "Jonko" ))
166+ require .False (t , str .StartsWith ("Malmö" , "Malmo" ))
167+ require .False (t , str .StartsWith ("你好" , "好" ))
168+ require .False (t , str .StartsWith ("你好" , "a" ))
169+ }
170+
171+ func Test_Lower (t * testing.T ) {
172+ require .Equal (t , "foo bar baz" , str .Lower ("FOO BAR BAZ" ))
173+ require .Equal (t , "foo bar baz" , str .Lower ("fOo Bar bAz" ))
174+ }
175+
176+ func Test_Upper (t * testing.T ) {
177+ require .Equal (t , "FOO BAR BAZ" , str .Upper ("foo bar baz" ))
178+ require .Equal (t , "FOO BAR BAZ" , str .Upper ("fOo Bar bAZ" ))
179+ }
180+
181+ func Test_Finish (t * testing.T ) {
182+ require .Equal (t , "abbc" , str .Finish ("ab" , "bc" ))
183+ require .Equal (t , "abbc" , str .Finish ("abbcbc" , "bc" ))
184+ require .Equal (t , "abcbbc" , str .Finish ("abcbbcbc" , "bc" ))
185+ require .Equal (t , "this/string/" , str .Finish ("this/string" , "/" ))
186+ require .Equal (t , "this/string/" , str .Finish ("this/string/" , "/" ))
187+ }
188+
189+ func Test_Start (t * testing.T ) {
190+ require .Equal (t , "/test/string" , str .Start ("test/string" , "/" ))
191+ require .Equal (t , "/test/string" , str .Start ("/test/string" , "/" ))
192+ require .Equal (t , "/test/string" , str .Start ("//test/string" , "/" ))
193+ }
0 commit comments