aboutsummaryrefslogtreecommitdiff
path: root/tests/lstrlib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-20 16:15:36 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-20 16:15:36 +0100
commit5f5ba74ace8a956ae48a9f0b182a157052c2546e (patch)
tree93381379f3711fd5ad67015d686dbfd518c0eef5 /tests/lstrlib.js
parent645437b8e0846635f886520bb679a79ec1849c09 (diff)
downloadfengari-5f5ba74ace8a956ae48a9f0b182a157052c2546e.tar.gz
fengari-5f5ba74ace8a956ae48a9f0b182a157052c2546e.tar.bz2
fengari-5f5ba74ace8a956ae48a9f0b182a157052c2546e.zip
string.gsub
Diffstat (limited to 'tests/lstrlib.js')
-rw-r--r--tests/lstrlib.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index aac3851..ce77bdc 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -621,4 +621,60 @@ test('string.find', function (t) {
"123",
"Correct element(s) on the stack"
);
+});
+
+
+test('string.gmatch', function (t) {
+ let luaCode = `
+ local s = "hello world from Lua"
+ local t = {}
+
+ for w in string.gmatch(s, "%a+") do
+ table.insert(t, w)
+ end
+
+ return table.unpack(t)
+ `, L;
+
+ t.plan(6);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lauxlib.luaL_loadstring(L, luaCode);
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "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),
+ "world",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -2),
+ "from",
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tostring(L, -1),
+ "Lua",
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file