diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/code.lua | 20 | ||||
-rw-r--r-- | testes/goto.lua | 16 |
2 files changed, 35 insertions, 1 deletions
diff --git a/testes/code.lua b/testes/code.lua index 9b3f2b68..4d44fa6a 100644 --- a/testes/code.lua +++ b/testes/code.lua | |||
@@ -339,8 +339,26 @@ check(function (a, b) | |||
339 | 339 | ||
340 | checkequal( | 340 | checkequal( |
341 | function (a) while a < 10 do a = a + 1 end end, | 341 | function (a) while a < 10 do a = a + 1 end end, |
342 | function (a) while true do if not(a < 10) then break end; a = a + 1; end end | 342 | function (a) |
343 | ::loop:: | ||
344 | if not (a < 10) then goto exit end | ||
345 | a = a + 1 | ||
346 | goto loop | ||
347 | ::exit:: | ||
348 | end | ||
343 | ) | 349 | ) |
344 | 350 | ||
351 | checkequal( | ||
352 | function (a) repeat local x = a + 1; a = x until a > 0 end, | ||
353 | function (a) | ||
354 | ::loop:: do | ||
355 | local x = a + 1 | ||
356 | a = x | ||
357 | end | ||
358 | if not (a > 0) then goto loop end | ||
359 | end | ||
360 | ) | ||
361 | |||
362 | |||
345 | print 'OK' | 363 | print 'OK' |
346 | 364 | ||
diff --git a/testes/goto.lua b/testes/goto.lua index 85038d02..92f048fb 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
@@ -249,6 +249,22 @@ assert(testG(2) == "2") | |||
249 | assert(testG(3) == "3") | 249 | assert(testG(3) == "3") |
250 | assert(testG(4) == 5) | 250 | assert(testG(4) == 5) |
251 | assert(testG(5) == 10) | 251 | assert(testG(5) == 10) |
252 | |||
253 | do | ||
254 | -- if x back goto out of scope of upvalue | ||
255 | local X | ||
256 | goto L1 | ||
257 | |||
258 | ::L2:: goto L3 | ||
259 | |||
260 | ::L1:: do | ||
261 | local scoped a = function () X = true end | ||
262 | assert(X == nil) | ||
263 | if a then goto L2 end -- jumping back out of scope of 'a' | ||
264 | end | ||
265 | |||
266 | ::L3:: assert(X == true) -- checks that 'a' was correctly closed | ||
267 | end | ||
252 | -------------------------------------------------------------------------------- | 268 | -------------------------------------------------------------------------------- |
253 | 269 | ||
254 | 270 | ||