From 290ec54e13d1dff301465cbfa2fd7b4e1e52962f Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 13:35:01 +0100 Subject: lua_stringtonumber, tonumber --- tests/lbaselib.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests') diff --git a/tests/lbaselib.js b/tests/lbaselib.js index 73d13a3..6dc6bfb 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -442,4 +442,51 @@ test('select', function (t) { [2, 3], "Correct element(s) on the stack" ); +}); + + +test('tonumber', function (t) { + let luaCode = ` + return tonumber('123'), tonumber('12.3'), tonumber('az', 36), tonumber('10', 2) + `, L; + + t.plan(5); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, bc, "test-tonumber"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tonumber(L, -4), + 123, + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tonumber(L, -3), + 12.3, + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tonumber(L, -2), + 395, + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tonumber(L, -1), + 2, + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-70-g09d2