From 1a158cc176055a50df492dfa39c1b93e9e5b478a Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 15 Mar 2017 08:42:55 +0100 Subject: utf8.len, utf8.codes --- tests/lutf8lib.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3-70-g09d2