aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-03-13 14:04:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-03-13 14:04:01 -0300
commitdfebe439db76b5c9fd9b4e3877857e2449c8ad87 (patch)
treec31aa85dc53d1c0e0704060f313b682765dd459c /testes
parentcf71a5ddc742692fad813f89f1c9ef53e1ffde0f (diff)
downloadlua-dfebe439db76b5c9fd9b4e3877857e2449c8ad87.tar.gz
lua-dfebe439db76b5c9fd9b4e3877857e2449c8ad87.tar.bz2
lua-dfebe439db76b5c9fd9b4e3877857e2449c8ad87.zip
New conversion specifier '%p' for 'string.format'
The call 'string.format("%p", val)' gives a Lua equivalent to the C API function 'lua_topointer'.
Diffstat (limited to 'testes')
-rw-r--r--testes/strings.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/testes/strings.lua b/testes/strings.lua
index da53a87e..8bcbb391 100644
--- a/testes/strings.lua
+++ b/testes/strings.lua
@@ -153,6 +153,22 @@ else -- compatible coercion
153 assert(tostring(-1203 + 0.0) == "-1203") 153 assert(tostring(-1203 + 0.0) == "-1203")
154end 154end
155 155
156do -- tests for '%p' format
157 -- not much to test, as C does not specify what '%p' does.
158 -- ("The value of the pointer is converted to a sequence of printing
159 -- characters, in an implementation-defined manner.")
160 local null = string.format("%p", nil)
161 assert(string.format("%p", {}) ~= null)
162 assert(string.format("%p", 4) == null)
163 assert(string.format("%p", print) ~= null)
164 assert(string.format("%p", coroutine.running()) ~= null)
165 assert(string.format("%p", {}) ~= string.format("%p", {}))
166 assert(string.format("%p", string.rep("a", 10)) ==
167 string.format("%p", string.rep("a", 10))) -- short strings
168 assert(string.format("%p", string.rep("a", 300)) ~=
169 string.format("%p", string.rep("a", 300))) -- long strings
170 assert(#string.format("%90p", {}) == 90)
171end
156 172
157x = '"�lo"\n\\' 173x = '"�lo"\n\\'
158assert(string.format('%q%s', x, x) == '"\\"�lo\\"\\\n\\\\""�lo"\n\\') 174assert(string.format('%q%s', x, x) == '"\\"�lo\\"\\\n\\\\""�lo"\n\\')