Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first test passes!

  • Loading branch information...
commit a91eb2237f6da81c06f73bea6189b8f46065c01c 1 parent bc66c37
@substack authored
Showing with 62 additions and 5 deletions.
  1. +22 −5 index.js
  2. +34 −0 test/cover.js
  3. +6 −0 test/src/cover.js
View
27 index.js
@@ -14,6 +14,7 @@ function Bunker () {
this.names = {
call : burrito.generateName(6),
+ expr : burrito.generateName(6),
stat : burrito.generateName(6)
};
}
@@ -32,16 +33,24 @@ Bunker.prototype.compile = function () {
var names = this.names;
return burrito(src, function (node) {
+ var i = nodes.length;
+
if (node.name === 'call') {
- var i = nodes.length;
nodes.push(node);
node.wrap(names.call + '(' + i + ')(%s)');
}
else if (node.name === 'stat' || node.name === 'throw') {
- var i = nodes.length;
nodes.push(node);
node.wrap('{' + names.stat + '(' + i + ');%s}');
}
+ else if (node.name === 'binary') {
+ nodes.push(node);
+ node.wrap(names.expr + '(' + i + ')(%s)');
+ }
+ else if (node.name === 'unary-postfix' || node.name === 'unary-prefix') {
+ nodes.push(node);
+ node.wrap(names.expr + '(' + i + ')(%s)');
+ }
});
};
@@ -55,7 +64,7 @@ Bunker.prototype.run = function (context) {
context[self.names.call] = function (i) {
var node = self.nodes[i];
stack.unshift(node);
- self.emit('call', node, stack);
+ self.emit('node', node, stack);
return function (expr) {
stack.shift();
@@ -63,12 +72,20 @@ Bunker.prototype.run = function (context) {
};
};
+ context[self.names.expr] = function (i) {
+ var node = self.nodes[i];
+ self.emit('node', node, stack);
+
+ return function (expr) {
+ return expr;
+ };
+ };
+
context[self.names.stat] = function (i) {
var node = self.nodes[i];
- self.emit('stat', node, stack);
+ self.emit('node', node, stack);
};
- console.log(src);
vm.runInNewContext(src, context);
return self;
View
34 test/cover.js
@@ -0,0 +1,34 @@
+var assert = require('assert');
+var bunker = require('../');
+var fs = require('fs');
+
+var src = fs.readdirSync(__dirname + '/src').reduce(function (acc, file) {
+ acc[file] = fs.readFileSync(__dirname + '/src/' + file, 'utf8');
+ return acc;
+}, {});
+
+exports.cover = function () {
+ var b = bunker(src['cover.js']);
+ var counts = {};
+
+ b.on('node', function (node) {
+ counts[node.name] = (counts[node.name] || 0) + 1;
+ });
+
+ b.run({
+ setInterval : setInterval,
+ clearInterval : function () {
+ process.nextTick(function () {
+ assert.deepEqual(counts, {
+ binary : 11,
+ 'unary-postfix' : 11,
+ call : 2, // setInterval and clearInterval
+ stat : 1, // clearInterval
+ });
+ });
+
+ return clearInterval.apply(this, arguments);
+ },
+ console : console
+ });
+};
View
6 test/src/cover.js
@@ -0,0 +1,6 @@
+var i = 0;
+var iv = setInterval(function () {
+ if (i++ === 10) {
+ clearInterval(iv);
+ }
+}, 10);
Please sign in to comment.
Something went wrong with that request. Please try again.