diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-22 13:35:01 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-22 13:35:01 +0100 |
commit | 290ec54e13d1dff301465cbfa2fd7b4e1e52962f (patch) | |
tree | ac1d4988da8cd15b567891294bf1ac94af90242d /tests/lbaselib.js | |
parent | a40719dc74b8dbb0d6c8fc0272c0d79ad8a7a9ea (diff) | |
download | fengari-290ec54e13d1dff301465cbfa2fd7b4e1e52962f.tar.gz fengari-290ec54e13d1dff301465cbfa2fd7b4e1e52962f.tar.bz2 fengari-290ec54e13d1dff301465cbfa2fd7b4e1e52962f.zip |
lua_stringtonumber, tonumber
Diffstat (limited to 'tests/lbaselib.js')
-rw-r--r-- | tests/lbaselib.js | 47 |
1 files changed, 47 insertions, 0 deletions
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 |