diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/strings.lua | 26 |
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") |
| 158 | end | 158 | end |
| 159 | 159 | ||
| 160 | |||
| 161 | local function topointer (s) | ||
| 162 | return string.format("%p", s) | ||
| 163 | end | ||
| 164 | |||
| 165 | |||
| 160 | do -- tests for '%p' format | 166 | do -- 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 |
| 196 | end | 202 | end |
| 197 | 203 | ||
| @@ -521,6 +527,20 @@ else | |||
| 521 | testpfs("P", str, {}) | 527 | testpfs("P", str, {}) |
| 522 | end | 528 | end |
| 523 | 529 | ||
| 530 | if T == nil then | ||
| 531 | (Message or print)('\n >>> testC not active: skipping external strings tests <<<\n') | ||
| 532 | else | ||
| 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) | ||
| 543 | end | ||
| 524 | 544 | ||
| 525 | print('OK') | 545 | print('OK') |
| 526 | 546 | ||
