aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-15 08:42:55 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-15 08:42:55 +0100
commit1a158cc176055a50df492dfa39c1b93e9e5b478a (patch)
tree1a6625ab9ed29379158072f0352e61450e3890a4 /tests
parentdbbbb1a029fa3d6ad346426bee3310191e0dd285 (diff)
downloadfengari-1a158cc176055a50df492dfa39c1b93e9e5b478a.tar.gz
fengari-1a158cc176055a50df492dfa39c1b93e9e5b478a.tar.bz2
fengari-1a158cc176055a50df492dfa39c1b93e9e5b478a.zip
utf8.len, utf8.codes
Diffstat (limited to 'tests')
-rw-r--r--tests/lutf8lib.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/lutf8lib.js b/tests/lutf8lib.js
index 7033a57..38d8f8a 100644
--- a/tests/lutf8lib.js
+++ b/tests/lutf8lib.js
@@ -112,4 +112,73 @@ test('utf8.char', function (t) {
"Correct element(s) on the stack"
);
+});
+
+
+test('utf8.len', function (t) {
+ let luaCode = `
+ return utf8.len("( ͡° ͜ʖ ͡° )")
+ `, 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_tointeger(L, -1),
+ 12,
+ "Correct element(s) on the stack"
+ );
+
+});
+
+
+test('utf8.codes', function (t) {
+ let luaCode = `
+ local s = "( ͡° ͜ʖ ͡° )"
+ local results = ""
+ for p, c in utf8.codes(s) do
+ results = results .. "[" .. p .. "," .. c .. "] "
+ end
+ return results
+ `, 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),
+ "[1,40] [2,32] [3,865] [5,176] [7,32] [8,860] [10,662] [12,32] [13,865] [15,176] [17,32] [18,41] ",
+ "Correct element(s) on the stack"
+ );
+
}); \ No newline at end of file