Permalink
Browse files

using tap

  • Loading branch information...
1 parent 9b1f388 commit 3de7a1753dbc7beeae7104834653261257c96860 @substack committed May 27, 2012
Showing with 144 additions and 150 deletions.
  1. +1 −0 example/microwave.js
  2. +5 −5 package.json
  3. +7 −5 test/ast.js
  4. +25 −20 test/err.js
  5. +55 −73 test/label.js
  6. +11 −10 test/microwave.js
  7. +7 −6 test/parent.js
  8. +33 −31 test/wrap.js
@@ -1,6 +1,7 @@
var burrito = require('burrito');
var res = burrito.microwave('Math.sin(2)', function (node) {
+ console.dir(node);
if (node.name === 'num') node.wrap('Math.PI / %s');
});
View
@@ -1,7 +1,7 @@
{
"name" : "burrito",
"description" : "Wrap up expressions with a trace function while walking the AST with rice and beans on the side",
- "version" : "0.2.11",
+ "version" : "0.2.12",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-burrito.git"
@@ -22,14 +22,14 @@
"test" : "test"
},
"scripts" : {
- "test" : "expresso"
+ "test" : "tap test/*.js"
},
"dependencies" : {
- "traverse" : ">=0.5.1 <0.6.0",
- "uglify-js" : "1.0.7"
+ "traverse" : "~0.5.1",
+ "uglify-js" : "~1.0.7"
},
"devDependencies" : {
- "expresso" : "=0.7.x"
+ "tap" : "~0.2.5"
},
"engines" : {
"node" : ">=0.4.0"
View
@@ -1,8 +1,10 @@
-var assert = require('assert');
+var test = require('tap').test;
var burrito = require('../');
var vm = require('vm');
-exports.ast = function () {
+test('ast', function (t) {
+ t.plan(2);
+
var ast = burrito.parse('f(g(h(5)))', false, true);
var src = burrito(ast, function (node) {
if (node.name === 'call') {
@@ -13,7 +15,7 @@ exports.ast = function () {
});
var times = 0;
- assert.equal(
+ t.equal(
vm.runInNewContext(src, {
f : function (x) { return x + 1 },
g : function (x) { return x + 2 },
@@ -25,5 +27,5 @@ exports.ast = function () {
}),
(((((5 + 3) * 10) + 2) * 10) + 1) * 10
);
- assert.equal(times, 3);
-};
+ t.equal(times, 3);
+});
View
@@ -1,47 +1,52 @@
-var assert = require('assert');
+var test = require('tap').test;
var burrito = require('../');
-exports.wrapError = function () {
+test('wrap error', function (t) {
+ t.plan(6);
+
try {
var src = burrito('f() && g()', function (node) {
if (node.name === 'binary') node.wrap('h(%a, %b')
});
- assert.fail('should have blown up');
+ t.fail('should have blown up');
}
catch (err) {
- assert.ok(err.message.match(/unexpected/i));
- assert.ok(err instanceof SyntaxError);
- assert.ok(!err.stack.match(/uglify-js/));
- assert.equal(err.line, 0);
- assert.equal(err.col, 10);
- assert.equal(err.pos, 10);
+ t.ok(err.message.match(/unexpected/i));
+ t.ok(err instanceof SyntaxError);
+ t.ok(!err.stack.match(/uglify-js/));
+ t.equal(err.line, 0);
+ t.equal(err.col, 10);
+ t.equal(err.pos, 10);
}
-};
+});
-exports.nonString = function () {
- assert.throws(function () {
+test('non string', function (t) {
+ t.plan(3);
+
+ t.throws(function () {
burrito.parse(new Buffer('[]'));
});
- assert.throws(function () {
+ t.throws(function () {
burrito.parse(new String('[]'));
});
- assert.throws(function () {
+ t.throws(function () {
burrito.parse();
});
-};
+});
-exports.syntaxError = function () {
+test('syntax error', function (t) {
+ t.plan(3);
try {
var src = burrito('f() && g())', function (node) {
if (node.name === 'binary') node.wrap('h(%a, %b)')
});
assert.fail('should have blown up');
}
catch (err) {
- assert.ok(err.message.match(/unexpected/i));
- assert.ok(err instanceof SyntaxError);
- assert.ok(!err.stack.match(/uglify-js/));
+ t.ok(err.message.match(/unexpected/i));
+ t.ok(err instanceof SyntaxError);
+ t.ok(!err.stack.match(/uglify-js/));
}
-};
+});
View
@@ -1,110 +1,92 @@
-var assert = require('assert');
+var test = require('tap').test;
var burrito = require('../');
-exports.callLabel = function () {
- var times = 0;
- var src = burrito('foo(10)', function (node) {
+test('call label', function (t) {
+ t.plan(1);
+
+ burrito('foo(10)', function (node) {
if (node.name === 'call') {
- assert.equal(node.label(), 'foo');
- times ++;
+ t.equal(node.label(), 'foo');
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.varLabel = function () {
- var times = 0;
- var src = burrito('var x = 2', function (node) {
+test('var label', function (t) {
+ t.plan(1);
+
+ burrito('var x = 2', function (node) {
if (node.name === 'var') {
- assert.deepEqual(node.label(), [ 'x' ]);
- times ++;
+ t.same(node.label(), [ 'x' ]);
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.varsLabel = function () {
- var times = 0;
- var src = burrito('var x = 2, y = 3', function (node) {
+test('vars label', function (t) {
+ t.plan(1);
+
+ burrito('var x = 2, y = 3', function (node) {
if (node.name === 'var') {
- assert.deepEqual(node.label(), [ 'x', 'y' ]);
- times ++;
+ t.same(node.label(), [ 'x', 'y' ]);
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.defunLabel = function () {
- var times = 0;
- var src = burrito('function moo () {}', function (node) {
+test('defun label', function (t) {
+ t.plan(1);
+
+ burrito('function moo () {}', function (node) {
if (node.name === 'defun') {
- assert.deepEqual(node.label(), 'moo');
- times ++;
+ t.same(node.label(), 'moo');
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.functionLabel = function () {
- var times = 0;
- var src = burrito('(function zzz () {})()', function (node) {
+test('function label', function (t) {
+ t.plan(1);
+
+ burrito('(function zzz () {})()', function (node) {
if (node.name === 'function') {
- assert.deepEqual(node.label(), 'zzz');
- times ++;
+ t.same(node.label(), 'zzz');
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.anonFunctionLabel = function () {
- var times = 0;
- var src = burrito('(function () {})()', function (node) {
+test('anon function label', function (t) {
+ t.plan(1);
+
+ burrito('(function () {})()', function (node) {
if (node.name === 'function') {
- assert.ok(node.label() === null);
- times ++;
+ t.equal(node.label(), null);
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.dotCallLabel = function () {
- var times = 0;
- var src = burrito('process.nextTick(fn)', function (node) {
+test('dot call label', function (t) {
+ t.plan(1);
+
+ burrito('process.nextTick(fn)', function (node) {
if (node.name === 'call') {
- assert.equal(node.label(), 'nextTick');
- times ++;
+ t.equal(node.label(), 'nextTick');
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.tripleDotLabel = function () {
- var times = 0;
- var src = burrito('a.b.c(fn)', function (node) {
+test('triple dot label', function (t) {
+ t.plan(1);
+
+ burrito('a.b.c(fn)', function (node) {
if (node.name === 'call') {
- assert.equal(node.label(), 'c');
- times ++;
+ t.equal(node.label(), 'c');
}
});
-
- assert.equal(times, 1);
-};
+});
-exports.exprLabel = function () {
- var times = 0;
- var src = burrito('a.b[x+1](fn)', function (node) {
+test('expr label', function (t) {
+ t.plan(1);
+
+ burrito('a.b[x+1](fn)', function (node) {
if (node.name === 'call') {
- assert.ok(node.label() === null);
- times ++;
+ t.ok(node.label() === null);
}
});
-
- assert.equal(times, 1);
-};
+});
View
@@ -1,14 +1,15 @@
-var assert = require('assert');
+var test = require('tap').test;
var burrito = require('../');
-exports.microwave = function () {
- var times = 0;
+test('microwave', function (t) {
+ t.plan(4);
+
var context = {
f : function (x) { return x + 1 },
g : function (x) { return x + 2 },
h : function (x) { return x + 3 },
z : function (x) {
- times ++;
+ t.ok(true); // 3 times
return x * 10;
},
};
@@ -21,13 +22,13 @@ exports.microwave = function () {
}
});
- assert.equal(res, (((((5 + 3) * 10) + 2) * 10) + 1) * 10);
- assert.equal(times, 3);
-};
+ t.equal(res, (((((5 + 3) * 10) + 2) * 10) + 1) * 10);
+});
-exports.emptyContext = function () {
+test('empty context', function (t) {
var res = burrito.microwave('Math.sin(2)', function (node) {
if (node.name === 'num') node.wrap('Math.PI / %s');
});
- assert.equal(res, 1);
-};
+ t.equal(res, 1);
+ t.end();
+});
View
@@ -1,15 +1,16 @@
-var assert = require('assert');
+var test = require('tap').test;
var burrito = require('../');
-exports.checkParent = function () {
+test('check parent', function (t) {
+ t.plan(5);
var src = 'Math.tan(0) + Math.sin(0)';
var res = burrito.microwave(src, function (node) {
if (node.name === 'binary') {
node.wrap('%a - %b');
}
else if (node.name === 'num') {
- assert.equal(node.parent().value[0][0], 'dot');
+ t.equal(node.parent().value[0][0], 'dot');
var fn = node.parent().value[0][2];
if (fn === 'sin') {
@@ -18,9 +19,9 @@ exports.checkParent = function () {
else if (fn === 'tan') {
node.wrap('Math.PI / 4');
}
- else assert.fail('Unknown fn');
+ else t.fail('Unknown fn');
}
});
- assert.equal(res, Math.tan(Math.PI / 4) - Math.sin(Math.PI / 2)); // ~ 0
-};
+ t.equal(res, Math.tan(Math.PI / 4) - Math.sin(Math.PI / 2)); // ~ 0
+});
Oops, something went wrong.

0 comments on commit 3de7a17

Please sign in to comment.