Permalink
Browse files

add coverage with istanbul

  • Loading branch information...
1 parent 136a825 commit 69d8c1307c37def64528ae2e9b3aee7d8e549076 Florent Jaby committed Jul 15, 2013
Showing with 48 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +1 −1 lib/Tokenizer.js
  3. +46 −0 test/test-tokenizer.js
View
1 .gitignore
@@ -1,3 +1,4 @@
.*.swp
.*.un~
node_modules
+coverage
View
2 lib/Tokenizer.js
@@ -141,7 +141,7 @@ Tokenizer.prototype.addRule = function addRule(regex, type) {
* set some tokens to be ignored. these won't be emitted
*/
Tokenizer.prototype.ignore = function ignore(ignored) {
- if(typeof ignore === 'array') {
+ if(Array.isArray(ignored)) {
for (var i = 0; i < ignored.length; ++i) {
this.ignore(ignored[i]);
}
View
46 test/test-tokenizer.js
@@ -34,6 +34,21 @@ exports['test emits error when no rules'] = function (test) {
t.end('Hello World!');
}.withDomain()
+exports['calling toString on tokens'] = function (test) {
+ var t = tokenizer();
+ t.addRule('number');
+ t.addRule('whitespace');
+ test.expect(3 * 2);
+ t.on('data', function(token, type) {
+ test.doesNotThrow(function () {
+ token.toString();
+ });
+ test.equal(token.content, token.toString());
+ });
+ t.on('end', test.done.bind(test));
+ t.end('8 10');
+}
+
exports['test ignore tokens'] = function(test) {
var t = tokenizer();
t.addRule('whitespace');
@@ -44,6 +59,37 @@ exports['test ignore tokens'] = function(test) {
t.end(' \n\r\t');
}.withDomain();
+exports['test ignore array of tokens'] = function(test) {
+ var t = tokenizer();
+ t.addRule('whitespace');
+ t.addRule('number');
+ t.ignore(['whitespace', 'number']);
+ test.expect(0);
+ t.on('data', test.fail.bind(test, "We should not get any data"));
+ t.on('end', test.done.bind(test));
+ t.end('8 67\n45\t10000');
+}.withDomain();
+
+
+exports['add built-in rules by name'] = function (test) {
+ var t = tokenizer();
+ test.expect(1);
+ t.on('token', function(token, type) {
+ test.equal('whitespace', type);
+ test.done();
+ });
+ t.addRule('whitespace');
+ t.end(' ');
+}
+
+exports['call addRule with no arguments throws'] = function (test) {
+ var t = tokenizer();
+ test.throws(function () {
+ t.addRule();
+ });
+ test.done();
+}
+
exports['test numbers'] = function(test) {
var numbers = [8, 1000, 34.5];
var t = tokenizer();

0 comments on commit 69d8c13

Please sign in to comment.