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 /testes/literals.lua | |
| parent | e2c07dcbf7492e79e5825a6ca66d28e2e372f71e (diff) | |
| download | lua-59acd79c05b78950fe03279d60b015aeed5348ab.tar.gz lua-59acd79c05b78950fe03279d60b015aeed5348ab.tar.bz2 lua-59acd79c05b78950fe03279d60b015aeed5348ab.zip | |
Added tests for string reuse by the scanner
Diffstat (limited to 'testes/literals.lua')
| -rw-r--r-- | testes/literals.lua | 24 |
1 files changed, 24 insertions, 0 deletions
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 |
