aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2020-07-09 22:56:47 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2020-07-09 22:56:47 +1000
commitde60088d19ff006b4feceb780e97a15611fe2905 (patch)
treef33c3c0e1ff38f18b539f5435aef4582473e7f77 /tests
parent942e9fb5c80368fe93ca195bc14272b2d4cd2881 (diff)
downloadluaossl-de60088d19ff006b4feceb780e97a15611fe2905.tar.gz
luaossl-de60088d19ff006b4feceb780e97a15611fe2905.tar.bz2
luaossl-de60088d19ff006b4feceb780e97a15611fe2905.zip
Squashed 'vendor/compat53/' changes from daebe77..7b783fb
7b783fb Fix repository name in rockspec 7e2b0b5 Add bit32 library 931652a Make it usable on Lua 5.4 a1735f6 Update backports to Lua 5.3.5 versions 01a43c0 Fix feature detection for strerror_r 71293f7 Fix structure initialization in compat53 lua_load 73fb49f Make test C module compile as C++ again. d7f9021 Link to `lua_getextraspace` quirks in README.md. 45ae6fe Improve `lua_getextraspace` tests. c325be4 Add an implementation of `lua_getextraspace()`. 3c76f8f Add rockspec for v0.7 release. git-subtree-dir: vendor/compat53 git-subtree-split: 7b783fb8efac60de8be91522d5731a9716e83d56
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test-bit32.lua9
-rwxr-xr-xtests/test.lua33
-rw-r--r--tests/testmod.c18
3 files changed, 56 insertions, 4 deletions
diff --git a/tests/test-bit32.lua b/tests/test-bit32.lua
new file mode 100755
index 0000000..cc91e52
--- /dev/null
+++ b/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/tests/test.lua b/tests/test.lua
index c2c0abf..0640cae 100755
--- a/tests/test.lua
+++ b/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/tests/testmod.c b/tests/testmod.c
index cd56e76..0d73ed4 100644
--- a/tests/testmod.c
+++ b/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 },