summaryrefslogtreecommitdiff
path: root/testes/strings.lua
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/strings.lua
parentcf71a5ddc742692fad813f89f1c9ef53e1ffde0f (diff)
downloadlua-github-dfebe439db76b5c9fd9b4e3877857e2449c8ad87.tar.gz
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/strings.lua')
-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
assert(tostring(-1203 + 0.0) == "-1203")
end
+do -- tests for '%p' format
+ -- not much to test, as C does not specify what '%p' does.
+ -- ("The value of the pointer is converted to a sequence of printing
+ -- characters, in an implementation-defined manner.")
+ local null = string.format("%p", nil)
+ assert(string.format("%p", {}) ~= null)
+ assert(string.format("%p", 4) == null)
+ assert(string.format("%p", print) ~= null)
+ assert(string.format("%p", coroutine.running()) ~= null)
+ assert(string.format("%p", {}) ~= string.format("%p", {}))
+ assert(string.format("%p", string.rep("a", 10)) ==
+ string.format("%p", string.rep("a", 10))) -- short strings
+ assert(string.format("%p", string.rep("a", 300)) ~=
+ string.format("%p", string.rep("a", 300))) -- long strings
+ assert(#string.format("%90p", {}) == 90)
+end
x = '"ílo"\n\\'
assert(string.format('%q%s', x, x) == '"\\"ílo\\"\\\n\\\\""ílo"\n\\')