diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-08-11 11:19:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-08-11 11:19:33 -0300 |
commit | 59acd79c05b78950fe03279d60b015aeed5348ab (patch) | |
tree | afcfc5473099ee36e77ef6a2907345e18ca86ddc | |
parent | e2c07dcbf7492e79e5825a6ca66d28e2e372f71e (diff) | |
download | lua-59acd79c05b78950fe03279d60b015aeed5348ab.tar.gz lua-59acd79c05b78950fe03279d60b015aeed5348ab.tar.bz2 lua-59acd79c05b78950fe03279d60b015aeed5348ab.zip |
Added tests for string reuse by the scanner
-rw-r--r-- | testes/errors.lua | 2 | ||||
-rw-r--r-- | testes/literals.lua | 24 |
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') | |||
241 | assert(o == x) | 241 | assert(o == x) |
242 | return "ABC" | 242 | return "ABC" |
243 | end}) | 243 | end}) |
244 | a, b, c = T.testC("pushint 10; Ltolstring -2; return 3", x) | 244 | local a, b, c = T.testC("pushint 10; Ltolstring -2; return 3", x) |
245 | assert(a == x and b == 10 and c == "ABC") | 245 | assert(a == x and b == 10 and c == "ABC") |
246 | end | 246 | end |
247 | end | 247 | 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 | |||
208 | b = nil | 208 | b = nil |
209 | 209 | ||
210 | 210 | ||
211 | do -- reuse of long strings | ||
212 | |||
213 | -- get the address of a string | ||
214 | local function getadd (s) return string.format("%p", s) end | ||
215 | |||
216 | local s1 <const> = "01234567890123456789012345678901234567890123456789" | ||
217 | local s2 <const> = "01234567890123456789012345678901234567890123456789" | ||
218 | local s3 = "01234567890123456789012345678901234567890123456789" | ||
219 | local function foo() return s1 end | ||
220 | local function foo1() return s3 end | ||
221 | local function foo2() | ||
222 | return "01234567890123456789012345678901234567890123456789" | ||
223 | end | ||
224 | local a1 = getadd(s1) | ||
225 | assert(a1 == getadd(s2)) | ||
226 | assert(a1 == getadd(foo())) | ||
227 | assert(a1 == getadd(foo1())) | ||
228 | assert(a1 == getadd(foo2())) | ||
229 | |||
230 | local sd = "0123456789" .. "0123456789012345678901234567890123456789" | ||
231 | assert(sd == s1 and getadd(sd) ~= a1) | ||
232 | end | ||
233 | |||
234 | |||
211 | -- testing line ends | 235 | -- testing line ends |
212 | prog = [[ | 236 | prog = [[ |
213 | a = 1 -- a comment | 237 | a = 1 -- a comment |