Skip to content

Commit

Permalink
Merge pull request #3 from ideadapt/resurrection
Browse files Browse the repository at this point in the history
Migrate to latest should.js, more robust test runner, espree replaces esprima
  • Loading branch information
Swatinem committed Mar 30, 2015
2 parents 3ea285f + cb65209 commit bcd8a4f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions bin/esgraph.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node

var esprima = require('esprima');
var espree = require('espree');
var walkes = require('walkes');
var esgraph = require('../');

Expand All @@ -19,7 +19,7 @@ process.stdin.on('end', function () {
}

try {
var ast = esprima.parse(source, {range: true});
var ast = espree.parse(source, {range: true});
var functions = findFunctions(ast);

console.log('digraph cfg {');
Expand Down Expand Up @@ -48,7 +48,7 @@ process.stdin.on('end', function () {

function findFunctions(ast) {
var functions = [];
function handleFunction(node, recurse, stop) {
function handleFunction(node, recurse) {
functions.push(node);
recurse(node.body);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"Arpad Borsos <arpad.borsos@googlemail.com> (http://swatinem.de)"
],
"dependencies": {
"esprima": "~ 1.0",
"espree": "~ 1.12.3",
"walkes": "~ 0.2.0"
},
"devDependencies": {
Expand Down
16 changes: 9 additions & 7 deletions test/test.js
@@ -1,11 +1,11 @@

var esgraph = require('../');
var esprima = require('esprima');
var espree = require('espree');
var fs = require('fs');

function createTest(dir, file) {
var contents = fs.readFileSync(dir + file, 'utf8');
var ast = esprima.parse(contents, {comment: true, range: true});
var ast = espree.parse(contents, {comment: true, range: true});
var comments = ast.comments;
delete ast.comments;
it(comments[0].value.trim() + ' (' + file + ')', function () {
Expand All @@ -24,21 +24,23 @@ describe('esgraph', function () {
var dir = __dirname + '/tests/';
var files = fs.readdirSync(dir);
files.forEach(function (file) {
createTest(dir, file);
if(/.js$/.test(file)){
createTest(dir, file);
}
});

it('should handle long graphs', function () {
var source = Array(1e4).join('stmt;');
var ast = esprima.parse(source);
var ast = espree.parse(source);
var cfg = esgraph(ast);
esgraph.dot(cfg);
});
});

describe('esgraph.dot', function () {
it('should number the nodes starting at `counter`', function () {
var out = esgraph.dot(esgraph(esprima.parse('var a;')), {counter: 10});
out.should.not.include('n0');
out.should.include('n10');
var out = esgraph.dot(esgraph(espree.parse('var a;')), {counter: 10});
out.should.not.containEql('n0');
out.should.containEql('n10');
});
});

0 comments on commit bcd8a4f

Please sign in to comment.