summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-08-11 11:19:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-08-11 11:19:33 -0300
commit59acd79c05b78950fe03279d60b015aeed5348ab (patch)
treeafcfc5473099ee36e77ef6a2907345e18ca86ddc
parente2c07dcbf7492e79e5825a6ca66d28e2e372f71e (diff)
downloadlua-github-59acd79c05b78950fe03279d60b015aeed5348ab.tar.gz
Added tests for string reuse by the scanner
-rw-r--r--testes/errors.lua2
-rw-r--r--testes/literals.lua24
2 files changed, 25 insertions, 1 deletions
diff --git a/testes/errors.lua b/testes/errors.lua
index a7dc479a..55bdab82 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -241,7 +241,7 @@ do -- named objects (field '__name')
assert(o == x)
return "ABC"
end})
- a, b, c = T.testC("pushint 10; Ltolstring -2; return 3", x)
+ local a, b, c = T.testC("pushint 10; Ltolstring -2; return 3", x)
assert(a == x and b == 10 and c == "ABC")
end
end
diff --git a/testes/literals.lua b/testes/literals.lua
index e101eabf..d5a769ed 100644
--- a/testes/literals.lua
+++ b/testes/literals.lua
@@ -208,6 +208,30 @@ a = nil
b = nil
+do -- reuse of long strings
+
+ -- get the address of a string
+ local function getadd (s) return string.format("%p", s) end
+
+ local s1 <const> = "01234567890123456789012345678901234567890123456789"
+ local s2 <const> = "01234567890123456789012345678901234567890123456789"
+ local s3 = "01234567890123456789012345678901234567890123456789"
+ local function foo() return s1 end
+ local function foo1() return s3 end
+ local function foo2()
+ return "01234567890123456789012345678901234567890123456789"
+ end
+ local a1 = getadd(s1)
+ assert(a1 == getadd(s2))
+ assert(a1 == getadd(foo()))
+ assert(a1 == getadd(foo1()))
+ assert(a1 == getadd(foo2()))
+
+ local sd = "0123456789" .. "0123456789012345678901234567890123456789"
+ assert(sd == s1 and getadd(sd) ~= a1)
+end
+
+
-- testing line ends
prog = [[
a = 1 -- a comment