Permalink
Browse files

added the first test

  • Loading branch information...
1 parent fe4b39d commit bf31a74a59e3078edfcc719a93b25caa0e2fe0a9 @dresende committed Aug 25, 2011
Showing with 31 additions and 0 deletions.
  1. +17 −0 tests/code/function-replace.js
  2. +14 −0 tests/function-replace.js
View
17 tests/code/function-replace.js
@@ -0,0 +1,17 @@
+var o = { a: oa, b: ob, o: { a: ooa, b: oob } }
+
+console.log(a());
+console.log(b());
+console.log(o.a());
+console.log(o.b());
+console.log(o.o.a());
+console.log(o.o.b());
+
+function a() { return "a" }
+function b() { return "b" }
+
+function oa() { return "o.a" }
+function ob() { return "o.b" }
+
+function ooa() { return "o.o.a" }
+function oob() { return "o.o.b" }
View
14 tests/function-replace.js
@@ -0,0 +1,14 @@
+var fs = require("fs"),
+ vm = require("vm"),
+ transformer = require("./../lib/ast-transformer");
+
+fs.readFile("./code/function-replace.js", function (err, data) {
+ if (err) return console.log(err);
+
+ var tf = new transformer.Transformer(transformer.parse(data));
+
+ tf.replaceFunctionCall("a", function () { return "a transformed"; })
+ .replaceFunctionCall("o.o.b", "o.o.b transformed");
+
+ vm.runInNewContext(tf.generate(), { console: console });
+});

0 comments on commit bf31a74

Please sign in to comment.