diff options
Diffstat (limited to 'testes/goto.lua')
-rw-r--r-- | testes/goto.lua | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/testes/goto.lua b/testes/goto.lua index 59713dd7..3f1f6e69 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
@@ -1,6 +1,10 @@ | |||
1 | -- $Id: testes/goto.lua $ | 1 | -- $Id: testes/goto.lua $ |
2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
3 | 3 | ||
4 | global require | ||
5 | global print, load, assert, string, setmetatable | ||
6 | global collectgarbage, error | ||
7 | |||
4 | print("testing goto and global declarations") | 8 | print("testing goto and global declarations") |
5 | 9 | ||
6 | collectgarbage() | 10 | collectgarbage() |
@@ -254,6 +258,8 @@ assert(testG(5) == 10) | |||
254 | 258 | ||
255 | do -- test goto's around to-be-closed variable | 259 | do -- test goto's around to-be-closed variable |
256 | 260 | ||
261 | global * | ||
262 | |||
257 | -- set 'var' and return an object that will reset 'var' when | 263 | -- set 'var' and return an object that will reset 'var' when |
258 | -- it goes out of scope | 264 | -- it goes out of scope |
259 | local function newobj (var) | 265 | local function newobj (var) |
@@ -265,16 +271,16 @@ do -- test goto's around to-be-closed variable | |||
265 | 271 | ||
266 | goto L1 | 272 | goto L1 |
267 | 273 | ||
268 | ::L4:: assert(not X); goto L5 -- varX dead here | 274 | ::L4:: assert(not varX); goto L5 -- varX dead here |
269 | 275 | ||
270 | ::L1:: | 276 | ::L1:: |
271 | local varX <close> = newobj("X") | 277 | local varX <close> = newobj("X") |
272 | assert(X); goto L2 -- varX alive here | 278 | assert(varX); goto L2 -- varX alive here |
273 | 279 | ||
274 | ::L3:: | 280 | ::L3:: |
275 | assert(X); goto L4 -- varX alive here | 281 | assert(varX); goto L4 -- varX alive here |
276 | 282 | ||
277 | ::L2:: assert(X); goto L3 -- varX alive here | 283 | ::L2:: assert(varX); goto L3 -- varX alive here |
278 | 284 | ||
279 | ::L5:: -- return | 285 | ::L5:: -- return |
280 | end | 286 | end |
@@ -285,8 +291,7 @@ foo() | |||
285 | -------------------------------------------------------------------------- | 291 | -------------------------------------------------------------------------- |
286 | 292 | ||
287 | do | 293 | do |
288 | global print, load, T<const>; global assert<const> | 294 | global T<const> |
289 | global string | ||
290 | 295 | ||
291 | local function checkerr (code, err) | 296 | local function checkerr (code, err) |
292 | local st, msg = load(code) | 297 | local st, msg = load(code) |
@@ -299,6 +304,7 @@ do | |||
299 | 304 | ||
300 | -- global variables cannot be to-be-closed | 305 | -- global variables cannot be to-be-closed |
301 | checkerr("global X<close>", "cannot be") | 306 | checkerr("global X<close>", "cannot be") |
307 | checkerr("global * <close>", "cannot be") | ||
302 | 308 | ||
303 | do | 309 | do |
304 | local X = 10 | 310 | local X = 10 |
@@ -349,6 +355,12 @@ do | |||
349 | return | 355 | return |
350 | end | 356 | end |
351 | ]], "%:2%:") -- correct line in error message | 357 | ]], "%:2%:") -- correct line in error message |
358 | |||
359 | checkerr([[ | ||
360 | global * <const>; | ||
361 | print(X) -- Ok to use | ||
362 | Y = 1 -- ERROR | ||
363 | ]], "assign to const variable 'Y'") | ||
352 | 364 | ||
353 | end | 365 | end |
354 | 366 | ||