aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2018-07-27 07:35:24 +0200
committerPhilipp Janda <siffiejoe@gmx.net>2018-07-27 07:35:24 +0200
commitc325be435c64be57cf2210fa6936af0d425d0ce0 (patch)
tree0a6398c67346ff8df989994e7e29d4110c515889 /tests
parent3c76f8f5edf602b023672f8d8f317b0eea2f1195 (diff)
downloadlua-compat-5.3-c325be435c64be57cf2210fa6936af0d425d0ce0.tar.gz
lua-compat-5.3-c325be435c64be57cf2210fa6936af0d425d0ce0.tar.bz2
lua-compat-5.3-c325be435c64be57cf2210fa6936af0d425d0ce0.zip
Add an implementation of `lua_getextraspace()`.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.lua19
-rw-r--r--tests/testmod.c16
2 files changed, 31 insertions, 4 deletions
diff --git a/tests/test.lua b/tests/test.lua
index c2c0abf..9bb08da 100755
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -664,14 +664,12 @@ print("isinteger", mod.isinteger(12.3))
664print("isinteger", mod.isinteger(math.huge)) 664print("isinteger", mod.isinteger(math.huge))
665print("isinteger", mod.isinteger(math.sqrt(-1))) 665print("isinteger", mod.isinteger(math.sqrt(-1)))
666 666
667
668___'' 667___''
669print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) 668print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6))
670print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) 669print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6))
671print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) 670print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6))
672print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) 671print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6))
673 672
674
675___'' 673___''
676print("strtonum", mod.strtonum("+123")) 674print("strtonum", mod.strtonum("+123"))
677print("strtonum", mod.strtonum(" 123 ")) 675print("strtonum", mod.strtonum(" 123 "))
@@ -679,7 +677,6 @@ print("strtonum", mod.strtonum("-1.23"))
679print("strtonum", mod.strtonum(" 123 abc")) 677print("strtonum", mod.strtonum(" 123 abc"))
680print("strtonum", mod.strtonum("jkl")) 678print("strtonum", mod.strtonum("jkl"))
681 679
682
683___'' 680___''
684local a, b, c = mod.requiref() 681local a, b, c = mod.requiref()
685print("requiref", type(a), type(b), type(c), 682print("requiref", type(a), type(b), type(c),
@@ -687,6 +684,20 @@ print("requiref", type(a), type(b), type(c),
687 type(requiref1), type(requiref2), type(requiref3)) 684 type(requiref1), type(requiref2), type(requiref3))
688 685
689___'' 686___''
687mod.extraspace("abc")
688print("getextraspace", mod.extraspace("xyz"))
689local c = coroutine.wrap(function()
690 print("getextraspace", mod.extraspace("uvw"))
691 print("getextraspace", mod.extraspace("123"))
692 coroutine.yield()
693 print("getextraspace", mod.extraspace("asd"))
694end)
695c()
696print("getextraspace", mod.extraspace("456"))
697c()
698print("getextraspace", mod.extraspace("789"))
699
700___''
690local proxy, backend = {}, {} 701local proxy, backend = {}, {}
691setmetatable(proxy, { __index = backend, __newindex = backend }) 702setmetatable(proxy, { __index = backend, __newindex = backend })
692print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) 703print("geti/seti", rawget(proxy, 1), rawget(backend, 1))
@@ -705,7 +716,7 @@ print("tonumber", mod.tonumber("error"))
705 716
706___'' 717___''
707print("tointeger", mod.tointeger(12)) 718print("tointeger", mod.tointeger(12))
708print("tointeger", mod.tointeger(-12)) 719print("tointeger", mod.tointeger(12))
709print("tointeger", mod.tointeger(12.1)) 720print("tointeger", mod.tointeger(12.1))
710print("tointeger", mod.tointeger(12.9)) 721print("tointeger", mod.tointeger(12.9))
711print("tointeger", mod.tointeger(-12.1)) 722print("tointeger", mod.tointeger(-12.1))
diff --git a/tests/testmod.c b/tests/testmod.c
index cd56e76..345a8c9 100644
--- a/tests/testmod.c
+++ b/tests/testmod.c
@@ -63,6 +63,21 @@ static int test_getseti (lua_State *L) {
63} 63}
64 64
65 65
66#ifndef LUA_EXTRASPACE
67#define LUA_EXTRASPACE (sizeof(void*))
68#endif
69
70static int test_getextraspace (lua_State *L) {
71 size_t len = 0;
72 char const* s = luaL_optlstring(L, 1, NULL, &len);
73 void* p = lua_getextraspace(L);
74 lua_pushstring(L, p);
75 if (s)
76 memcpy(p, s, len > LUA_EXTRASPACE-1 ? LUA_EXTRASPACE-1 : len+1);
77 return 1;
78}
79
80
66/* additional tests for Lua5.1 */ 81/* additional tests for Lua5.1 */
67#define NUP 3 82#define NUP 3
68 83
@@ -307,6 +322,7 @@ static const luaL_Reg funcs[] = {
307 { "strtonum", test_str2num }, 322 { "strtonum", test_str2num },
308 { "requiref", test_requiref }, 323 { "requiref", test_requiref },
309 { "getseti", test_getseti }, 324 { "getseti", test_getseti },
325 { "extraspace", test_getextraspace },
310 { "newproxy", test_newproxy }, 326 { "newproxy", test_newproxy },
311 { "arith", test_arith }, 327 { "arith", test_arith },
312 { "compare", test_compare }, 328 { "compare", test_compare },