-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
47 lines (38 loc) · 904 Bytes
/
index.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
46
47
const { doFile, doString, loadProgram } = require('.');
test('doString', () => {
const program = `
print("Hello, World!")
`;
return expect(doString(program)).resolves.toBe(undefined);
});
test('doFile', () => {
const path = require('path');
const file = path.join(__dirname, 'examples', 'test1.lua').toString();
return expect(doFile(file)).resolves.toBe(undefined);
});
test('Passing table', (done) => {
const state = loadProgram(`
obj.ox = 50
`);
state.setTable('obj', {ox: 0});
state.run().then((G) => {
expect(G.obj).toEqual({ox: 50});
done();
});
});
test('Passing function', (done) => {
const state = loadProgram(`
obj.mes("Hello, World!")
`);
let message = '';
const table = {
mes: (text) => {
message += text;
},
};
state.setTable('obj', table);
state.run().then(() => {
expect(message).toBe('Hello, World!');
done();
});
});