diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/strings.lua | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/testes/strings.lua b/testes/strings.lua index 2ce3ebc3..4a10857e 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
| @@ -158,28 +158,38 @@ do -- tests for '%p' format | |||
| 158 | -- not much to test, as C does not specify what '%p' does. | 158 | -- not much to test, as C does not specify what '%p' does. |
| 159 | -- ("The value of the pointer is converted to a sequence of printing | 159 | -- ("The value of the pointer is converted to a sequence of printing |
| 160 | -- characters, in an implementation-defined manner.") | 160 | -- characters, in an implementation-defined manner.") |
| 161 | local null = string.format("%p", nil) | 161 | local null = "(null)" -- nulls are formatted by Lua |
| 162 | assert(string.format("%p", {}) ~= null) | ||
| 163 | assert(string.format("%p", 4) == null) | 162 | assert(string.format("%p", 4) == null) |
| 164 | assert(string.format("%p", true) == null) | 163 | assert(string.format("%p", true) == null) |
| 164 | assert(string.format("%p", nil) == null) | ||
| 165 | assert(string.format("%p", {}) ~= null) | ||
| 165 | assert(string.format("%p", print) ~= null) | 166 | assert(string.format("%p", print) ~= null) |
| 166 | assert(string.format("%p", coroutine.running()) ~= null) | 167 | assert(string.format("%p", coroutine.running()) ~= null) |
| 167 | assert(string.format("%p", io.stdin) ~= null) | 168 | assert(string.format("%p", io.stdin) ~= null) |
| 168 | assert(string.format("%p", io.stdin) == string.format("%p", io.stdin)) | 169 | assert(string.format("%p", io.stdin) == string.format("%p", io.stdin)) |
| 170 | assert(string.format("%p", print) == string.format("%p", print)) | ||
| 171 | assert(string.format("%p", print) ~= string.format("%p", assert)) | ||
| 172 | |||
| 173 | assert(#string.format("%90p", {}) == 90) | ||
| 174 | assert(#string.format("%-60p", {}) == 60) | ||
| 175 | assert(string.format("%10p", false) == string.rep(" ", 10 - #null) .. null) | ||
| 176 | assert(string.format("%-12p", 1.5) == null .. string.rep(" ", 12 - #null)) | ||
| 177 | |||
| 169 | do | 178 | do |
| 170 | local t1 = {}; local t2 = {} | 179 | local t1 = {}; local t2 = {} |
| 171 | assert(string.format("%p", t1) ~= string.format("%p", t2)) | 180 | assert(string.format("%p", t1) ~= string.format("%p", t2)) |
| 172 | end | 181 | end |
| 182 | |||
| 173 | do -- short strings are internalized | 183 | do -- short strings are internalized |
| 174 | local s1 = string.rep("a", 10) | 184 | local s1 = string.rep("a", 10) |
| 175 | local s2 = string.rep("a", 10) | 185 | local s2 = string.rep("aa", 5) |
| 176 | assert(string.format("%p", s1) == string.format("%p", s2)) | 186 | assert(string.format("%p", s1) == string.format("%p", s2)) |
| 177 | end | 187 | end |
| 188 | |||
| 178 | do -- long strings aren't internalized | 189 | do -- long strings aren't internalized |
| 179 | local s1 = string.rep("a", 300); local s2 = string.rep("a", 300) | 190 | local s1 = string.rep("a", 300); local s2 = string.rep("a", 300) |
| 180 | assert(string.format("%p", s1) ~= string.format("%p", s2)) | 191 | assert(string.format("%p", s1) ~= string.format("%p", s2)) |
| 181 | end | 192 | end |
| 182 | assert(#string.format("%90p", {}) == 90) | ||
| 183 | end | 193 | end |
| 184 | 194 | ||
| 185 | x = '"ílo"\n\\' | 195 | x = '"ílo"\n\\' |
