diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-03-29 14:39:57 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-03-30 09:57:53 +0200 |
commit | 456ab7b69f88859683c60cc2261e70d6dbadd8e8 (patch) | |
tree | 12baf4ae489e7afd4819ec94bc413c1c2a1db05d /tests/lstrlib.js | |
parent | 2e5b595a2e04fe72555a565af4aae43560946473 (diff) | |
download | fengari-456ab7b69f88859683c60cc2261e70d6dbadd8e8.tar.gz fengari-456ab7b69f88859683c60cc2261e70d6dbadd8e8.tar.bz2 fengari-456ab7b69f88859683c60cc2261e70d6dbadd8e8.zip |
8-bit string internally tests
Lexing/Parsing is done on byte rather than js strings
Diffstat (limited to 'tests/lstrlib.js')
-rw-r--r-- | tests/lstrlib.js | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/tests/lstrlib.js b/tests/lstrlib.js index 12df173..2bde19d 100644 --- a/tests/lstrlib.js +++ b/tests/lstrlib.js @@ -6,6 +6,7 @@ const beautify = require('js-beautify').js_beautify; const tests = require("./tests.js"); const toByteCode = tests.toByteCode; +const lua = require("../src/lua.js"); const lapi = require("../src/lapi.js"); const lauxlib = require("../src/lauxlib.js"); const linit = require('../src/linit.js'); @@ -74,7 +75,7 @@ test('string.char', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "hello", "Correct element(s) on the stack" ); @@ -105,13 +106,13 @@ test('string.upper, string.lower', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "HELLO", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "hello", "Correct element(s) on the stack" ); @@ -142,7 +143,7 @@ test('string.rep', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "hello, hello, hello", "Correct element(s) on the stack" ); @@ -173,7 +174,7 @@ test('string.reverse', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "hello", "Correct element(s) on the stack" ); @@ -247,7 +248,7 @@ test('string.format', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "%10 0000000023", "Correct element(s) on the stack" ); @@ -278,7 +279,7 @@ test('string.format', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "FFFFFFF", "Correct element(s) on the stack" ); @@ -309,7 +310,7 @@ test('string.format', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), '"a string with \\"quotes\\" and \\\n new line"', "Correct element(s) on the stack" ); @@ -350,67 +351,67 @@ test('string.sub', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -11), + lapi.lua_tojsstring(L, -11), "234", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -10), + lapi.lua_tojsstring(L, -10), "789", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -9), + lapi.lua_tojsstring(L, -9), "", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -8), + lapi.lua_tojsstring(L, -8), "7", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -7), + lapi.lua_tojsstring(L, -7), "", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -6), + lapi.lua_tojsstring(L, -6), "123456789", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -5), + lapi.lua_tojsstring(L, -5), "123456789", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -4), + lapi.lua_tojsstring(L, -4), "", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -3), + lapi.lua_tojsstring(L, -3), "9", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "6789", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "456", "Correct element(s) on the stack" ); @@ -448,14 +449,14 @@ test('string.dump', function (t) { let dv = lapi.lua_todataview(L, -1); - lapi.lua_load(L, null, dv, "test", "binary"); + lapi.lua_load(L, null, dv, lua.to_luastring("test"), lua.to_luastring("binary")); lapi.lua_call(L, 0, -1); }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "hello1212.5", "Correct element(s) on the stack" ); @@ -562,13 +563,13 @@ test('string.match', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "foo", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "123", "Correct element(s) on the stack" ); @@ -611,13 +612,13 @@ test('string.find', function (t) { ); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "foo", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "123", "Correct element(s) on the stack" ); @@ -655,25 +656,25 @@ test('string.gmatch', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -4), + lapi.lua_tojsstring(L, -4), "hello", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -3), + lapi.lua_tojsstring(L, -3), "world", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "from", "Correct element(s) on the stack" ); t.strictEqual( - lapi.lua_tostring(L, -1), + lapi.lua_tojsstring(L, -1), "Lua", "Correct element(s) on the stack" ); @@ -704,7 +705,7 @@ test('string.gsub', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "hello hello world world", "Correct element(s) on the stack" ); @@ -741,7 +742,7 @@ test('string.gsub (number)', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "hello hello world", "Correct element(s) on the stack" ); @@ -778,7 +779,7 @@ test('string.gsub (pattern)', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "world hello Lua from", "Correct element(s) on the stack" ); @@ -817,7 +818,7 @@ test('string.gsub (function)', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "4+5 = 9", "Correct element(s) on the stack" ); @@ -856,7 +857,7 @@ test('string.gsub (table)', function (t) { }, "Lua program ran without error"); t.strictEqual( - lapi.lua_tostring(L, -2), + lapi.lua_tojsstring(L, -2), "lua-5.3.tar.gz", "Correct element(s) on the stack" ); @@ -866,4 +867,4 @@ test('string.gsub (table)', function (t) { 2, "Correct element(s) on the stack" ); -});
\ No newline at end of file +}); |