Skip to content

Commit 7970765

Browse files
committed
wstring: add new test cases for TRIM, LTRIM, RTRIM when used with WSTRING
1 parent e53c036 commit 7970765

File tree

4 files changed

+717
-474
lines changed

4 files changed

+717
-474
lines changed

tests/wstring/chk-wstring.bi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#macro CU_ASSERT_WSTRING_EQUAL( a, b )
4+
5+
'' length check
6+
CU_ASSERT( len(a) = len(b) )
7+
8+
'' comparison check
9+
CU_ASSERT_EQUAL(a, b)
10+
11+
'' byte-by-byte check
12+
scope
13+
if(len(a) = len(b)) then
14+
do
15+
for i as integer = 0 to len(a) - 1
16+
if(a[i] <> b[i]) then
17+
CU_FAIL()
18+
exit do
19+
end if
20+
next
21+
CU_PASS()
22+
loop until true
23+
end if
24+
end scope
25+
26+
#endmacro

tests/wstring/ltrim.bas

Lines changed: 230 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,258 @@
11
#include "fbcunit.bi"
2+
#include once "chk-wstring.bi"
23

34
SUITE( fbc_tests.wstring_.ltrim_ )
45

5-
dim shared result as integer
6-
dim shared str_ret as wstring*32
7-
8-
TEST( test1 )
9-
10-
str_ret = ltrim(wstr("asd"))
11-
CU_ASSERT( len(str_ret) = 3 )
12-
result = str_ret = "asd"
13-
CU_ASSERT( result )
14-
15-
str_ret = ltrim(wstr(" asd"))
16-
CU_ASSERT( len(str_ret) = 3 )
17-
result = str_ret = "asd"
18-
CU_ASSERT( result )
19-
20-
str_ret = ltrim(wstr(" asd"))
21-
CU_ASSERT( len(str_ret) = 3 )
22-
result = str_ret = "asd"
23-
CU_ASSERT( result )
24-
6+
#macro check( a, length, expected )
7+
scope
8+
dim wr as wstring * 50 = ltrim( wstr(a) )
9+
dim we as wstring * 50 = wstr( expected )
10+
11+
CU_ASSERT( len(wr) = length )
12+
CU_ASSERT_WSTRING_EQUAL( wr, we )
13+
end scope
14+
15+
scope
16+
dim wa as wstring * 50 = wstr(a)
17+
dim we as wstring * 50 = wstr( expected )
18+
dim wr as wstring * 50 = ltrim( wa )
19+
20+
CU_ASSERT( len(wr) = length )
21+
CU_ASSERT_WSTRING_EQUAL( wr, we )
22+
end scope
23+
#endmacro
24+
25+
#macro check_filter( a, filter, length, expected )
26+
scope
27+
dim wr as wstring * 50 = ltrim( wstr(a), wstr(filter) )
28+
dim we as wstring * 50 = wstr( expected )
29+
30+
CU_ASSERT( len(wr) = length )
31+
CU_ASSERT_WSTRING_EQUAL( wr, we )
32+
end scope
33+
34+
scope
35+
dim wa as wstring * 50 = wstr(a)
36+
dim wf as wstring * 50 = wstr(filter)
37+
dim wr as wstring * 50 = ltrim( wa, wf )
38+
dim we as wstring * 50 = wstr( expected )
39+
40+
CU_ASSERT( len(wr) = length )
41+
CU_ASSERT_WSTRING_EQUAL( wr, we )
42+
end scope
43+
#endmacro
44+
45+
#macro check_filter_any( a, filter, length, expected )
46+
scope
47+
dim wr as wstring * 50 = ltrim( wstr(a), any wstr(filter) )
48+
dim we as wstring * 50 = wstr( expected )
49+
50+
CU_ASSERT( len(wr) = length )
51+
CU_ASSERT_WSTRING_EQUAL( wr, we )
52+
end scope
53+
54+
scope
55+
dim wa as wstring * 50 = wstr(a)
56+
dim wf as wstring * 50 = wstr(filter)
57+
dim wr as wstring * 50 = ltrim( wa, any wf )
58+
dim we as wstring * 50 = wstr( expected )
59+
60+
CU_ASSERT( len(wr) = length )
61+
CU_ASSERT_WSTRING_EQUAL( wr, we )
62+
end scope
63+
#endmacro
64+
65+
TEST( default )
66+
check( "" , 0, "" )
67+
check( " " , 0, "" )
68+
check( " " , 0, "" )
69+
check( "asd" , 3, "asd" )
70+
check( "asd " , 4, "asd " )
71+
check( "asd " , 5, "asd " )
72+
check( " asd" , 3, "asd" )
73+
check( " asd" , 3, "asd" )
74+
check( " asd " , 4, "asd " )
75+
check( " asd ", 5, "asd " )
2576
END_TEST
2677

27-
TEST( test2 )
28-
29-
str_ret = ltrim(wstr("asd"), wstr("x"))
30-
CU_ASSERT( len(str_ret) = 3 )
31-
result = str_ret = "asd"
32-
CU_ASSERT( result )
33-
34-
str_ret = ltrim(wstr("xasd"), wstr("x"))
35-
CU_ASSERT( len(str_ret) = 3 )
36-
result = str_ret = "asd"
37-
CU_ASSERT( result )
38-
39-
str_ret = ltrim(wstr("xxasd"), wstr("x"))
40-
CU_ASSERT( len(str_ret) = 3 )
41-
result = str_ret = "asd"
42-
CU_ASSERT( result )
43-
78+
TEST( filter )
79+
check_filter( "" , "" , 0, "" )
80+
check_filter( "" , " " , 0, "" )
81+
check_filter( "" , " ", 0, "" )
82+
check_filter( " " , "" , 1, " " )
83+
check_filter( " " , " " , 0, "" )
84+
check_filter( " " , " ", 1, " " )
85+
check_filter( " " , "" , 2, " " )
86+
check_filter( " " , " " , 0, "" )
87+
check_filter( " " , " ", 0, "" )
88+
89+
check_filter( "asd" , " ", 3, "asd" )
90+
check_filter( "asd " , " ", 4, "asd " )
91+
check_filter( "asd " , " ", 5, "asd " )
92+
check_filter( " asd" , " ", 3, "asd" )
93+
check_filter( " asd" , " ", 3, "asd" )
94+
check_filter( " asd " , " ", 4, "asd " )
95+
check_filter( " asd ", " ", 5, "asd " )
96+
97+
check_filter( "" , "x", 0, "" )
98+
check_filter( " " , "x", 1, " " )
99+
check_filter( "x" , "x", 0, "" )
100+
check_filter( "xx" , "x", 0, "" )
101+
check_filter( "asd" , "x", 3, "asd" )
102+
check_filter( "asdx" , "x", 4, "asdx" )
103+
check_filter( "asdxx" , "x", 5, "asdxx" )
104+
check_filter( "xasd" , "x", 3, "asd" )
105+
check_filter( "xxasd" , "x", 3, "asd" )
106+
check_filter( "xasdx" , "x", 4, "asdx" )
107+
check_filter( "xxasdxx", "x", 5, "asdxx" )
108+
109+
check_filter( "" , "xy", 0, "" )
110+
check_filter( "xy" , "xy", 0, "" )
111+
check_filter( "xyxy" , "xy", 0, "" )
112+
check_filter( "xyxyx" , "xy", 1, "x" )
113+
check_filter( "yxyxy" , "xy", 5, "yxyxy" )
114+
115+
check_filter( "asd" , "xy", 3, "asd" )
116+
check_filter( "asdx" , "xy", 4, "asdx" )
117+
check_filter( "asdxy" , "xy", 5, "asdxy" )
118+
check_filter( "asdxy" , "yx", 5, "asdxy" )
119+
check_filter( "asdyy" , "yx", 5, "asdyy" )
120+
121+
check_filter( "xasd" , "xy", 4, "xasd" )
122+
check_filter( "xyasd" , "xy", 3, "asd" )
123+
check_filter( "xyasd" , "yx", 5, "xyasd" )
124+
check_filter( "yyasd" , "yx", 5, "yyasd" )
125+
126+
check_filter( "xasdx" , "xy", 5, "xasdx" )
127+
check_filter( "xyasdxy", "xy", 5, "asdxy" )
128+
check_filter( "xyasdxy", "yx", 7, "xyasdxy" )
129+
check_filter( "yyasdyy", "yx", 7, "yyasdyy" )
44130
END_TEST
45131

46-
TEST( test3 )
47-
48-
str_ret = ltrim(wstr("asd"), wstr("xy"))
49-
CU_ASSERT( len(str_ret) = 3 )
50-
result = str_ret = "asd"
51-
CU_ASSERT( result )
52-
53-
str_ret = ltrim(wstr("xasd"), wstr("xy"))
54-
CU_ASSERT( len(str_ret) = 4 )
55-
result = str_ret = "xasd"
56-
CU_ASSERT( result )
57-
58-
str_ret = ltrim(wstr("xyasd"), wstr("xy"))
59-
CU_ASSERT( len(str_ret) = 3 )
60-
result = str_ret = "asd"
61-
CU_ASSERT( result )
62-
63-
str_ret = ltrim(wstr("xyasd"), wstr("yx"))
64-
CU_ASSERT( len(str_ret) = 5 )
65-
result = str_ret = "xyasd"
66-
CU_ASSERT( result )
67-
68-
str_ret = ltrim(wstr("yyasd"), wstr("yx"))
69-
CU_ASSERT( len(str_ret) = 5 )
70-
result = str_ret = "yyasd"
71-
CU_ASSERT( result )
72132

133+
TEST( filter_any )
134+
check_filter_any( "" , "" , 0, "" )
135+
check_filter_any( "" , " " , 0, "" )
136+
check_filter_any( "" , " ", 0, "" )
137+
check_filter_any( " " , "" , 1, " " )
138+
check_filter_any( " " , " " , 0, "" )
139+
check_filter_any( " " , " ", 0, "" )
140+
check_filter_any( " " , "" , 2, " " )
141+
check_filter_any( " " , " " , 0, "" )
142+
check_filter_any( " " , " ", 0, "" )
143+
144+
145+
check_filter_any( "asd" , " ", 3, "asd" )
146+
check_filter_any( "asd " , " ", 4, "asd " )
147+
check_filter_any( "asd " , " ", 5, "asd " )
148+
check_filter_any( " asd" , " ", 3, "asd" )
149+
check_filter_any( " asd" , " ", 3, "asd" )
150+
check_filter_any( " asd " , " ", 4, "asd " )
151+
check_filter_any( " asd ", " ", 5, "asd " )
152+
153+
check_filter_any( "" , "x", 0, "" )
154+
check_filter_any( " " , "x", 1, " " )
155+
check_filter_any( "x" , "x", 0, "" )
156+
check_filter_any( "xx" , "x", 0, "" )
157+
check_filter_any( "asd" , "x", 3, "asd" )
158+
check_filter_any( "asdx" , "x", 4, "asdx" )
159+
check_filter_any( "asdxx" , "x", 5, "asdxx" )
160+
check_filter_any( "xasd" , "x", 3, "asd" )
161+
check_filter_any( "xxasd" , "x", 3, "asd" )
162+
check_filter_any( "xasdx" , "x", 4, "asdx" )
163+
check_filter_any( "xxasdxx", "x", 5, "asdxx" )
164+
165+
check_filter_any( "" , "xy", 0, "" )
166+
check_filter_any( "x" , "xy", 0, "" )
167+
check_filter_any( "y" , "xy", 0, "" )
168+
check_filter_any( "xy" , "xy", 0, "" )
169+
check_filter_any( "xyxy" , "xy", 0, "" )
170+
check_filter_any( "xyxyx" , "xy", 0, "" )
171+
check_filter_any( "yxyxy" , "xy", 0, "" )
172+
173+
check_filter_any( "asd" , "xy", 3, "asd" )
174+
check_filter_any( "asdx" , "xy", 4, "asdx" )
175+
check_filter_any( "asdxy" , "xy", 5, "asdxy" )
176+
check_filter_any( "asdxy" , "yx", 5, "asdxy" )
177+
check_filter_any( "asdyy" , "yx", 5, "asdyy" )
178+
179+
check_filter_any( "xasd" , "" , 4, "xasd" )
180+
check_filter_any( "xyasd" , "xy", 3, "asd" )
181+
check_filter_any( "xyasd" , "yx", 3, "asd" )
182+
check_filter_any( "yyasd" , "yx", 3, "asd" )
183+
184+
check_filter_any( "xasdx" , "xy", 4, "asdx" )
185+
check_filter_any( "xyasdxy", "xy", 5, "asdxy" )
186+
check_filter_any( "xyasdxy", "yx", 5, "asdxy" )
187+
check_filter_any( "yyasdyy", "yx", 5, "asdyy" )
188+
189+
check_filter_any( "asd" , " d", 3, "asd" )
190+
check_filter_any( "asd " , " d", 4, "asd " )
191+
check_filter_any( "asd " , " d", 5, "asd " )
192+
check_filter_any( "das" , " d", 2, "as" )
193+
check_filter_any( " das" , " d", 2, "as" )
194+
check_filter_any( " das" , " d", 2, "as" )
195+
check_filter_any( "dasd" , " d", 3, "asd" )
196+
check_filter_any( " dasd " , " d", 4, "asd " )
197+
check_filter_any( " dasd ", " d", 5, "asd " )
198+
check_filter_any( "asd" , "d ", 3, "asd" )
199+
check_filter_any( "asd " , "d ", 4, "asd " )
200+
check_filter_any( "asd " , "d ", 5, "asd " )
201+
check_filter_any( "das" , "d ", 2, "as" )
202+
check_filter_any( " das" , "d ", 2, "as" )
203+
check_filter_any( " das" , "d ", 2, "as" )
204+
check_filter_any( "dasd" , "d ", 3, "asd" )
205+
check_filter_any( " dasd " , "d ", 4, "asd " )
206+
check_filter_any( " dasd ", "d ", 5, "asd " )
73207
END_TEST
74208

75-
TEST( test4 )
209+
TEST( escaped )
210+
check( !"\u3041\u3043\u3045\u3047\u3049" , 5, !"\u3041\u3043\u3045\u3047\u3049" )
211+
check( !" \u3041\u3043\u3045\u3047\u3049" , 5, !"\u3041\u3043\u3045\u3047\u3049" )
212+
check( !"\u3041\u3043\u3045\u3047\u3049 " , 7, !"\u3041\u3043\u3045\u3047\u3049 " )
213+
check( !" \u3041\u3043\u3045\u3047\u3049 ", 7, !"\u3041\u3043\u3045\u3047\u3049 " )
76214

77-
str_ret = ltrim(wstr("asd"), any wstr(" "))
78-
CU_ASSERT( len(str_ret) = 3 )
79-
result = str_ret = "asd"
80-
CU_ASSERT( result )
215+
check_filter( !"\u3041\u3043\u3045\u3047\u3049", !"\u3041", _
216+
4, !"\u3043\u3045\u3047\u3049" )
81217

82-
str_ret = ltrim(wstr(" asd"), any wstr(" "))
83-
CU_ASSERT( len(str_ret) = 3 )
84-
result = str_ret = "asd"
85-
CU_ASSERT( result )
218+
check_filter( !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043", _
219+
3, !"\u3045\u3047\u3049" )
86220

87-
str_ret = ltrim(wstr(" asd"), any wstr(" "))
88-
CU_ASSERT( len(str_ret) = 3 )
89-
result = str_ret = "asd"
90-
CU_ASSERT( result )
221+
check_filter( !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3041", _
222+
5, !"\u3041\u3043\u3045\u3047\u3049" )
91223

92-
END_TEST
224+
check_filter( !"\u3041\u3043\u3045\u3047\u3049", !"\u3049", _
225+
5, !"\u3041\u3043\u3045\u3047\u3049" )
93226

94-
TEST( test5 )
227+
check_filter( !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049", _
228+
5, !"\u3041\u3043\u3045\u3047\u3049" )
95229

96-
str_ret = ltrim(wstr("asd"), any wstr(" a"))
97-
CU_ASSERT( len(str_ret) = 2 )
98-
result = str_ret = "sd"
99-
CU_ASSERT( result )
230+
check_filter( !"\u3041\u3043\u3045\u3047\u3049", !"\u3049\u3047", _
231+
5, !"\u3041\u3043\u3045\u3047\u3049" )
100232

101-
str_ret = ltrim(wstr(" asd"), any wstr(" a"))
102-
CU_ASSERT( len(str_ret) = 2 )
103-
result = str_ret = "sd"
104-
CU_ASSERT( result )
233+
check_filter( !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3049", _
234+
5, !"\u3041\u3043\u3045\u3047\u3049" )
105235

106-
str_ret = ltrim(wstr(" asd"), any wstr(" a"))
107-
CU_ASSERT( len(str_ret) = 2 )
108-
result = str_ret = "sd"
109-
CU_ASSERT( result )
236+
check_filter_any( !"\u3041\u3043\u3045\u3047\u3049", !"\u3041", _
237+
4, !"\u3043\u3045\u3047\u3049" )
110238

111-
END_TEST
239+
check_filter_any( !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3043", _
240+
3, !"\u3045\u3047\u3049" )
112241

113-
TEST( test6 )
242+
check_filter_any( !"\u3041\u3043\u3045\u3047\u3049", !"\u3043\u3041", _
243+
3, !"\u3045\u3047\u3049" )
114244

115-
str_ret = ltrim(wstr("asd"), any wstr("a "))
116-
CU_ASSERT( len(str_ret) = 2 )
117-
result = str_ret = "sd"
118-
CU_ASSERT( result )
245+
check_filter_any( !"\u3041\u3043\u3045\u3047\u3049", !"\u3049", _
246+
5, !"\u3041\u3043\u3045\u3047\u3049" )
119247

120-
str_ret = ltrim(wstr(" asd"), any wstr("a "))
121-
CU_ASSERT( len(str_ret) = 2 )
122-
result = str_ret = "sd"
123-
CU_ASSERT( result )
248+
check_filter_any( !"\u3041\u3043\u3045\u3047\u3049", !"\u3047\u3049", _
249+
5, !"\u3041\u3043\u3045\u3047\u3049" )
124250

125-
str_ret = ltrim(wstr(" asd"), any wstr("a "))
126-
CU_ASSERT( len(str_ret) = 2 )
127-
result = str_ret = "sd"
128-
CU_ASSERT( result )
251+
check_filter_any( !"\u3041\u3043\u3045\u3047\u3049", !"\u3049\u3047", _
252+
5, !"\u3041\u3043\u3045\u3047\u3049" )
129253

254+
check_filter_any( !"\u3041\u3043\u3045\u3047\u3049", !"\u3041\u3049", _
255+
4, !"\u3043\u3045\u3047\u3049" )
130256
END_TEST
131257

132258
END_SUITE

0 commit comments

Comments
 (0)