diff options
Diffstat (limited to 'testes/goto.lua')
| -rw-r--r-- | testes/goto.lua | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/testes/goto.lua b/testes/goto.lua index a692a623..906208b5 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
| @@ -293,6 +293,7 @@ end | |||
| 293 | foo() | 293 | foo() |
| 294 | -------------------------------------------------------------------------- | 294 | -------------------------------------------------------------------------- |
| 295 | 295 | ||
| 296 | -- check for compilation errors | ||
| 296 | local function checkerr (code, err) | 297 | local function checkerr (code, err) |
| 297 | local st, msg = load(code) | 298 | local st, msg = load(code) |
| 298 | assert(not st and string.find(msg, err)) | 299 | assert(not st and string.find(msg, err)) |
| @@ -414,22 +415,26 @@ end | |||
| 414 | do print "testing initialization in global declarations" | 415 | do print "testing initialization in global declarations" |
| 415 | global<const> a, b, c = 10, 20, 30 | 416 | global<const> a, b, c = 10, 20, 30 |
| 416 | assert(_ENV.a == 10 and b == 20 and c == 30) | 417 | assert(_ENV.a == 10 and b == 20 and c == 30) |
| 418 | _ENV.a = nil; _ENV.b = nil; _ENV.c = nil; | ||
| 417 | 419 | ||
| 418 | global<const> a, b, c = 10 | 420 | global<const> a, b, c = 10 |
| 419 | assert(_ENV.a == 10 and b == nil and c == nil) | 421 | assert(_ENV.a == 10 and b == nil and c == nil) |
| 422 | _ENV.a = nil; _ENV.b = nil; _ENV.c = nil; | ||
| 420 | 423 | ||
| 421 | global table | 424 | global table |
| 422 | global a, b, c, d = table.unpack{1, 2, 3, 6, 5} | 425 | global a, b, c, d = table.unpack{1, 2, 3, 6, 5} |
| 423 | assert(_ENV.a == 1 and b == 2 and c == 3 and d == 6) | 426 | assert(_ENV.a == 1 and b == 2 and c == 3 and d == 6) |
| 427 | a = nil; b = nil; c = nil; d = nil | ||
| 424 | 428 | ||
| 425 | local a, b = 100, 200 | 429 | local a, b = 100, 200 |
| 426 | do | 430 | do |
| 427 | global a, b = a, b | 431 | global a, b = a, b |
| 428 | end | 432 | end |
| 429 | assert(_ENV.a == 100 and _ENV.b == 200) | 433 | assert(_ENV.a == 100 and _ENV.b == 200) |
| 434 | _ENV.a = nil; _ENV.b = nil | ||
| 430 | 435 | ||
| 431 | 436 | ||
| 432 | _ENV.a, _ENV.b, _ENV.c, _ENV.d = nil -- erase these globals | 437 | assert(_ENV.a == nil and _ENV.b == nil and _ENV.c == nil and _ENV.d == nil) |
| 433 | end | 438 | end |
| 434 | 439 | ||
| 435 | do | 440 | do |
| @@ -454,5 +459,19 @@ do | |||
| 454 | assert(env.a == 10 and env.b == 20 and env.c == 30) | 459 | assert(env.a == 10 and env.b == 20 and env.c == 30) |
| 455 | end | 460 | end |
| 456 | 461 | ||
| 462 | |||
| 463 | do -- testing global redefinitions | ||
| 464 | -- cannot use 'checkerr' as errors are not compile time | ||
| 465 | global pcall | ||
| 466 | local f = assert(load("global print = 10")) | ||
| 467 | local st, msg = pcall(f) | ||
| 468 | assert(string.find(msg, "global 'print' already defined")) | ||
| 469 | |||
| 470 | local f = assert(load("local _ENV = {AA = false}; global AA = 10")) | ||
| 471 | local st, msg = pcall(f) | ||
| 472 | assert(string.find(msg, "global 'AA' already defined")) | ||
| 473 | |||
| 474 | end | ||
| 475 | |||
| 457 | print'OK' | 476 | print'OK' |
| 458 | 477 | ||
