aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/strings.lua26
1 files changed, 23 insertions, 3 deletions
diff --git a/testes/strings.lua b/testes/strings.lua
index 90983edd..c124b369 100644
--- a/testes/strings.lua
+++ b/testes/strings.lua
@@ -157,6 +157,12 @@ else -- compatible coercion
157 assert(tostring(-1203 + 0.0) == "-1203") 157 assert(tostring(-1203 + 0.0) == "-1203")
158end 158end
159 159
160
161local function topointer (s)
162 return string.format("%p", s)
163end
164
165
160do -- tests for '%p' format 166do -- tests for '%p' format
161 -- not much to test, as C does not specify what '%p' does. 167 -- not much to test, as C does not specify what '%p' does.
162 -- ("The value of the pointer is converted to a sequence of printing 168 -- ("The value of the pointer is converted to a sequence of printing
@@ -180,18 +186,18 @@ do -- tests for '%p' format
180 186
181 do 187 do
182 local t1 = {}; local t2 = {} 188 local t1 = {}; local t2 = {}
183 assert(string.format("%p", t1) ~= string.format("%p", t2)) 189 assert(topointer(t1) ~= topointer(t2))
184 end 190 end
185 191
186 do -- short strings are internalized 192 do -- short strings are internalized
187 local s1 = string.rep("a", 10) 193 local s1 = string.rep("a", 10)
188 local s2 = string.rep("aa", 5) 194 local s2 = string.rep("aa", 5)
189 assert(string.format("%p", s1) == string.format("%p", s2)) 195 assert(topointer(s1) == topointer(s2))
190 end 196 end
191 197
192 do -- long strings aren't internalized 198 do -- long strings aren't internalized
193 local s1 = string.rep("a", 300); local s2 = string.rep("a", 300) 199 local s1 = string.rep("a", 300); local s2 = string.rep("a", 300)
194 assert(string.format("%p", s1) ~= string.format("%p", s2)) 200 assert(topointer(s1) ~= topointer(s2))
195 end 201 end
196end 202end
197 203
@@ -521,6 +527,20 @@ else
521 testpfs("P", str, {}) 527 testpfs("P", str, {})
522end 528end
523 529
530if T == nil then
531 (Message or print)('\n >>> testC not active: skipping external strings tests <<<\n')
532else
533 print("testing external strings")
534 local x = T.externKstr("hello") -- external fixed short string
535 assert(x == "hello")
536 local x = T.externstr("hello") -- external allocated short string
537 assert(x == "hello")
538 x = string.rep("a", 100) -- long string
539 local y = T.externKstr(x) -- external fixed long string
540 assert(y == x)
541 local z = T.externstr(x) -- external allocated long string
542 assert(z == y)
543end
524 544
525print('OK') 545print('OK')
526 546