aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 11:58:46 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 12:03:47 +0100
commit6d3d22b3938a811bdde9a311753837003df42d08 (patch)
tree11a8c9943d4ba6295200fe906c54333732aa37b2 /tests
parente0d4ffcc75a04b3ecc2cc08aea372d9621e5b6ac (diff)
downloadfengari-6d3d22b3938a811bdde9a311753837003df42d08.tar.gz
fengari-6d3d22b3938a811bdde9a311753837003df42d08.tar.bz2
fengari-6d3d22b3938a811bdde9a311753837003df42d08.zip
rawset, rawget
Diffstat (limited to 'tests')
-rw-r--r--tests/lbaselib.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index ab68a5f..b3af927 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -126,4 +126,64 @@ test('rawequal', function (t) {
lapi.lua_toboolean(L, -1),
"Correct element(s) on the stack"
);
+});
+
+
+test('rawset, rawget', function (t) {
+ let luaCode = `
+ local mt = {
+ __newindex = function (table, key, value)
+ rawset(table, key, "hello")
+ end
+ }
+
+ local t = {}
+
+ setmetatable(t, mt);
+
+ t["yo"] = "bye"
+ rawset(t, "yoyo", "bye")
+
+ return rawget(t, "yo"), t["yo"], rawget(t, "yoyo"), t["yoyo"]
+ `, 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-rawequal");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -4),
+ "hello",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -3),
+ "hello",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -2),
+ "bye",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "bye",
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file