Skip to content

Commit f2fbc61

Browse files
committed
udt-wstring: SELECT statement will accept UDT as Z|WSTRING to return a Z|WSTRING
1 parent aefa43e commit f2fbc61

File tree

5 files changed

+323
-0
lines changed

5 files changed

+323
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Version 1.07.0
2020
- MID statement will accept UDT as Z|WSTRING
2121
- ASC function will accept UDT as Z|WSTRING
2222
- STR/WSTR function will accept UDT as Z|WSTRING to return a Z|WSTRING
23+
- SELECT statement will accept UDT as Z|WSTRING to return a Z|WSTRING
2324

2425
[fixed]
2526
- sf.net #881: C backend: support for varadic function parameters in gcc using __builtin_va_list type and related macros

src/compiler/parser-compound-select.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ sub cSelectStmtBegin( )
9292
expr = astNewCONSTi( 0 )
9393
end if
9494

95+
astTryOvlStringCONV( expr )
96+
9597
'' can't be an UDT
9698
if( astGetDataType( expr ) = FB_DATATYPE_STRUCT ) then
9799
errReport( FB_ERRMSG_INVALIDDATATYPES )

tests/udt-wstring/select.bas

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include "fbcunit.bi"
2+
#include once "uwstring-fixed.bi"
3+
#include once "chk-wstring.bi"
4+
5+
#define ustring UWSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_wstring_.select_ )
8+
9+
#macro check( expr, literal, is_match )
10+
scope
11+
dim w as wstring * 50 = expr
12+
dim u as ustring = w
13+
14+
select case u
15+
case literal
16+
if( is_match ) then
17+
CU_PASS()
18+
else
19+
CU_FAIL()
20+
end if
21+
case else
22+
if( is_match ) then
23+
CU_FAIL()
24+
else
25+
CU_PASS()
26+
end if
27+
end select
28+
end scope
29+
#endmacro
30+
31+
#macro check_range( expr, literal1, literal2, is_match )
32+
scope
33+
dim w as wstring * 50 = expr
34+
dim u as ustring = w
35+
36+
select case u
37+
case literal1 to literal2
38+
if( is_match ) then
39+
CU_PASS()
40+
else
41+
CU_FAIL()
42+
end if
43+
case else
44+
if( is_match ) then
45+
CU_FAIL()
46+
else
47+
CU_PASS()
48+
end if
49+
end select
50+
end scope
51+
#endmacro
52+
53+
TEST( ucs2 )
54+
check( !"\u3041", !"\u3041", true )
55+
check( !"\u3041", !"\u3043", false )
56+
check( !"a\u3041b", !"a\u3041b", true )
57+
check( !"a\u3041b", !"ab", false )
58+
check( !"\u3041\u3043\u3045\u3047\u3049", _ )
59+
!"\u3041\u3043\u3045\u3047\u3049", true )
60+
check( !"\u3041\u3043\u3045\u3047\u3049", _ )
61+
!"\u3041\u3043\u3045\u3047", false )
62+
63+
dim arg as wstring * 50 = !"\u3041\u3043\u3045\u3047\u3049"
64+
check( left( arg, 0 ), "", true )
65+
check( left( arg, 1 ), !"\u3041", true )
66+
check( left( arg, 2 ), !"\u3041\u3043", true )
67+
check( left( arg, 3 ), !"\u3041\u3043\u3045", true )
68+
69+
check( right( arg, 0 ), "", true )
70+
check( right( arg, 1 ), !"\u3049", true )
71+
check( right( arg, 2 ), !"\u3047\u3049", true )
72+
check( right( arg, 3 ), !"\u3045\u3047\u3049", true )
73+
74+
check( mid( arg, 2 ), !"\u3043\u3045\u3047\u3049", true )
75+
check( mid( arg, 3 ), !"\u3045\u3047\u3049", true )
76+
check( mid( arg, 4 ), !"\u3047\u3049", true )
77+
check( mid( arg, 5 ), !"\u3049", true )
78+
79+
check_range( !"\u3043\u3045\u3047\u3049", !"\u3041", !"\u3045", true )
80+
check_range( !"\u3047\u3049", !"\u3041", !"\u3045", false )
81+
END_TEST
82+
83+
TEST( ascii )
84+
check( "0123456789", "0123456789", true )
85+
check( "0123456789", "012345678", false )
86+
check( "abc", "abc", true )
87+
check( "abc", "ABC", false )
88+
89+
dim arg as wstring * 50 = "abcdefghij"
90+
check( left( arg, 0 ), "", true )
91+
check( left( arg, 1 ), "a", true )
92+
check( left( arg, 2 ), "ab", true )
93+
check( left( arg, 3 ), "abc", true )
94+
95+
check( right( arg, 0 ), "", true )
96+
check( right( arg, 1 ), "j", true )
97+
check( right( arg, 2 ), "ij", true )
98+
check( right( arg, 3 ), "hij", true )
99+
100+
check( mid( arg, 2 ), "bcdefghij", true )
101+
check( mid( arg, 3 ), "cdefghij", true )
102+
check( mid( arg, 4 ), "defghij", true )
103+
check( mid( arg, 5 ), "efghij", true )
104+
105+
check_range( "bcd", "b", "c", true )
106+
check_range( "xyz", "b", "c", false )
107+
END_TEST
108+
109+
END_SUITE
110+

tests/udt-zstring/select.bas

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "fbcunit.bi"
2+
#include once "uzstring-fixed.bi"
3+
#include once "chk-zstring.bi"
4+
5+
#define ustring UZSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_zstring_.select_ )
8+
9+
#macro check( expr, literal, is_match )
10+
scope
11+
dim w as zstring * 50 = expr
12+
dim u as ustring = w
13+
14+
select case u
15+
case literal
16+
if( is_match ) then
17+
CU_PASS()
18+
else
19+
CU_FAIL()
20+
end if
21+
case else
22+
if( is_match ) then
23+
CU_FAIL()
24+
else
25+
CU_PASS()
26+
end if
27+
end select
28+
end scope
29+
#endmacro
30+
31+
#macro check_range( expr, literal1, literal2, is_match )
32+
scope
33+
dim w as zstring * 50 = expr
34+
dim u as ustring = w
35+
36+
select case u
37+
case literal1 to literal2
38+
if( is_match ) then
39+
CU_PASS()
40+
else
41+
CU_FAIL()
42+
end if
43+
case else
44+
if( is_match ) then
45+
CU_FAIL()
46+
else
47+
CU_PASS()
48+
end if
49+
end select
50+
end scope
51+
#endmacro
52+
53+
TEST( ascii )
54+
check( "0123456789", "0123456789", true )
55+
check( "0123456789", "012345678", false )
56+
check( "abc", "abc", true )
57+
check( "abc", "ABC", false )
58+
59+
dim arg as zstring * 50 = "abcdefghij"
60+
check( left( arg, 0 ), "", true )
61+
check( left( arg, 1 ), "a", true )
62+
check( left( arg, 2 ), "ab", true )
63+
check( left( arg, 3 ), "abc", true )
64+
65+
check( right( arg, 0 ), "", true )
66+
check( right( arg, 1 ), "j", true )
67+
check( right( arg, 2 ), "ij", true )
68+
check( right( arg, 3 ), "hij", true )
69+
70+
check( mid( arg, 2 ), "bcdefghij", true )
71+
check( mid( arg, 3 ), "cdefghij", true )
72+
check( mid( arg, 4 ), "defghij", true )
73+
check( mid( arg, 5 ), "efghij", true )
74+
75+
check_range( "bcd", "b", "c", true )
76+
check_range( "xyz", "b", "c", false )
77+
END_TEST
78+
79+
END_SUITE
80+

tests/wstring/select.bas

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,136 @@
22

33
SUITE( fbc_tests.wstring_.select_ )
44

5+
#macro check( expr, literal, is_match )
6+
scope
7+
dim w as wstring * 50 = expr
8+
9+
select case w
10+
case literal
11+
if( is_match ) then
12+
CU_PASS()
13+
else
14+
CU_FAIL()
15+
end if
16+
case else
17+
if( is_match ) then
18+
CU_FAIL()
19+
else
20+
CU_PASS()
21+
end if
22+
end select
23+
24+
dim pw as wstring ptr = strptr( w )
25+
select case *pw
26+
case literal
27+
if( is_match ) then
28+
CU_PASS()
29+
else
30+
CU_FAIL()
31+
end if
32+
case else
33+
if( is_match ) then
34+
CU_FAIL()
35+
else
36+
CU_PASS()
37+
end if
38+
end select
39+
end scope
40+
#endmacro
41+
42+
#macro check_range( expr, literal1, literal2, is_match )
43+
scope
44+
dim w as wstring * 50 = expr
45+
46+
select case w
47+
case literal1 to literal2
48+
if( is_match ) then
49+
CU_PASS()
50+
else
51+
CU_FAIL()
52+
end if
53+
case else
54+
if( is_match ) then
55+
CU_FAIL()
56+
else
57+
CU_PASS()
58+
end if
59+
end select
60+
61+
dim pw as wstring ptr = strptr( w )
62+
select case *pw
63+
case literal1 to literal2
64+
if( is_match ) then
65+
CU_PASS()
66+
else
67+
CU_FAIL()
68+
end if
69+
case else
70+
if( is_match ) then
71+
CU_FAIL()
72+
else
73+
CU_PASS()
74+
end if
75+
end select
76+
end scope
77+
#endmacro
78+
79+
TEST( ucs2 )
80+
check( !"\u3041", !"\u3041", true )
81+
check( !"\u3041", !"\u3043", false )
82+
check( !"a\u3041b", !"a\u3041b", true )
83+
check( !"a\u3041b", !"ab", false )
84+
check( !"\u3041\u3043\u3045\u3047\u3049", _ )
85+
!"\u3041\u3043\u3045\u3047\u3049", true )
86+
check( !"\u3041\u3043\u3045\u3047\u3049", _ )
87+
!"\u3041\u3043\u3045\u3047", false )
88+
89+
dim arg as wstring * 50 = !"\u3041\u3043\u3045\u3047\u3049"
90+
check( left( arg, 0 ), "", true )
91+
check( left( arg, 1 ), !"\u3041", true )
92+
check( left( arg, 2 ), !"\u3041\u3043", true )
93+
check( left( arg, 3 ), !"\u3041\u3043\u3045", true )
94+
95+
check( right( arg, 0 ), "", true )
96+
check( right( arg, 1 ), !"\u3049", true )
97+
check( right( arg, 2 ), !"\u3047\u3049", true )
98+
check( right( arg, 3 ), !"\u3045\u3047\u3049", true )
99+
100+
check( mid( arg, 2 ), !"\u3043\u3045\u3047\u3049", true )
101+
check( mid( arg, 3 ), !"\u3045\u3047\u3049", true )
102+
check( mid( arg, 4 ), !"\u3047\u3049", true )
103+
check( mid( arg, 5 ), !"\u3049", true )
104+
105+
check_range( !"\u3043\u3045\u3047\u3049", !"\u3041", !"\u3045", true )
106+
check_range( !"\u3047\u3049", !"\u3041", !"\u3045", false )
107+
END_TEST
108+
109+
TEST( ascii )
110+
check( "0123456789", "0123456789", true )
111+
check( "0123456789", "012345678", false )
112+
check( "abc", "abc", true )
113+
check( "abc", "ABC", false )
114+
115+
dim arg as wstring * 50 = "abcdefghij"
116+
check( left( arg, 0 ), "", true )
117+
check( left( arg, 1 ), "a", true )
118+
check( left( arg, 2 ), "ab", true )
119+
check( left( arg, 3 ), "abc", true )
120+
121+
check( right( arg, 0 ), "", true )
122+
check( right( arg, 1 ), "j", true )
123+
check( right( arg, 2 ), "ij", true )
124+
check( right( arg, 3 ), "hij", true )
125+
126+
check( mid( arg, 2 ), "bcdefghij", true )
127+
check( mid( arg, 3 ), "cdefghij", true )
128+
check( mid( arg, 4 ), "defghij", true )
129+
check( mid( arg, 5 ), "efghij", true )
130+
131+
check_range( "bcd", "b", "c", true )
132+
check_range( "xyz", "b", "c", false )
133+
END_TEST
134+
5135
TEST( default )
6136

7137
dim w as wstring * 10 => "abc"

0 commit comments

Comments
 (0)