diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-18 11:43:43 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-18 11:43:43 -0300 |
| commit | abbae57c7844b1121e7251d56f681394f20c1821 (patch) | |
| tree | 823201f4d2631fcae027117681553de80b2c96f0 /testes | |
| parent | f2c1531e6cacb10926158d8def5fa5841a0f357e (diff) | |
| download | lua-abbae57c7844b1121e7251d56f681394f20c1821.tar.gz lua-abbae57c7844b1121e7251d56f681394f20c1821.tar.bz2 lua-abbae57c7844b1121e7251d56f681394f20c1821.zip | |
Variable attributes can prefix name list
In this format, the attribute applies to all names in the list;
e.g. "global<const> print, require, math".
Diffstat (limited to 'testes')
| -rwxr-xr-x | testes/all.lua | 2 | ||||
| -rw-r--r-- | testes/calls.lua | 2 | ||||
| -rw-r--r-- | testes/closure.lua | 2 | ||||
| -rw-r--r-- | testes/code.lua | 2 | ||||
| -rw-r--r-- | testes/files.lua | 2 | ||||
| -rw-r--r-- | testes/goto.lua | 12 | ||||
| -rw-r--r-- | testes/literals.lua | 2 | ||||
| -rw-r--r-- | testes/locals.lua | 22 | ||||
| -rw-r--r-- | testes/math.lua | 7 | ||||
| -rw-r--r-- | testes/nextvar.lua | 2 | ||||
| -rw-r--r-- | testes/pm.lua | 2 | ||||
| -rw-r--r-- | testes/strings.lua | 2 | ||||
| -rw-r--r-- | testes/utf8.lua | 2 |
13 files changed, 36 insertions, 25 deletions
diff --git a/testes/all.lua b/testes/all.lua index 499c100d..d3e2f123 100755 --- a/testes/all.lua +++ b/testes/all.lua | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | -- $Id: testes/all.lua $ | 2 | -- $Id: testes/all.lua $ |
| 3 | -- See Copyright Notice in file lua.h | 3 | -- See Copyright Notice in file lua.h |
| 4 | 4 | ||
| 5 | global * <const> | 5 | global <const> * |
| 6 | 6 | ||
| 7 | global _soft, _port, _nomsg | 7 | global _soft, _port, _nomsg |
| 8 | global T | 8 | global T |
diff --git a/testes/calls.lua b/testes/calls.lua index 0ea1c4ab..21441701 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/calls.lua $ | 1 | -- $Id: testes/calls.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print("testing functions and calls") | 6 | print("testing functions and calls") |
| 7 | 7 | ||
diff --git a/testes/closure.lua b/testes/closure.lua index c55d1583..0c2e96c0 100644 --- a/testes/closure.lua +++ b/testes/closure.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/closure.lua $ | 1 | -- $Id: testes/closure.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print "testing closures" | 6 | print "testing closures" |
| 7 | 7 | ||
diff --git a/testes/code.lua b/testes/code.lua index b6ceb34c..633f4896 100644 --- a/testes/code.lua +++ b/testes/code.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/code.lua $ | 1 | -- $Id: testes/code.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | if T==nil then | 6 | if T==nil then |
| 7 | (Message or print)('\n >>> testC not active: skipping opcode tests <<<\n') | 7 | (Message or print)('\n >>> testC not active: skipping opcode tests <<<\n') |
diff --git a/testes/files.lua b/testes/files.lua index c2b355fb..d4e327b7 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/files.lua $ | 1 | -- $Id: testes/files.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | local debug = require "debug" | 6 | local debug = require "debug" |
| 7 | 7 | ||
diff --git a/testes/goto.lua b/testes/goto.lua index 3f1f6e69..44486e20 100644 --- a/testes/goto.lua +++ b/testes/goto.lua | |||
| @@ -1,9 +1,9 @@ | |||
| 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 | 4 | global<const> require |
| 5 | global print, load, assert, string, setmetatable | 5 | global<const> print, load, assert, string, setmetatable |
| 6 | global collectgarbage, error | 6 | global<const> collectgarbage, error |
| 7 | 7 | ||
| 8 | print("testing goto and global declarations") | 8 | print("testing goto and global declarations") |
| 9 | 9 | ||
| @@ -304,7 +304,7 @@ do | |||
| 304 | 304 | ||
| 305 | -- global variables cannot be to-be-closed | 305 | -- global variables cannot be to-be-closed |
| 306 | checkerr("global X<close>", "cannot be") | 306 | checkerr("global X<close>", "cannot be") |
| 307 | checkerr("global * <close>", "cannot be") | 307 | checkerr("global <close> *", "cannot be") |
| 308 | 308 | ||
| 309 | do | 309 | do |
| 310 | local X = 10 | 310 | local X = 10 |
| @@ -345,7 +345,7 @@ do | |||
| 345 | end | 345 | end |
| 346 | 346 | ||
| 347 | checkerr([[ | 347 | checkerr([[ |
| 348 | global foo <const>; | 348 | global<const> foo; |
| 349 | function foo (x) return end -- ERROR: foo is read-only | 349 | function foo (x) return end -- ERROR: foo is read-only |
| 350 | ]], "assign to const variable 'foo'") | 350 | ]], "assign to const variable 'foo'") |
| 351 | 351 | ||
| @@ -357,7 +357,7 @@ do | |||
| 357 | ]], "%:2%:") -- correct line in error message | 357 | ]], "%:2%:") -- correct line in error message |
| 358 | 358 | ||
| 359 | checkerr([[ | 359 | checkerr([[ |
| 360 | global * <const>; | 360 | global<const> *; |
| 361 | print(X) -- Ok to use | 361 | print(X) -- Ok to use |
| 362 | Y = 1 -- ERROR | 362 | Y = 1 -- ERROR |
| 363 | ]], "assign to const variable 'Y'") | 363 | ]], "assign to const variable 'Y'") |
diff --git a/testes/literals.lua b/testes/literals.lua index fecdd6d3..336ef585 100644 --- a/testes/literals.lua +++ b/testes/literals.lua | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | print('testing scanner') | 4 | print('testing scanner') |
| 5 | 5 | ||
| 6 | global * <const> | 6 | global <const> * |
| 7 | 7 | ||
| 8 | local debug = require "debug" | 8 | local debug = require "debug" |
| 9 | 9 | ||
diff --git a/testes/locals.lua b/testes/locals.lua index 99ff9edc..02f41980 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/locals.lua $ | 1 | -- $Id: testes/locals.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print('testing local variables and environments') | 6 | print('testing local variables and environments') |
| 7 | 7 | ||
| @@ -181,23 +181,25 @@ assert(x==20) | |||
| 181 | A = nil | 181 | A = nil |
| 182 | 182 | ||
| 183 | 183 | ||
| 184 | do -- constants | 184 | do print("testing local constants") |
| 185 | global assert<const>, load, string, X | 185 | global assert<const>, load, string, X |
| 186 | X = 1 -- not a constant | 186 | X = 1 -- not a constant |
| 187 | local a<const>, b, c<const> = 10, 20, 30 | 187 | local a<const>, b, c<const> = 10, 20, 30 |
| 188 | b = a + c + b -- 'b' is not constant | 188 | b = a + c + b -- 'b' is not constant |
| 189 | assert(a == 10 and b == 60 and c == 30) | 189 | assert(a == 10 and b == 60 and c == 30) |
| 190 | |||
| 190 | local function checkro (name, code) | 191 | local function checkro (name, code) |
| 191 | local st, msg = load(code) | 192 | local st, msg = load(code) |
| 192 | local gab = string.format("attempt to assign to const variable '%s'", name) | 193 | local gab = string.format("attempt to assign to const variable '%s'", name) |
| 193 | assert(not st and string.find(msg, gab)) | 194 | assert(not st and string.find(msg, gab)) |
| 194 | end | 195 | end |
| 196 | |||
| 195 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") | 197 | checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12") |
| 196 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") | 198 | checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11") |
| 197 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") | 199 | checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11") |
| 198 | checkro("foo", "local foo <const> = 10; function foo() end") | 200 | checkro("foo", "local<const> foo = 10; function foo() end") |
| 199 | checkro("foo", "local foo <const> = {}; function foo() end") | 201 | checkro("foo", "local<const> foo <const> = {}; function foo() end") |
| 200 | checkro("foo", "global foo <const>; function foo() end") | 202 | checkro("foo", "global<const> foo <const>; function foo() end") |
| 201 | checkro("XX", "global XX <const>; XX = 10") | 203 | checkro("XX", "global XX <const>; XX = 10") |
| 202 | checkro("XX", "local _ENV; global XX <const>; XX = 10") | 204 | checkro("XX", "local _ENV; global XX <const>; XX = 10") |
| 203 | 205 | ||
| @@ -218,8 +220,18 @@ do -- constants | |||
| 218 | end | 220 | end |
| 219 | 221 | ||
| 220 | 222 | ||
| 223 | |||
| 221 | print"testing to-be-closed variables" | 224 | print"testing to-be-closed variables" |
| 222 | 225 | ||
| 226 | |||
| 227 | do | ||
| 228 | local st, msg = load("local <close> a, b") | ||
| 229 | assert(not st and string.find(msg, "multiple")) | ||
| 230 | |||
| 231 | local st, msg = load("local a<close>, b<close>") | ||
| 232 | assert(not st and string.find(msg, "multiple")) | ||
| 233 | end | ||
| 234 | |||
| 223 | local function stack(n) n = ((n == 0) or stack(n - 1)) end | 235 | local function stack(n) n = ((n == 0) or stack(n - 1)) end |
| 224 | 236 | ||
| 225 | local function func2close (f, x, y) | 237 | local function func2close (f, x, y) |
diff --git a/testes/math.lua b/testes/math.lua index 242579b1..0d228d09 100644 --- a/testes/math.lua +++ b/testes/math.lua | |||
| @@ -8,11 +8,10 @@ local string = require "string" | |||
| 8 | 8 | ||
| 9 | global none | 9 | global none |
| 10 | 10 | ||
| 11 | global print, assert, pcall, type, pairs, load | 11 | global<const> print, assert, pcall, type, pairs, load |
| 12 | global tonumber, tostring, select | 12 | global<const> tonumber, tostring, select |
| 13 | 13 | ||
| 14 | local minint <const> = math.mininteger | 14 | local<const> minint, maxint = math.mininteger, math.maxinteger |
| 15 | local maxint <const> = math.maxinteger | ||
| 16 | 15 | ||
| 17 | local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 | 16 | local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 |
| 18 | assert((1 << intbits) == 0) | 17 | assert((1 << intbits) == 0) |
diff --git a/testes/nextvar.lua b/testes/nextvar.lua index e5a97178..03810a8e 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | -- $Id: testes/nextvar.lua $ | 1 | -- $Id: testes/nextvar.lua $ |
| 2 | -- See Copyright Notice in file lua.h | 2 | -- See Copyright Notice in file lua.h |
| 3 | 3 | ||
| 4 | global * <const> | 4 | global <const> * |
| 5 | 5 | ||
| 6 | print('testing tables, next, and for') | 6 | print('testing tables, next, and for') |
| 7 | 7 | ||
diff --git a/testes/pm.lua b/testes/pm.lua index 1700ca2c..720d2a35 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | print('testing pattern matching') | 7 | print('testing pattern matching') |
| 8 | 8 | ||
| 9 | global * <const> | 9 | global <const> * |
| 10 | 10 | ||
| 11 | local function checkerror (msg, f, ...) | 11 | local function checkerror (msg, f, ...) |
| 12 | local s, err = pcall(f, ...) | 12 | local s, err = pcall(f, ...) |
diff --git a/testes/strings.lua b/testes/strings.lua index 455398c3..46912d43 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | -- ISO Latin encoding | 4 | -- ISO Latin encoding |
| 5 | 5 | ||
| 6 | global * <const> | 6 | global <const> * |
| 7 | 7 | ||
| 8 | print('testing strings and string library') | 8 | print('testing strings and string library') |
| 9 | 9 | ||
diff --git a/testes/utf8.lua b/testes/utf8.lua index ec9b706f..143c6d34 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | -- UTF-8 file | 4 | -- UTF-8 file |
| 5 | 5 | ||
| 6 | global * <const> | 6 | global <const> * |
| 7 | 7 | ||
| 8 | print "testing UTF-8 library" | 8 | print "testing UTF-8 library" |
| 9 | 9 | ||
