-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
45 lines (34 loc) · 904 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
macros = require("../index.js");
burrito = require("burrito");
macros.register(".ds",{
prepend: "console.log('being processed: '+ (new Date));\n",
regex: [
[/development.local/, "example.com"]
],
token: function(tok){
if(tok.type == "name" && tok.value == "f"){
tok.type = "keyword";
tok.value = "function";
}
return tok;
},
ast: function(ast){
var str = burrito(ast, function(node){
if(node.name === 'call'){
node.wrap('wrapper(%s)');
}
});
return burrito.parse(str);
},
append: "function wrapper(fnCall){ return fnCall;}"
});
sample = require("./sample");
result = sample();
expect = "f(){}";
reg = result[0].toString().substr(1, expect.length);
str = result[1];
assert = require("assert");
assert.equal(expect, str);
assert.equal(expect, reg);
assert.equal("example.com", sample.location);
console.log("ok");