diff options
Diffstat (limited to 'vendor/compat53/tests')
-rwxr-xr-x | vendor/compat53/tests/test-bit32.lua | 9 | ||||
-rwxr-xr-x | vendor/compat53/tests/test.lua | 33 | ||||
-rw-r--r-- | vendor/compat53/tests/testmod.c | 18 |
3 files changed, 56 insertions, 4 deletions
diff --git a/vendor/compat53/tests/test-bit32.lua b/vendor/compat53/tests/test-bit32.lua new file mode 100755 index 0000000..cc91e52 --- /dev/null +++ b/vendor/compat53/tests/test-bit32.lua @@ -0,0 +1,9 @@ +#!/usr/bin/env lua + +local bit32 = require("bit32") + + +assert(bit32.bnot(0) == 2^32-1) +assert(bit32.band(1, 3, 5) == 1) +assert(bit32.bor(1, 3, 5) == 7) + diff --git a/vendor/compat53/tests/test.lua b/vendor/compat53/tests/test.lua index c2c0abf..0640cae 100755 --- a/vendor/compat53/tests/test.lua +++ b/vendor/compat53/tests/test.lua @@ -664,14 +664,12 @@ print("isinteger", mod.isinteger(12.3)) print("isinteger", mod.isinteger(math.huge)) print("isinteger", mod.isinteger(math.sqrt(-1))) - ___'' print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) - ___'' print("strtonum", mod.strtonum("+123")) print("strtonum", mod.strtonum(" 123 ")) @@ -679,7 +677,6 @@ print("strtonum", mod.strtonum("-1.23")) print("strtonum", mod.strtonum(" 123 abc")) print("strtonum", mod.strtonum("jkl")) - ___'' local a, b, c = mod.requiref() print("requiref", type(a), type(b), type(c), @@ -687,6 +684,34 @@ print("requiref", type(a), type(b), type(c), type(requiref1), type(requiref2), type(requiref3)) ___'' +local c = coroutine.wrap(function() + mod.extraspace("uvw") + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) +end) +c() +mod.extraspace("abc") +print("getextraspace", mod.extraspace()) +c() +local d = coroutine.wrap(function() + print("getextraspace", mod.extraspace()) + mod.extraspace("xyz") + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) +end) +d() +print("getextraspace", mod.extraspace()) +mod.extraspace("123") +c() +d() + +___'' local proxy, backend = {}, {} setmetatable(proxy, { __index = backend, __newindex = backend }) print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) @@ -705,7 +730,7 @@ print("tonumber", mod.tonumber("error")) ___'' print("tointeger", mod.tointeger(12)) -print("tointeger", mod.tointeger(-12)) +print("tointeger", mod.tointeger(12)) print("tointeger", mod.tointeger(12.1)) print("tointeger", mod.tointeger(12.9)) print("tointeger", mod.tointeger(-12.1)) diff --git a/vendor/compat53/tests/testmod.c b/vendor/compat53/tests/testmod.c index cd56e76..0d73ed4 100644 --- a/vendor/compat53/tests/testmod.c +++ b/vendor/compat53/tests/testmod.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <errno.h> #include "compat-5.3.h" @@ -63,6 +64,21 @@ static int test_getseti (lua_State *L) { } +#ifndef LUA_EXTRASPACE +#define LUA_EXTRASPACE (sizeof(void*)) +#endif + +static int test_getextraspace (lua_State *L) { + size_t len = 0; + char const* s = luaL_optlstring(L, 1, NULL, &len); + char* p = (char*)lua_getextraspace(L); + lua_pushstring(L, p); + if (s) + memcpy(p, s, len > LUA_EXTRASPACE-1 ? LUA_EXTRASPACE-1 : len+1); + return 1; +} + + /* additional tests for Lua5.1 */ #define NUP 3 @@ -270,6 +286,7 @@ static int test_buffer (lua_State *L) { static int test_exec (lua_State *L) { const char *cmd = luaL_checkstring(L, 1); + errno = 0; return luaL_execresult(L, system(cmd)); } @@ -307,6 +324,7 @@ static const luaL_Reg funcs[] = { { "strtonum", test_str2num }, { "requiref", test_requiref }, { "getseti", test_getseti }, + { "extraspace", test_getextraspace }, { "newproxy", test_newproxy }, { "arith", test_arith }, { "compare", test_compare }, |