aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-27 15:35:50 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-27 15:35:50 +0100
commitc1cf887d702a36729bab0257247066745223cf6e (patch)
tree31958bdfafc4603a95581b751ac996311c06ef2f /tests
parent6beeccbd0a859f3a9d1be4142d16a3d11ac30743 (diff)
downloadfengari-c1cf887d702a36729bab0257247066745223cf6e.tar.gz
fengari-c1cf887d702a36729bab0257247066745223cf6e.tar.bz2
fengari-c1cf887d702a36729bab0257247066745223cf6e.zip
TK_LOCAL, TK_NAME, TK_INT
Diffstat (limited to 'tests')
-rw-r--r--tests/llex.js52
1 files changed, 50 insertions, 2 deletions
diff --git a/tests/llex.js b/tests/llex.js
index 3c05366..725d3f8 100644
--- a/tests/llex.js
+++ b/tests/llex.js
@@ -13,7 +13,7 @@ const lua = require('../src/lua.js');
const R = llex.RESERVED;
-test('basic lexing', function (t) {
+test('basic lexing: TK_RETURN, TK_STRING', function (t) {
let luaCode = `
return "hello lex !"
`, L;
@@ -32,7 +32,7 @@ test('basic lexing', function (t) {
llex.luaX_next(ls);
while (ls.t.token !== R.TK_EOS) {
- console.log(llex.luaX_tokens[ls.t.token - llex.FIRST_RESERVED]);
+ // console.log(llex.luaX_tokens[ls.t.token - llex.FIRST_RESERVED]);
readTokens.push(ls.t.token);
llex.luaX_next(ls);
@@ -47,4 +47,52 @@ test('basic lexing', function (t) {
"Correct tokens found"
)
+});
+
+
+test('TK_LOCAL, TK_NAME, TK_INT', function (t) {
+ let luaCode = `
+ local f = testing(aBunch)
+ return "of"
+ end
+
+ return f("things") + 12
+ `, 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(ls.t.token >= llex.FIRST_RESERVED ?
+ // llex.luaX_tokens[ls.t.token - llex.FIRST_RESERVED]
+ // : ls.t.token);
+
+ readTokens.push(ls.t.token);
+ llex.luaX_next(ls);
+ }
+
+
+ }, "JS Lua program ran without error");
+
+ t.deepEqual(
+ readTokens,
+ [
+ R.TK_LOCAL, R.TK_NAME, '=', R.TK_NAME, '(', R.TK_NAME, ')',
+ R.TK_RETURN, R.TK_STRING,
+ R.TK_END,
+ R.TK_RETURN, R.TK_NAME, '(', R.TK_STRING, ')', '+', R.TK_INT
+ ],
+ "Correct tokens found"
+ )
+
}); \ No newline at end of file