diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2018-07-27 07:35:24 +0200 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2018-07-27 07:35:24 +0200 |
| commit | c325be435c64be57cf2210fa6936af0d425d0ce0 (patch) | |
| tree | 0a6398c67346ff8df989994e7e29d4110c515889 /tests | |
| parent | 3c76f8f5edf602b023672f8d8f317b0eea2f1195 (diff) | |
| download | lua-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-x | tests/test.lua | 19 | ||||
| -rw-r--r-- | tests/testmod.c | 16 |
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)) | |||
| 664 | print("isinteger", mod.isinteger(math.huge)) | 664 | print("isinteger", mod.isinteger(math.huge)) |
| 665 | print("isinteger", mod.isinteger(math.sqrt(-1))) | 665 | print("isinteger", mod.isinteger(math.sqrt(-1))) |
| 666 | 666 | ||
| 667 | |||
| 668 | ___'' | 667 | ___'' |
| 669 | print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) | 668 | print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) |
| 670 | print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) | 669 | print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) |
| 671 | print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) | 670 | print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) |
| 672 | print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) | 671 | print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) |
| 673 | 672 | ||
| 674 | |||
| 675 | ___'' | 673 | ___'' |
| 676 | print("strtonum", mod.strtonum("+123")) | 674 | print("strtonum", mod.strtonum("+123")) |
| 677 | print("strtonum", mod.strtonum(" 123 ")) | 675 | print("strtonum", mod.strtonum(" 123 ")) |
| @@ -679,7 +677,6 @@ print("strtonum", mod.strtonum("-1.23")) | |||
| 679 | print("strtonum", mod.strtonum(" 123 abc")) | 677 | print("strtonum", mod.strtonum(" 123 abc")) |
| 680 | print("strtonum", mod.strtonum("jkl")) | 678 | print("strtonum", mod.strtonum("jkl")) |
| 681 | 679 | ||
| 682 | |||
| 683 | ___'' | 680 | ___'' |
| 684 | local a, b, c = mod.requiref() | 681 | local a, b, c = mod.requiref() |
| 685 | print("requiref", type(a), type(b), type(c), | 682 | print("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 | ___'' |
| 687 | mod.extraspace("abc") | ||
| 688 | print("getextraspace", mod.extraspace("xyz")) | ||
| 689 | local 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")) | ||
| 694 | end) | ||
| 695 | c() | ||
| 696 | print("getextraspace", mod.extraspace("456")) | ||
| 697 | c() | ||
| 698 | print("getextraspace", mod.extraspace("789")) | ||
| 699 | |||
| 700 | ___'' | ||
| 690 | local proxy, backend = {}, {} | 701 | local proxy, backend = {}, {} |
| 691 | setmetatable(proxy, { __index = backend, __newindex = backend }) | 702 | setmetatable(proxy, { __index = backend, __newindex = backend }) |
| 692 | print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) | 703 | print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) |
| @@ -705,7 +716,7 @@ print("tonumber", mod.tonumber("error")) | |||
| 705 | 716 | ||
| 706 | ___'' | 717 | ___'' |
| 707 | print("tointeger", mod.tointeger(12)) | 718 | print("tointeger", mod.tointeger(12)) |
| 708 | print("tointeger", mod.tointeger(-12)) | 719 | print("tointeger", mod.tointeger(12)) |
| 709 | print("tointeger", mod.tointeger(12.1)) | 720 | print("tointeger", mod.tointeger(12.1)) |
| 710 | print("tointeger", mod.tointeger(12.9)) | 721 | print("tointeger", mod.tointeger(12.9)) |
| 711 | print("tointeger", mod.tointeger(-12.1)) | 722 | print("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 | |||
| 70 | static 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 }, |
