-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
45 lines (37 loc) · 977 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
const assert = require("assert");
const fs = require("fs");
const { compile, lex, parse } = require("./ooclib");
// TODO: test compiler
assert.strictEqual(
compile(fs.readFileSync("sample/empty.oo", "utf8")),
"(function () {\n})();"
);
assert.strictEqual(
compile(fs.readFileSync("sample/hello.oo", "utf8")),
"(function () {\n\tfunction main() {\n\t\tconsole.log(\"Hello, World!\");\n\t}\n\n\tconst mainReturn = main();\n\n\tif (mainReturn) {\n\t\tprocess.exit(mainReturn);\n\t}\n})();"
);
assert.strictEqual(
compile(fs.readFileSync("sample/variable.oo", "utf8")),
`(function () {
function main() {
a = 1;
b = a;
console.log(b);
}
const mainReturn = main();
if (mainReturn) {
process.exit(mainReturn);
}
})();`
);
// TODO: test lexer
assert.strictEqual(
JSON.stringify(lex(fs.readFileSync("sample/empty.oo", "utf8"))),
JSON.stringify([])
);
// TODO: test parser
assert.strictEqual(
JSON.stringify(parse([])),
JSON.stringify({})
);