Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
getLastNodeToken test
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevils committed Nov 23, 2014
1 parent aa9dcc7 commit b2e6b05
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions test/js-file.js
Expand Up @@ -51,19 +51,6 @@ describe('modules/js-file', function() {
});
});

it('should return token for specified node', function() {
var str = 'if (true) { while (true) x++; }';
var file = new JsFile(null, str, esprima.parse(str, {loc: true, range: true, tokens: true}));

var ifToken = file.getFirstNodeToken(file.getNodesByType('IfStatement')[0]);
assert(ifToken.type === 'Keyword');
assert(ifToken.value === 'if');

var incToken = file.getFirstNodeToken(file.getNodesByType('UpdateExpression')[0]);
assert(incToken.type === 'Identifier');
assert(incToken.value === 'x');
});

describe('iterateTokenByValue', function() {
it('should find token by value', function() {
var str = 'if (true);';
Expand Down Expand Up @@ -445,4 +432,34 @@ describe('modules/js-file', function() {
assert(token === undefined);
});
});

describe('getFirstNodeToken', function() {
it('should return token for specified node', function() {
var str = 'if (true) { while (true) x++; }';
var file = new JsFile(null, str, esprima.parse(str, {loc: true, range: true, tokens: true}));

var ifToken = file.getFirstNodeToken(file.getNodesByType('IfStatement')[0]);
assert.equal(ifToken.type, 'Keyword');
assert.equal(ifToken.value, 'if');

var incToken = file.getFirstNodeToken(file.getNodesByType('UpdateExpression')[0]);
assert.equal(incToken.type, 'Identifier');
assert.equal(incToken.value, 'x');
});
});

describe('getLastNodeToken', function() {
it('should return token for specified node', function() {
var str = 'if (true) { while (true) x++; }';
var file = new JsFile(null, str, esprima.parse(str, {loc: true, range: true, tokens: true}));

var ifToken = file.getLastNodeToken(file.getNodesByType('IfStatement')[0]);
assert.equal(ifToken.type, 'Punctuator');
assert.equal(ifToken.value, '}');

var incToken = file.getLastNodeToken(file.getNodesByType('UpdateExpression')[0]);
assert.equal(incToken.type, 'Punctuator');
assert.equal(incToken.value, '++');
});
});
});

0 comments on commit b2e6b05

Please sign in to comment.