diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-27 15:08:09 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-27 15:08:09 +0100 |
commit | 6beeccbd0a859f3a9d1be4142d16a3d11ac30743 (patch) | |
tree | 0d6c8ded314a0b3e3c989952e4dbdff6a27048b3 /tests | |
parent | 5a47025d64f013975051473c1115ff70c0281785 (diff) | |
download | fengari-6beeccbd0a859f3a9d1be4142d16a3d11ac30743.tar.gz fengari-6beeccbd0a859f3a9d1be4142d16a3d11ac30743.tar.bz2 fengari-6beeccbd0a859f3a9d1be4142d16a3d11ac30743.zip |
Basic lexing tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/llex.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/llex.js b/tests/llex.js new file mode 100644 index 0000000..3c05366 --- /dev/null +++ b/tests/llex.js @@ -0,0 +1,50 @@ +/*jshint esversion: 6 */ +"use strict"; + +const test = require('tape'); +const beautify = require('js-beautify').js_beautify; + +const tests = require("./tests.js"); + +const lapi = require("../src/lapi.js"); +const lauxlib = require("../src/lauxlib.js"); +const llex = require("../src/llex.js"); +const lua = require('../src/lua.js'); +const R = llex.RESERVED; + + +test('basic lexing', function (t) { + let luaCode = ` + return "hello lex !" + `, L; + + t.plan(2); + + let readTokens = []; + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + let ls = new llex.LexState(); + llex.luaX_setinput(L, ls, new llex.MBuffer(luaCode), luaCode, luaCode.charAt(0)); + + llex.luaX_next(ls); + + while (ls.t.token !== R.TK_EOS) { + console.log(llex.luaX_tokens[ls.t.token - llex.FIRST_RESERVED]); + + readTokens.push(ls.t.token); + llex.luaX_next(ls); + } + + + }, "JS Lua program ran without error"); + + t.deepEqual( + readTokens, + [R.TK_RETURN, R.TK_STRING], + "Correct tokens found" + ) + +});
\ No newline at end of file |