-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTest.bb
More file actions
157 lines (128 loc) · 4.23 KB
/
Copy pathStringTest.bb
File metadata and controls
157 lines (128 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Strict
EnableGC
; Acceptance suite for the string standard library.
; Each block proves one documented contract with exact literal expectations.
; No block performs an operation documented to potentially hang.
; --- Replace: empty `from` must terminate and return s unchanged (criterion 1) ---
Test ReplaceEmptyFromTest()
Assert( Replace("hello", "", "x") = "hello" )
Assert( Replace("hello", "", "") = "hello" )
; Empty source string with empty from must also terminate and return unchanged.
Assert( Replace("", "", "x") = "" )
End Test
; --- Replace: normal match / no match (criterion 2) ---
Test ReplaceMatchTest()
; Every occurrence replaced.
Assert( Replace("aaa", "a", "b") = "bbb" )
Assert( Replace("hello world", "o", "0") = "hell0 w0rld" )
Assert( Replace("ababab", "ab", "X") = "XXX" )
End Test
Test ReplaceNoMatchTest()
Assert( Replace("hello", "z", "Q") = "hello" )
Assert( Replace("hello", "xyz", "Q") = "hello" )
End Test
; --- Left / Right / Mid boundaries (criterion 3) ---
Test LeftBoundaryTest()
Assert( Left("abc", 2) = "ab" )
Assert( Left("abc", 3) = "abc" )
; n past end returns whole string.
Assert( Left("abc", 10) = "abc" )
Assert( Left("abc", 0) = "" )
End Test
Test RightBoundaryTest()
Assert( Right("abc", 2) = "bc" )
Assert( Right("abc", 3) = "abc" )
; n past end returns whole string.
Assert( Right("abc", 10) = "abc" )
Assert( Right("abc", 0) = "" )
End Test
Test MidBoundaryTest()
; Default count (-1) means "to end of string".
Assert( Mid("hello", 2) = "ello" )
Assert( Mid("hello", 1) = "hello" )
; Explicit count.
Assert( Mid("hello", 2, 3) = "ell" )
; start past the end returns "".
Assert( Mid("hi", 10, 5) = "" )
; count past end clamps to remaining chars.
Assert( Mid("hello", 3, 99) = "llo" )
End Test
; --- Instr: found / not-found / from past end (criterion 4) ---
Test InstrFoundTest()
Assert( Instr("hello", "l") = 3 )
Assert( Instr("hello", "hello") = 1 )
Assert( Instr("hello", "o") = 5 )
End Test
Test InstrNotFoundTest()
Assert( Instr("hello", "z") = 0 )
End Test
Test InstrFromTest()
; from skips earlier matches.
Assert( Instr("hello", "l", 4) = 4 )
; from past end returns 0.
Assert( Instr("hello", "o", 99) = 0 )
End Test
; --- Trim (criterion 5) ---
Test TrimTest()
Assert( Trim(" hello ") = "hello" )
Assert( Trim("hello") = "hello" )
; Tabs and other non-graphical chars are whitespace.
Assert( Trim( Chr(9) + "hello" + Chr(9) ) = "hello" )
; whitespace-only string trims to empty.
Assert( Trim(" ") = "" )
End Test
; --- Upper / Lower (criterion 6) ---
Test UpperLowerTest()
Assert( Upper("Hello World") = "HELLO WORLD" )
Assert( Lower("Hello World") = "hello world" )
; Non-alpha chars are left untouched.
Assert( Upper("abc123") = "ABC123" )
Assert( Lower("ABC123") = "abc123" )
End Test
; --- LSet / RSet truncate + pad (criterion 6) ---
Test LSetTest()
; pad shorter with trailing spaces.
Assert( LSet("ab", 5) = "ab " )
; truncate longer.
Assert( LSet("abcdef", 3) = "abc" )
; exact width unchanged.
Assert( LSet("abc", 3) = "abc" )
End Test
Test RSetTest()
; pad shorter with leading spaces.
Assert( RSet("ab", 5) = " ab" )
; truncate longer, keeping rightmost.
Assert( RSet("abcdef", 3) = "def" )
; exact width unchanged.
Assert( RSet("abc", 3) = "abc" )
End Test
; --- Chr / Asc, including Asc("") = -1 (criterion 6) ---
Test ChrAscTest()
Assert( Chr(65) = "A" )
Assert( Asc("A") = 65 )
; Asc of first char only.
Assert( Asc("ABC") = 65 )
; round-trip.
Assert( Asc( Chr(97) ) = 97 )
; empty string returns -1.
Assert( Asc("") = -1 )
End Test
; --- Len (criterion 6) ---
Test LenTest()
Assert( Len("hello") = 5 )
Assert( Len("") = 0 )
Assert( Len(" ") = 1 )
End Test
; --- Hex (criterion 6) ---
Test HexTest()
Assert( Hex(255) = "000000FF" )
Assert( Hex(0) = "00000000" )
Assert( Hex(16) = "00000010" )
End Test
; --- Bin (criterion 6) ---
Test BinTest()
Assert( Len( Bin(5) ) = 32 )
Assert( Right( Bin(5), 4 ) = "0101" )
Assert( Bin(0) = "00000000000000000000000000000000" )
Assert( Right( Bin(1), 1 ) = "1" )
End Test