summaryrefslogtreecommitdiff
path: root/tests/lstrlib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-16 09:45:50 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-16 15:10:30 +0100
commit4161f6756dadef6cd5a5c2e1e75804122e892949 (patch)
treef229a3b3fee394fe9cc2c8a977196d62c09132e7 /tests/lstrlib.js
parent8388f1d2eb85bfc5fdbe1cfeb62e85a7d88403b5 (diff)
downloadfengari-4161f6756dadef6cd5a5c2e1e75804122e892949.tar.gz
fengari-4161f6756dadef6cd5a5c2e1e75804122e892949.tar.bz2
fengari-4161f6756dadef6cd5a5c2e1e75804122e892949.zip
string.format
Diffstat (limited to 'tests/lstrlib.js')
-rw-r--r--tests/lstrlib.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index b15eecf..0475a42 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -220,4 +220,96 @@ test('string.byte', function (t) {
108,
"Correct element(s) on the stack"
);
+});
+
+
+test('string.format', function (t) {
+ let luaCode = `
+ return string.format("%%%d %010d", 10, 23)
+ `, L;
+
+ t.plan(3);
+
+ 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, -1),
+ "%10 0000000023",
+ "Correct element(s) on the stack"
+ );
+});
+
+
+test('string.format', function (t) {
+ let luaCode = `
+ return string.format("%07X", 0xFFFFFFF)
+ `, L;
+
+ t.plan(3);
+
+ 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, -1),
+ "FFFFFFF",
+ "Correct element(s) on the stack"
+ );
+});
+
+test('string.format', function (t) {
+ let luaCode = `
+ return string.format("%q", 'a string with "quotes" and \\n new line')
+ `, L;
+
+ t.plan(3);
+
+ 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, -1),
+ '"a string with \\"quotes\\" and \\\n new line"',
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file