aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-05-18 11:43:43 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-05-18 11:43:43 -0300
commitabbae57c7844b1121e7251d56f681394f20c1821 (patch)
tree823201f4d2631fcae027117681553de80b2c96f0 /testes
parentf2c1531e6cacb10926158d8def5fa5841a0f357e (diff)
downloadlua-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-xtestes/all.lua2
-rw-r--r--testes/calls.lua2
-rw-r--r--testes/closure.lua2
-rw-r--r--testes/code.lua2
-rw-r--r--testes/files.lua2
-rw-r--r--testes/goto.lua12
-rw-r--r--testes/literals.lua2
-rw-r--r--testes/locals.lua22
-rw-r--r--testes/math.lua7
-rw-r--r--testes/nextvar.lua2
-rw-r--r--testes/pm.lua2
-rw-r--r--testes/strings.lua2
-rw-r--r--testes/utf8.lua2
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
5global * <const> 5global <const> *
6 6
7global _soft, _port, _nomsg 7global _soft, _port, _nomsg
8global T 8global 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
4global * <const> 4global <const> *
5 5
6print("testing functions and calls") 6print("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
4global * <const> 4global <const> *
5 5
6print "testing closures" 6print "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
4global * <const> 4global <const> *
5 5
6if T==nil then 6if 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
4global * <const> 4global <const> *
5 5
6local debug = require "debug" 6local 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
4global require 4global<const> require
5global print, load, assert, string, setmetatable 5global<const> print, load, assert, string, setmetatable
6global collectgarbage, error 6global<const> collectgarbage, error
7 7
8print("testing goto and global declarations") 8print("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
4print('testing scanner') 4print('testing scanner')
5 5
6global * <const> 6global <const> *
7 7
8local debug = require "debug" 8local 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
4global * <const> 4global <const> *
5 5
6print('testing local variables and environments') 6print('testing local variables and environments')
7 7
@@ -181,23 +181,25 @@ assert(x==20)
181A = nil 181A = nil
182 182
183 183
184do -- constants 184do 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
218end 220end
219 221
220 222
223
221print"testing to-be-closed variables" 224print"testing to-be-closed variables"
222 225
226
227do
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"))
233end
234
223local function stack(n) n = ((n == 0) or stack(n - 1)) end 235local function stack(n) n = ((n == 0) or stack(n - 1)) end
224 236
225local function func2close (f, x, y) 237local 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
9global none 9global none
10 10
11global print, assert, pcall, type, pairs, load 11global<const> print, assert, pcall, type, pairs, load
12global tonumber, tostring, select 12global<const> tonumber, tostring, select
13 13
14local minint <const> = math.mininteger 14local<const> minint, maxint = math.mininteger, math.maxinteger
15local maxint <const> = math.maxinteger
16 15
17local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1 16local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1
18assert((1 << intbits) == 0) 17assert((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
4global * <const> 4global <const> *
5 5
6print('testing tables, next, and for') 6print('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
7print('testing pattern matching') 7print('testing pattern matching')
8 8
9global * <const> 9global <const> *
10 10
11local function checkerror (msg, f, ...) 11local 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
6global * <const> 6global <const> *
7 7
8print('testing strings and string library') 8print('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
6global * <const> 6global <const> *
7 7
8print "testing UTF-8 library" 8print "testing UTF-8 library"
9 9