From 65d022bf3d7330a3d8dc69c08e07a81f25b8ba4b Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sat, 14 Apr 2018 14:53:11 +1000 Subject: test/test-suite: Move ported PUC-Rio test suite to jest --- test/test-suite/tpack.test.js | 496 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 496 insertions(+) create mode 100644 test/test-suite/tpack.test.js (limited to 'test/test-suite/tpack.test.js') diff --git a/test/test-suite/tpack.test.js b/test/test-suite/tpack.test.js new file mode 100644 index 0000000..132956e --- /dev/null +++ b/test/test-suite/tpack.test.js @@ -0,0 +1,496 @@ +"use strict"; + +const lua = require('../../src/lua.js'); +const lauxlib = require('../../src/lauxlib.js'); +const lualib = require('../../src/lualib.js'); +const {to_luastring} = require("../../src/fengaricore.js"); + +const prefix = ` + local pack = string.pack + local packsize = string.packsize + local unpack = string.unpack + + function checkerror (msg, f, ...) + local status, err = pcall(f, ...) + -- print(status, err, msg) + assert(not status and string.find(err, msg)) + end + + local NB = 16 + + local sizeshort = packsize("h") + local sizeint = packsize("i") + local sizelong = packsize("l") + local sizesize_t = packsize("T") + local sizeLI = packsize("j") + local sizefloat = packsize("f") + local sizedouble = packsize("d") + local sizenumber = packsize("n") + local little = (pack("i2", 1) == "\\1\\0") + local align = packsize("!xXi16") +`; + +test("[test-suite] tpack: maximum size for integers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + assert(1 <= sizeshort and sizeshort <= sizeint and sizeint <= sizelong and + sizefloat <= sizedouble) + + print("platform:") + print(string.format( + "\\tshort %d, int %d, long %d, size_t %d, float %d, double %d,\\n\\z + \\tlua Integer %d, lua Number %d", + sizeshort, sizeint, sizelong, sizesize_t, sizefloat, sizedouble, + sizeLI, sizenumber)) + print("\\t" .. (little and "little" or "big") .. " endian") + print("\\talignment: " .. align) + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + assert(unpack("B", pack("B", 0xff)) == 0xff) + assert(unpack("b", pack("b", 0x7f)) == 0x7f) + assert(unpack("b", pack("b", -0x80)) == -0x80) + + assert(unpack("H", pack("H", 0xffff)) == 0xffff) + assert(unpack("h", pack("h", 0x7fff)) == 0x7fff) + assert(unpack("h", pack("h", -0x8000)) == -0x8000) + + assert(unpack("L", pack("L", 0xffffffff)) == 0xffffffff) + assert(unpack("l", pack("l", 0x7fffffff)) == 0x7fffffff) + assert(unpack("l", pack("l", -0x80000000)) == -0x80000000) + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + for i = 1, NB do + -- small numbers with signal extension ("\\xFF...") + local s = string.rep("\\xff", i) + assert(pack("i" .. i, -1) == s) + assert(packsize("i" .. i) == #s) + assert(unpack("i" .. i, s) == -1) + + -- small unsigned number ("\\0...\\xAA") + s = "\\xAA" .. string.rep("\\0", i - 1) + assert(pack("I" .. i, 0xAA) == s:reverse()) + assert(unpack(">I" .. i, s:reverse()) == 0xAA) + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + do + local lnum = 0x13121110090807060504030201 + local s = pack("i" .. i, ("\\xFF"):rep(i - sizeLI) .. s:reverse()) == -lnum) + assert(unpack("i" .. i, "\\1" .. ("\\x00"):rep(i - 1)) + end + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + for i = 1, sizeLI do + local lstr = "\\1\\2\\3\\4\\5\\6\\7\\8\\9\\10\\11\\12\\13" + local lnum = 0x13121110090807060504030201 + local n = lnum & (~(-1 << (i * 8))) + local s = string.sub(lstr, 1, i) + assert(pack("i" .. i, n) == s:reverse()) + assert(unpack(">i" .. i, s:reverse()) == n) + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: sign extension", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + do + local u = 0xf0 + for i = 1, sizeLI - 1 do + assert(unpack("I"..i, "\\xf0"..("\\xff"):rep(i - 1)) == u) + u = u * 256 + 0xff + end + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: mixed endianness", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + do + assert(pack(">i2 i2", "\\10\\0\\0\\20") + assert(a == 10 and b == 20) + assert(pack("=i4", 2001) == pack("i4", 2001)) + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: testing invalid formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + checkerror("out of limits", pack, "i0", 0) + checkerror("out of limits", pack, "i" .. NB + 1, 0) + checkerror("out of limits", pack, "!" .. NB + 1, 0) + checkerror("%(17%) out of limits %[1,16%]", pack, "Xi" .. NB + 1) + checkerror("invalid format option 'r'", pack, "i3r", 0) + checkerror("16%-byte integer", unpack, "i16", string.rep('\\3', 16)) + checkerror("not power of 2", pack, "!4i3", 0); + checkerror("missing size", pack, "c", "") + checkerror("variable%-length format", packsize, "s") + checkerror("variable%-length format", packsize, "z") + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: overflow in option size (error will be in digit after limit)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + checkerror("invalid format", packsize, "c1" .. string.rep("0", 40)) + + if packsize("i") == 4 then + -- result would be 2^31 (2^3 repetitions of 2^28 strings) + local s = string.rep("c268435456", 2^3) + checkerror("too large", packsize, s) + -- one less is OK + s = string.rep("c268435456", 2^3 - 1) .. "c268435455" + assert(packsize(s) == 0x7fffffff) + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: overflow in packing", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + for i = 1, sizeLI - 1 do + local umax = (1 << (i * 8)) - 1 + local max = umax >> 1 + local min = ~max + checkerror("overflow", pack, "I" .. i, umax + 1) + + checkerror("overflow", pack, ">i" .. i, umax) + checkerror("overflow", pack, ">i" .. i, max + 1) + checkerror("overflow", pack, "i" .. i, pack(">i" .. i, max)) == max) + assert(unpack("I" .. i, pack(">I" .. i, umax)) == umax) + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: Lua integer size", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + assert(unpack(">j", pack(">j", math.maxinteger)) == math.maxinteger) + assert(unpack("f", 24)) + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: testing pack/unpack of floating-point numbers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + for _, n in ipairs{0, -1.1, 1.9, 1/0, -1/0, 1e20, -1e20, 0.1, 2000.7} do + assert(unpack("n", pack("n", n)) == n) + assert(unpack("n", pack(">n", n)) == n) + assert(pack("f", n):reverse()) + assert(pack(">d", n) == pack("f", pack(">f", n)) == n) + assert(unpack("d", pack(">d", n)) == n) + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: testing pack/unpack of strings", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + do + local s = string.rep("abc", 1000) + assert(pack("zB", s, 247) == s .. "\\0\\xF7") + local s1, b = unpack("zB", s .. "\\0\\xF9") + assert(b == 249 and s1 == s) + s1 = pack("s", s) + assert(unpack("s", s1) == s) + + checkerror("does not fit", pack, "s1", s) + + checkerror("contains zeros", pack, "z", "alo\\0"); + + for i = 2, NB do + local s1 = pack("s" .. i, s) + assert(unpack("s" .. i, s1) == s and #s1 == #s + i) + end + end + + do + local x = pack("s", "alo") + checkerror("too short", unpack, "s", x:sub(1, -2)) + checkerror("too short", unpack, "c5", "abcd") + checkerror("out of limits", pack, "s100", "alo") + end + + do + assert(pack("c0", "") == "") + assert(packsize("c0") == 0) + assert(unpack("c0", "") == "") + assert(pack("!4 c6", "abcdef") == "abcdef") + assert(pack("c3", "123") == "123") + assert(pack("c0", "") == "") + assert(pack("c8", "123456") == "123456\\0\\0") + assert(pack("c88", "") == string.rep("\\0", 88)) + assert(pack("c188", "ab") == "ab" .. string.rep("\\0", 188 - 2)) + local a, b, c = unpack("!4 z c3", "abcdefghi\\0xyz") + assert(a == "abcdefghi" and b == "xyz" and c == 14) + checkerror("longer than", pack, "c3", "1234") + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: testing multiple types and sequence", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + do + local x = pack(" { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + do + assert(pack(" < i1 i2 ", 2, 3) == "\\2\\3\\0") -- no alignment by default + local x = pack(">!8 b Xh i4 i8 c1 Xi8", -12, 100, 200, "\\xEC") + assert(#x == packsize(">!8 b Xh i4 i8 c1 Xi8")) + assert(x == "\\xf4" .. "\\0\\0\\0" .. + "\\0\\0\\0\\100" .. + "\\0\\0\\0\\0\\0\\0\\0\\xC8" .. + "\\xEC" .. "\\0\\0\\0\\0\\0\\0\\0") + local a, b, c, d, pos = unpack(">!8 c1 Xh i4 i8 b Xi8 XI XH", x) + assert(a == "\\xF4" and b == 100 and c == 200 and d == -20 and (pos - 1) == #x) + + x = pack(">!4 c3 c4 c2 z i4 c5 c2 Xi4", + "abc", "abcd", "xz", "hello", 5, "world", "xy") + assert(x == "abcabcdxzhello\\0\\0\\0\\0\\0\\5worldxy\\0") + local a, b, c, d, e, f, g, pos = unpack(">!4 c3 c4 c2 z i4 c5 c2 Xh Xi4", x) + assert(a == "abc" and b == "abcd" and c == "xz" and d == "hello" and + e == 5 and f == "world" and g == "xy" and (pos - 1) % 4 == 0) + + x = pack(" b b Xd b Xb x", 1, 2, 3) + assert(packsize(" b b Xd b Xb x") == 4) + assert(x == "\\1\\2\\3\\0") + a, b, c, pos = unpack("bbXdb", x) + assert(a == 1 and b == 2 and c == 3 and pos == #x) + + -- only alignment + assert(packsize("!8 xXi8") == 8) + local pos = unpack("!8 xXi8", "0123456701234567"); assert(pos == 9) + assert(packsize("!8 xXi2") == 2) + local pos = unpack("!8 xXi2", "0123456701234567"); assert(pos == 3) + assert(packsize("!2 xXi2") == 2) + local pos = unpack("!2 xXi2", "0123456701234567"); assert(pos == 3) + assert(packsize("!2 xXi8") == 2) + local pos = unpack("!2 xXi8", "0123456701234567"); assert(pos == 3) + assert(packsize("!16 xXi16") == 16) + local pos = unpack("!16 xXi16", "0123456701234567"); assert(pos == 17) + + checkerror("invalid next option", pack, "X") + checkerror("invalid next option", unpack, "XXi", "") + checkerror("invalid next option", unpack, "X i", "") + checkerror("invalid next option", pack, "Xc1") + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] tpack: testing initial position", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + do + local x = pack("i4i4i4i4", 1, 2, 3, 4) + for pos = 1, 16, 4 do + local i, p = unpack("i4", x, pos) + assert(i == pos//4 + 1 and p == pos + 4) + end + + -- with alignment + for pos = 0, 12 do -- will always round position to power of 2 + local i, p = unpack("!4 i4", x, pos + 1) + assert(i == (pos + 3)//4 + 1 and p == i*4 + 1) + end + + -- negative indices + local i, p = unpack("!4 i4", x, -4) + assert(i == 4 and p == 17) + local i, p = unpack("!4 i4", x, -7) + assert(i == 4 and p == 17) + local i, p = unpack("!4 i4", x, -#x) + assert(i == 1 and p == 5) + + -- limits + for i = 1, #x + 1 do + assert(unpack("c0", x, i) == "") + end + checkerror("out of string", unpack, "c0", x, 0) + checkerror("out of string", unpack, "c0", x, #x + 2) + checkerror("out of string", unpack, "c0", x, -(#x + 1)) + + end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); -- cgit v1.2.3-54-g00ecf From e9986b9189e2358f9c1a005412a792b7795643d2 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sat, 14 Apr 2018 15:03:54 +1000 Subject: test/test-suite: Remove print calls --- test/lbaselib.test.js | 1 - test/test-suite/api.test.js | 2 +- test/test-suite/attrib.test.js | 2 +- test/test-suite/code.test.js | 2 +- test/test-suite/constructs.test.js | 2 +- test/test-suite/db.test.js | 3 +- test/test-suite/math.test.js | 124 +++++++++++++++++++------------------ test/test-suite/sort.test.js | 6 +- test/test-suite/strings.test.js | 2 +- test/test-suite/tpack.test.js | 16 ++--- test/test-suite/vararg.test.js | 2 +- 11 files changed, 81 insertions(+), 81 deletions(-) (limited to 'test/test-suite/tpack.test.js') diff --git a/test/lbaselib.test.js b/test/lbaselib.test.js index 259de36..dc30a98 100644 --- a/test/lbaselib.test.js +++ b/test/lbaselib.test.js @@ -28,7 +28,6 @@ test('setmetatable, getmetatable', () => { let luaCode = ` local mt = { __index = function () - print("hello") return "hello" end } diff --git a/test/test-suite/api.test.js b/test/test-suite/api.test.js index 152ddcf..5a5e10e 100644 --- a/test/test-suite/api.test.js +++ b/test/test-suite/api.test.js @@ -686,7 +686,7 @@ test("[test-suite] api: test errors in non protected threads", () => { if not _soft then checkerrnopro("pushnum 3; call 0 0", "attempt to call") - print"testing stack overflow in unprotected thread" + -- print"testing stack overflow in unprotected thread" function f () f() end checkerrnopro("getglobal 'f'; call 0 0;", "stack overflow") end diff --git a/test/test-suite/attrib.test.js b/test/test-suite/attrib.test.js index 596c82c..bb07e62 100644 --- a/test/test-suite/attrib.test.js +++ b/test/test-suite/attrib.test.js @@ -23,7 +23,7 @@ test("[test-suite] attrib: testing require", () => { assert(type(package.preload) == "table") assert(type(package.config) == "string") - print("package config: "..string.gsub(package.config, "\\n", "|")) + -- print("package config: "..string.gsub(package.config, "\\n", "|")) do -- create a path with 'max' templates, diff --git a/test/test-suite/code.test.js b/test/test-suite/code.test.js index d37030c..377dd63 100644 --- a/test/test-suite/code.test.js +++ b/test/test-suite/code.test.js @@ -45,7 +45,7 @@ const prefix = ` local arg = {...} local c = T.listcode(f) for i=1, #arg do - print(arg[i], c[i]) + -- print(arg[i], c[i]) assert(string.find(c[i], '- '..arg[i]..' *%d')) end assert(c[#arg+2] == nil) diff --git a/test/test-suite/constructs.test.js b/test/test-suite/constructs.test.js index de0648d..e79778a 100644 --- a/test/test-suite/constructs.test.js +++ b/test/test-suite/constructs.test.js @@ -332,7 +332,7 @@ test.skip('[test-suite] constructs: huge loops, upvalue', () => { IX = false assert(p() == v[2] and IX == not not v[2]) i = i + 1 - if i % 60000 == 0 then print('+') end + -- if i % 60000 == 0 then print('+') end end end `; diff --git a/test/test-suite/db.test.js b/test/test-suite/db.test.js index 38330db..89ec66d 100644 --- a/test/test-suite/db.test.js +++ b/test/test-suite/db.test.js @@ -598,8 +598,7 @@ test("[test-suite] db: tests for tail calls", () => { local tail = debug.getinfo(2) assert(tail.func == g1 and tail.istailcall == true) assert(debug.getinfo(3, "S").what == "main") - print"+" - end + end end function g(x) return f(x) end diff --git a/test/test-suite/math.test.js b/test/test-suite/math.test.js index c649225..9cf4e21 100644 --- a/test/test-suite/math.test.js +++ b/test/test-suite/math.test.js @@ -80,8 +80,8 @@ test("[test-suite] math: number of bits in the mantissa of a floating-point numb local x = 2.0^floatbits assert(x > x - 1.0 and x == x + 1.0) - print(string.format("%d-bit integers, %d-bit (mantissa) floats", - intbits, floatbits)) + -- print(string.format("%d-bit integers, %d-bit (mantissa) floats", + -- intbits, floatbits)) end assert(math.type(0) == "integer" and math.type(0.0) == "float" @@ -304,66 +304,69 @@ test("[test-suite] math: order between floats and integers", () => { assert(minint <= -2^(intbits - 1)) assert(-2^(intbits - 1) <= minint) end + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); - if floatbits < intbits then - print("testing order (floats cannot represent all integers)") - local fmax = 2^floatbits - local ifmax = fmax | 0 - assert(fmax < ifmax + 1) - assert(fmax - 1 < ifmax) - assert(-(fmax - 1) > -ifmax) - assert(not (fmax <= ifmax - 1)) - assert(-fmax > -(ifmax + 1)) - assert(not (-fmax >= -(ifmax - 1))) - - assert(fmax/2 - 0.5 < ifmax//2) - assert(-(fmax/2 - 0.5) > -ifmax//2) - - assert(maxint < 2^intbits) - assert(minint > -2^intbits) - assert(maxint <= 2^intbits) - assert(minint >= -2^intbits) - else - print("testing order (floats can represent all integers)") - assert(maxint < maxint + 1.0) - assert(maxint < maxint + 0.5) - assert(maxint - 1.0 < maxint) - assert(maxint - 0.5 < maxint) - assert(not (maxint + 0.0 < maxint)) - assert(maxint + 0.0 <= maxint) - assert(not (maxint < maxint + 0.0)) - assert(maxint + 0.0 <= maxint) - assert(maxint <= maxint + 0.0) - assert(not (maxint + 1.0 <= maxint)) - assert(not (maxint + 0.5 <= maxint)) - assert(not (maxint <= maxint - 1.0)) - assert(not (maxint <= maxint - 0.5)) - - assert(minint < minint + 1.0) - assert(minint < minint + 0.5) - assert(minint <= minint + 0.5) - assert(minint - 1.0 < minint) - assert(minint - 1.0 <= minint) - assert(not (minint + 0.0 < minint)) - assert(not (minint + 0.5 < minint)) - assert(not (minint < minint + 0.0)) - assert(minint + 0.0 <= minint) - assert(minint <= minint + 0.0) - assert(not (minint + 1.0 <= minint)) - assert(not (minint + 0.5 <= minint)) - assert(not (minint <= minint - 1.0)) - end - do - local NaN = 0/0 - assert(not (NaN < 0)) - assert(not (NaN > minint)) - assert(not (NaN <= -9)) - assert(not (NaN <= maxint)) - assert(not (NaN < maxint)) - assert(not (minint <= NaN)) - assert(not (minint < NaN)) - end +test("[test-suite] math: testing order (floats can represent all integers)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + assert(floatbits >= intbits) + + assert(maxint < maxint + 1.0) + assert(maxint < maxint + 0.5) + assert(maxint - 1.0 < maxint) + assert(maxint - 0.5 < maxint) + assert(not (maxint + 0.0 < maxint)) + assert(maxint + 0.0 <= maxint) + assert(not (maxint < maxint + 0.0)) + assert(maxint + 0.0 <= maxint) + assert(maxint <= maxint + 0.0) + assert(not (maxint + 1.0 <= maxint)) + assert(not (maxint + 0.5 <= maxint)) + assert(not (maxint <= maxint - 1.0)) + assert(not (maxint <= maxint - 0.5)) + + assert(minint < minint + 1.0) + assert(minint < minint + 0.5) + assert(minint <= minint + 0.5) + assert(minint - 1.0 < minint) + assert(minint - 1.0 <= minint) + assert(not (minint + 0.0 < minint)) + assert(not (minint + 0.5 < minint)) + assert(not (minint < minint + 0.0)) + assert(minint + 0.0 <= minint) + assert(minint <= minint + 0.0) + assert(not (minint + 1.0 <= minint)) + assert(not (minint + 0.5 <= minint)) + assert(not (minint <= minint - 1.0)) + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); + + +test("[test-suite] math: NaN order", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + let luaCode = ` + local NaN = 0/0 + assert(not (NaN < 0)) + assert(not (NaN > minint)) + assert(not (NaN <= -9)) + assert(not (NaN <= maxint)) + assert(not (NaN < maxint)) + assert(not (minint <= NaN)) + assert(not (minint < NaN)) `; lualib.luaL_openlibs(L); if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) @@ -988,7 +991,6 @@ test("[test-suite] math: testing -0 and NaN", () => { let luaCode = ` do - print("testing -0 and NaN") local mz, z = -0.0, 0.0 assert(mz == z) assert(1/mz < 0 and 0 < 1/z) diff --git a/test/test-suite/sort.test.js b/test/test-suite/sort.test.js index 154db03..cc33c0c 100644 --- a/test/test-suite/sort.test.js +++ b/test/test-suite/sort.test.js @@ -22,7 +22,7 @@ const prefix = ` table.sort(a, func) x = (os.clock() - x) * 1000 pre = pre or "" - print(string.format("%ssorting %d %s elements in %.2f msec.", pre, n, msg, x)) + -- print(string.format("%ssorting %d %s elements in %.2f msec.", pre, n, msg, x)) check(a, func) end @@ -397,8 +397,8 @@ test("[test-suite] sort: Invert-sorting", () => { x = os.clock(); i=0 table.sort(a, function(x,y) i=i+1; return y { end if not pcall(string.format, "%.3a", 0) then - (Message or print)("\\n >>> modifiers for format '%a' not available <<<\\n") + -- (Message or print)("\\n >>> modifiers for format '%a' not available <<<\\n") else assert(string.find(string.format("%+.2A", 12), "^%+0X%x%.%x0P%+?%d$")) assert(string.find(string.format("%.4A", -12), "^%-0X%x%.%x000P%+?%d$")) diff --git a/test/test-suite/tpack.test.js b/test/test-suite/tpack.test.js index 132956e..3b97d3a 100644 --- a/test/test-suite/tpack.test.js +++ b/test/test-suite/tpack.test.js @@ -38,14 +38,14 @@ test("[test-suite] tpack: maximum size for integers", () => { assert(1 <= sizeshort and sizeshort <= sizeint and sizeint <= sizelong and sizefloat <= sizedouble) - print("platform:") - print(string.format( - "\\tshort %d, int %d, long %d, size_t %d, float %d, double %d,\\n\\z - \\tlua Integer %d, lua Number %d", - sizeshort, sizeint, sizelong, sizesize_t, sizefloat, sizedouble, - sizeLI, sizenumber)) - print("\\t" .. (little and "little" or "big") .. " endian") - print("\\talignment: " .. align) + -- print("platform:") + -- print(string.format( + -- "\\tshort %d, int %d, long %d, size_t %d, float %d, double %d,\\n\\z + -- \\tlua Integer %d, lua Number %d", + -- sizeshort, sizeint, sizelong, sizesize_t, sizefloat, sizedouble, + -- sizeLI, sizenumber)) + -- print("\\t" .. (little and "little" or "big") .. " endian") + -- print("\\talignment: " .. align) `; lualib.luaL_openlibs(L); if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) diff --git a/test/test-suite/vararg.test.js b/test/test-suite/vararg.test.js index 78439f1..0538541 100644 --- a/test/test-suite/vararg.test.js +++ b/test/test-suite/vararg.test.js @@ -45,7 +45,7 @@ test("[test-suite] vararg: testing vararg", () => { assert(a[1] == b and a[2] == c and a.n == 2) a = vararg(call(call, {c12, {1,2}})) assert(a.n == 2 and a[1] == 55 and a[2] == 2) - a = call(print, {'+'}) + a = call(function()end, {'+'}) assert(a == nil) local t = {1, 10} -- cgit v1.2.3-54-g00ecf