-
Notifications
You must be signed in to change notification settings - Fork 3
/
narcissus-test.js
executable file
·95 lines (74 loc) · 2.59 KB
/
narcissus-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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env narwhal
var narcissus = require('narcissus');
var file = require('file'),
os = require('os'),
json = require('json');
// Hack for v8
var BASE_DIR = '/home/andy/git/narwhal2/packages/narcissus';
function testFileContents(path) {
var absPath = file.join(BASE_DIR, path);
return file.open(absPath).read();
}
print("\n\n");
print("NARCISSUS");
for (var name in narcissus) {
print(name);
}
print("\n\n");
var forLoop = "for (var i = 0; i < 10; i++) { print(i); }";
exports.testLoopParse = function() {
// Can parse JSON Template, but can't execute it yet.
//var code = file.open('testdata/json-template.js').read();
print(forLoop);
var parseTree = narcissus.parse(forLoop);
print("Done parsing");
if (narcissus.execute) {
var execResult = narcissus.execute(
parseTree, new narcissus.ExecutionContext(narcissus.GLOBAL_CODE));
//print("execResult " + execResult);
parseTree = narcissus.parse("function t() {return true;}");
//print(parseTree);
execResult = narcissus.execute(
parseTree, new narcissus.ExecutionContext(narcissus.FUNCTION_CODE));
//print("execResult FUNCTION_CODE " + execResult);
parseTree = narcissus.parse(
"function t() {print('in function t ***'); return true;}");
execResult = narcissus.execute(
parseTree, new narcissus.ExecutionContext(narcissus.EVAL_CODE));
print("execResult EVAL_CODE " + execResult);
}
}
exports.testSimpleCode = function() {
var code = testFileContents('testdata/simple.js');
print(code);
var parseTree = narcissus.parse(code);
print("Done parsing");
var execResult = narcissus.evaluate(code);
}
exports.testFormat = function() {
var code = testFileContents('testdata/simple.js');
print(code);
var parseTree = narcissus.parse(code);
print(narcissus.format(parseTree));
}
exports.testFunction = function() {
// TODO: Make this work
var code = testFileContents('testdata/function.js');
var result = narcissus.evaluate(code);
return;
print("testFunction " + result);
}
exports.testParseRealCode = function() {
var code = testFileContents('testdata/json-template.js');
return; // disabled for Rhino
var parseTree = narcissus.parse(code);
print(json.stringify(parseTree, null, 2));
print(narcissus.format(parseTree));
}
exports.testBreak = function() {
var code = testFileContents('testdata/break.js');
var parseTree = narcissus.parse(code);
//print(json.stringify(parseTree, null, 2));
}
if (require.main === module.id)
require("test/runner").run(exports);