diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-17 14:46:37 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-17 14:46:37 -0200 |
commit | 063d4e4543088e7a21965bda8ee5a0f952a9029e (patch) | |
tree | 6c3f2f8e98c26f071a94a32f9f2754396a66a9de /testes/big.lua | |
parent | e354c6355e7f48e087678ec49e340ca0696725b1 (diff) | |
download | lua-5.3.5.tar.gz lua-5.3.5.tar.bz2 lua-5.3.5.zip |
Lua 5.3.5 ported to gitv5.3.5
This is the first commit for the branch Lua 5.3. All source files
were copied from the official distribution of 5.3.5 in the Lua site.
The test files are the same of 5.3.4. The manual came from the
previous RCS repository, revision 1.167.1.2.
Diffstat (limited to '')
-rw-r--r-- | testes/big.lua | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/testes/big.lua b/testes/big.lua new file mode 100644 index 00000000..1a1fa788 --- /dev/null +++ b/testes/big.lua | |||
@@ -0,0 +1,82 @@ | |||
1 | -- $Id: big.lua,v 1.32 2016/11/07 13:11:28 roberto Exp $ | ||
2 | -- See Copyright Notice in file all.lua | ||
3 | |||
4 | if _soft then | ||
5 | return 'a' | ||
6 | end | ||
7 | |||
8 | print "testing large tables" | ||
9 | |||
10 | local debug = require"debug" | ||
11 | |||
12 | local lim = 2^18 + 1000 | ||
13 | local prog = { "local y = {0" } | ||
14 | for i = 1, lim do prog[#prog + 1] = i end | ||
15 | prog[#prog + 1] = "}\n" | ||
16 | prog[#prog + 1] = "X = y\n" | ||
17 | prog[#prog + 1] = ("assert(X[%d] == %d)"):format(lim - 1, lim - 2) | ||
18 | prog[#prog + 1] = "return 0" | ||
19 | prog = table.concat(prog, ";") | ||
20 | |||
21 | local env = {string = string, assert = assert} | ||
22 | local f = assert(load(prog, nil, nil, env)) | ||
23 | |||
24 | f() | ||
25 | assert(env.X[lim] == lim - 1 and env.X[lim + 1] == lim) | ||
26 | for k in pairs(env) do env[k] = nil end | ||
27 | |||
28 | -- yields during accesses larger than K (in RK) | ||
29 | setmetatable(env, { | ||
30 | __index = function (t, n) coroutine.yield('g'); return _G[n] end, | ||
31 | __newindex = function (t, n, v) coroutine.yield('s'); _G[n] = v end, | ||
32 | }) | ||
33 | |||
34 | X = nil | ||
35 | co = coroutine.wrap(f) | ||
36 | assert(co() == 's') | ||
37 | assert(co() == 'g') | ||
38 | assert(co() == 'g') | ||
39 | assert(co() == 0) | ||
40 | |||
41 | assert(X[lim] == lim - 1 and X[lim + 1] == lim) | ||
42 | |||
43 | -- errors in accesses larger than K (in RK) | ||
44 | getmetatable(env).__index = function () end | ||
45 | getmetatable(env).__newindex = function () end | ||
46 | local e, m = pcall(f) | ||
47 | assert(not e and m:find("global 'X'")) | ||
48 | |||
49 | -- errors in metamethods | ||
50 | getmetatable(env).__newindex = function () error("hi") end | ||
51 | local e, m = xpcall(f, debug.traceback) | ||
52 | assert(not e and m:find("'__newindex'")) | ||
53 | |||
54 | f, X = nil | ||
55 | |||
56 | coroutine.yield'b' | ||
57 | |||
58 | if 2^32 == 0 then -- (small integers) { | ||
59 | |||
60 | print "testing string length overflow" | ||
61 | |||
62 | local repstrings = 192 -- number of strings to be concatenated | ||
63 | local ssize = math.ceil(2.0^32 / repstrings) + 1 -- size of each string | ||
64 | |||
65 | assert(repstrings * ssize > 2.0^32) -- it should be larger than maximum size | ||
66 | |||
67 | local longs = string.rep("\0", ssize) -- create one long string | ||
68 | |||
69 | -- create function to concatentate 'repstrings' copies of its argument | ||
70 | local rep = assert(load( | ||
71 | "local a = ...; return " .. string.rep("a", repstrings, ".."))) | ||
72 | |||
73 | local a, b = pcall(rep, longs) -- call that function | ||
74 | |||
75 | -- it should fail without creating string (result would be too large) | ||
76 | assert(not a and string.find(b, "overflow")) | ||
77 | |||
78 | end -- } | ||
79 | |||
80 | print'OK' | ||
81 | |||
82 | return 'a' | ||