diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/load.js | 4 | ||||
-rw-r--r-- | tests/lua.js | 33 | ||||
-rw-r--r-- | tests/single.lua | 73 |
3 files changed, 107 insertions, 3 deletions
diff --git a/tests/load.js b/tests/load.js index 143549a..9b76ad3 100644 --- a/tests/load.js +++ b/tests/load.js @@ -1,10 +1,8 @@ "use strict"; const test = require('tape'); -const beautify = require('js-beautify').js_beautify; const tests = require("./tests.js"); -const getState = tests.getState; const toByteCode = tests.toByteCode; const VM = require("../src/lvm.js"); @@ -212,4 +210,4 @@ test('dofile', function (t) { "Correct element(s) on the stack" ); -});
\ No newline at end of file +}); diff --git a/tests/lua.js b/tests/lua.js new file mode 100644 index 0000000..b2e0a6b --- /dev/null +++ b/tests/lua.js @@ -0,0 +1,33 @@ +"use strict"; + +const test = require('tape'); + +const lapi = require("../src/lapi.js"); +const lauxlib = require("../src/lauxlib.js"); +const lua = require('../src/lua.js'); +const linit = require('../src/linit.js'); + +test('string.lua', function (t) { + let luaCode = ` + return dofile("tests/single.lua") + `, L; + + t.plan(1); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, luaCode); + + }, "Lua program loaded without error"); + + // t.doesNotThrow(function () { + + lapi.lua_call(L, 0, -1); + + // }, "Lua program ran without error"); + +}); diff --git a/tests/single.lua b/tests/single.lua new file mode 100644 index 0000000..616e2a4 --- /dev/null +++ b/tests/single.lua @@ -0,0 +1,73 @@ +-- $Id: strings.lua,v 1.86 2016/11/07 13:11:28 roberto Exp roberto $ +-- See Copyright Notice in file all.lua + +print('testing strings and string library') + +local maxi, mini = math.maxinteger, math.mininteger + + +local function checkerror (msg, f, ...) + local s, err = pcall(f, ...) + assert(not s and string.find(err, msg)) +end + + +-- testing string comparisons +assert('alo' < 'alo1') +assert('' < 'a') +assert('alo\0alo' < 'alo\0b') +assert('alo\0alo\0\0' > 'alo\0alo\0') +assert('alo' < 'alo\0') +assert('alo\0' > 'alo') +assert('\0' < '\1') +assert('\0\0' < '\0\1') +assert('\1\0a\0a' <= '\1\0a\0a') +assert(not ('\1\0a\0b' <= '\1\0a\0a')) +assert('\0\0\0' < '\0\0\0\0') +assert(not('\0\0\0\0' < '\0\0\0')) +assert('\0\0\0' <= '\0\0\0\0') +assert(not('\0\0\0\0' <= '\0\0\0')) +assert('\0\0\0' <= '\0\0\0') +assert('\0\0\0' >= '\0\0\0') +assert(not ('\0\0b' < '\0\0a\0')) + +-- testing string.sub +assert(string.sub("123456789",2,4) == "234") +assert(string.sub("123456789",7) == "789") +assert(string.sub("123456789",7,6) == "") +assert(string.sub("123456789",7,7) == "7") +assert(string.sub("123456789",0,0) == "") +assert(string.sub("123456789",-10,10) == "123456789") +assert(string.sub("123456789",1,9) == "123456789") +assert(string.sub("123456789",-10,-20) == "") +assert(string.sub("123456789",-1) == "9") +assert(string.sub("123456789",-4) == "6789") +assert(string.sub("123456789",-6, -4) == "456") +assert(string.sub("123456789", mini, -4) == "123456") +assert(string.sub("123456789", mini, maxi) == "123456789") +assert(string.sub("123456789", mini, mini) == "") +assert(string.sub("\000123456789",3,5) == "234") +assert(("\000123456789"):sub(8) == "789") + +-- testing string.find +assert(string.find("123456789", "345") == 3) +a,b = string.find("123456789", "345") +assert(string.sub("123456789", a, b) == "345") +assert(string.find("1234567890123456789", "345", 3) == 3) +assert(string.find("1234567890123456789", "345", 4) == 13) +assert(string.find("1234567890123456789", "346", 4) == nil) +assert(string.find("1234567890123456789", ".45", -9) == 13) +assert(string.find("abcdefg", "\0", 5, 1) == nil) +assert(string.find("", "") == 1) +assert(string.find("", "", 1) == 1) +assert(not string.find("", "", 2)) +assert(string.find('', 'aaa', 1) == nil) +assert(('alo(.)alo'):find('(.)', 1, 1) == 4) + +assert(string.len("") == 0) +assert(string.len("\0\0\0") == 3) +assert(string.len("1234567890") == 10) + +assert(#"" == 0) +assert(#"\0\0\0" == 3) +assert(#"1234567890" == 10) |