From e0d4ffcc75a04b3ecc2cc08aea372d9621e5b6ac Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 20 Feb 2017 11:26:28 +0100 Subject: rawequal --- tests/lbaselib.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/lbaselib.js') diff --git a/tests/lbaselib.js b/tests/lbaselib.js index 3ddec2d..ab68a5f 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -82,4 +82,48 @@ test('setmetatable, getmetatable', function (t) { lapi.lua_istable(L, -1), "Correct element(s) on the stack" ); +}); + + +test('rawequal', function (t) { + let luaCode = ` + local mt = { + __eq = function () + return true + end + } + + local t1 = {} + local t2 = {} + + setmetatable(t1, mt); + + return rawequal(t1, t2), t1 == t2 + `, L; + + t.plan(3); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, bc, "test-rawequal"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.notOk( + lapi.lua_toboolean(L, -2), + "Correct element(s) on the stack" + ); + + t.ok( + lapi.lua_toboolean(L, -1), + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf