|
2 | 2 |
|
3 | 3 | SUITE( fbc_tests.wstring_.select_ ) |
4 | 4 |
|
| 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 | + |
5 | 135 | TEST( default ) |
6 | 136 |
|
7 | 137 | dim w as wstring * 10 => "abc" |
|
0 commit comments