This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathrepeat.livecodescript
More file actions
287 lines (240 loc) · 10.7 KB
/
Copy pathrepeat.livecodescript
File metadata and controls
287 lines (240 loc) · 10.7 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
script "CoreControlRepeat"
/*
Copyright (C) 2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
on TestRepeatForever
local tCounter
put 0 into tCounter
repeat forever
add 1 to tCounter
if tCounter is 1000 then
exit repeat
end if
end repeat
TestAssert "repeat forever runs 1000 times", tCounter is 1000
end TestRepeatForever
on TestRepeatCount
local tCounter
put 1000 into tCounter
repeat 1000 times
subtract 1 from tCounter
end repeat
TestAssert "repeat 1000 times runs 1000 times", tCounter is 0
end TestRepeatCount
on TestRepeatForEachKeyInArray
local tArray
put 1 into tArray["foo"]
put 2 into tArray["bar"]
put 3 into tArray["baz"]
local tTotal, tLastKey
repeat for each key tKey in tArray
add tArray[tKey] to tTotal
put tKey into tLastKey
end repeat
TestAssert "repeat for each key in array", tTotal is 6
TestAssert "repeat for each key in array preserves last value", tKey is tLastKey
put "something" into tKey
repeat for each key tKey in empty
end repeat
TestAssert "repeat for each key in empty preserves initial value", tKey is "something"
end TestRepeatForEachKeyInArray
on TestRepeatForEachKeyInSequence
local tArray, tExpectedString
repeat with i = 1 to 10000
put i into tArray[i]
put i & comma after tExpectedString
end repeat
local tComputedString
repeat for each key tKey in tArray
put tArray[tKey] & comma after tComputedString
end repeat
TestAssertBroken "repeat for each key in sequence", tComputedString is tExpectedString, "anomaly 16449"
end TestRepeatForEachKeyInSequence
on TestRepeatForEachElementInArray
local tArray
put 1 into tArray["foo"]
put 2 into tArray["bar"]
put 3 into tArray["baz"]
local tTotal, tLastElement
repeat for each element tElement in tArray
add tElement to tTotal
put tElement into tLastElement
end repeat
TestAssert "repeat for each element in array", tTotal is 6
TestAssert "repeat for each element preserves last value", tElement is tLastElement
put "something" into tElement
repeat for each element tElement in empty
end repeat
TestAssert "repeat for each element in empty preserves initial value", tElement is "something"
end TestRepeatForEachElementInArray
on TestRepeatForEachElementInSequence
local tArray, tExpectedString
repeat with i = 1 to 10000
put i into tArray[i]
put i & comma after tExpectedString
end repeat
local tComputedString
repeat for each element tElement in tArray
put tElement & comma after tComputedString
end repeat
TestAssert "repeat for each element in sequence", tComputedString is tExpectedString
TestAssert "repeat for each element in sequence preserves last value", tElement is 10000
end TestRepeatForEachElementInSequence
on TestRepeatForEachByte
local tBytes, tExpectedString
repeat with i = 0 to 255
put numToByte(i) after tBytes
put i & comma after tExpectedString
end repeat
local tComputedString
repeat for each byte tByte in tBytes
put byteToNum(tByte) & comma after tComputedString
end repeat
TestAssert "repeat for each byte", tComputedString is tExpectedString
TestAssert "repeat for each byte preserves last value", tByte is the last byte of tBytes
put "something" into tByte
repeat for each byte tByte in empty
end repeat
TestAssert "repeat for each byte in empty preserves initial value", tByte is "something"
end TestRepeatForEachByte
on TestRepeatForEachChar
local tString, tExpectedCharString, tExpectedCodepointString, tExpectedCodeunitString, tComputedString
repeat for each word tType in "native simple combining surrogates"
switch tType
case "native"
-- native boundaries are the same for char, codepoint and codeunit
put "foo" into tString
put "f,o,o," into tExpectedCharString
put "f,o,o," into tExpectedCodepointString
put "f,o,o," into tExpectedCodeunitString
break
case "simple"
-- unicode characters which are 1-1-1 (char,unit,point)
-- we use greek alpha, beta and gamma
put numToCodepoint(0x0391) & numToCodepoint(0x392) & numToCodepoint(0x393) into tString
put numToCodepoint(0x0391) , numToCodepoint(0x392) , numToCodepoint(0x393) , empty into tExpectedCharString
put tExpectedCharString into tExpectedCodepointString
put tExpectedCharString into tExpectedCodeunitString
break
case "combining"
-- unicode characters which give 2-1-1 (char,unit,point)
put "fo" & numToCodepoint(0x301) & "o" into tString
put "f", "o" & numToCodepoint(0x301) , "o" , empty into tExpectedCharString
put "f", "o", numToCodepoint(0x301) , "o" , empty into tExpectedCodepointString
put tExpectedCodepointString into tExpectedCodeunitString
break
end switch
put empty into tComputedString
repeat for each character tChar in tString
put tChar & comma after tComputedString
end repeat
TestAssert "repeat for each character -" && tType, tComputedString is tExpectedCharString
put empty into tComputedString
repeat for each codepoint tChar in tString
put tChar & comma after tComputedString
end repeat
TestAssert "repeat for each codepoint -" && tType, tComputedString is tExpectedCodepointString
put empty into tComputedString
repeat for each codeunit tChar in tString
put tChar & comma after tComputedString
end repeat
TestAssert "repeat for each codeunit -" && tType, tComputedString is tExpectedCodeunitString
end repeat
repeat for each character tChar in "abc"
end repeat
TestAssert "repeat for each character preserves last value", tChar is "c"
repeat for each codepoint tChar in "abc"
end repeat
TestAssert "repeat for each codepoint preserves last value", tChar is "c"
repeat for each codeunit tChar in "abc"
end repeat
TestAssert "repeat for each codeunit preserves last value", tChar is "c"
put "something" into tChar
repeat for each character tChar in empty
end repeat
TestAssertBroken "repeat for each character in empty preserves initial value", tChar is "something", "anomaly 16454"
put "something" into tChar
repeat for each codepoint tChar in empty
end repeat
TestAssertBroken "repeat for each codepoint in empty preserves initial value", tChar is "something", "anomaly 16454"
put "something" into tChar
repeat for each codeunit tChar in empty
end repeat
TestAssertBroken "repeat for each codeunit in empty preserves initial value", tChar is "something", "anomaly 16454"
end TestRepeatForEachChar
on TestRepeatForEachDelimitedChunk
local tChunks, tComputedChunks
put "foo,bar,baz,foobar,foobaz,barbaz" into tChunks
put empty into tComputedChunks
repeat for each item tChunk in tChunks
put tChunk & comma after tComputedChunks
end repeat
TestAssert "repeat for each item", tComputedChunks is (tChunks & comma)
TestAssert "repeat for each item preserves last value", tChunk is the last item of tChunks
put empty into tComputedChunks
repeat for each item tChunk in (tChunks & comma)
put tChunk & comma after tComputedChunks
end repeat
TestAssert "repeat for each item trailing delimiter", tComputedChunks is (tChunks & comma)
TestAssert "repeat for each item trailing delimiter preserves last value", tChunk is the last item of tChunks
put "something" into tChunk
repeat for each item tChunk in empty
end repeat
TestAssertBroken "repeat for each item in empty preserves initial value", tChunk is "something", "anomaly 16454"
replace comma with return in tChunks
put empty into tComputedChunks
repeat for each line tChunk in tChunks
put tChunk & return after tComputedChunks
end repeat
TestAssert "repeat for each line", tComputedChunks is (tChunks & return)
TestAssert "repeat for each line preserves last value", tChunk is the last line of tChunks
put empty into tComputedChunks
repeat for each line tChunk in (tChunks & return)
put tChunk & return after tComputedChunks
end repeat
TestAssert "repeat for each line trailing delimiter", tComputedChunks is (tChunks & return)
TestAssert "repeat for each line trailing delimiter preserves last value", tChunk is the last line of tChunks
put "something" into tChunk
repeat for each line tChunk in empty
end repeat
TestAssertBroken "repeat for each line in empty preserves initial value", tChunk is "something", "anomaly 16454"
end TestRepeatForEachDelimitedChunk
on TestRepeatForEachSegment
local tSegments, tExpectedString
put " the " & quote & "quick brown" & quote & " fox" into tSegments
put "the," & quote & "quick brown" & quote & ",fox," into tExpectedString
local tComputedString
repeat for each segment tSegment in tSegments
put tSegment & comma after tComputedString
end repeat
TestAssert "repeat for each segment", tComputedString is tExpectedString
TestAssert "repeat for each segment preserves last value", tSegment is the last segment of tSegments
put "something" into tSegment
repeat for each segment tSegment in empty
end repeat
TestAssertBroken "repeat for each segment in empty preserves initial value", tSegment is "something", "anomaly 16454"
end TestRepeatForEachSegment
on TestRepeatForEachTrueWord
local tTrueWords, tExpectedString
put " the " & quote & "quick brown" & quote & " fox" into tTrueWords
put "the,quick,brown,fox," into tExpectedString
local tComputedString
repeat for each trueWord tTrueWord in tTrueWords
put tTrueWord & comma after tComputedString
end repeat
TestAssert "repeat for each true word", tComputedString is tExpectedString
TestAssert "repeat for each true word preserves last value", tTrueWord is the last trueWord of tTrueWords
put "something" into tTrueWord
repeat for each trueWord tTrueWord in empty
end repeat
TestAssertBroken "repeat for each true word in empty preserves initial value", tTrueWord is "something", "anomaly 16454"
end TestRepeatForEachTrueWord