Skip to content

Commit

Permalink
Add Tokenizer test for bug #33.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdecaluwe committed Nov 11, 2020
1 parent 65955e4 commit 9a20a97
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/TokenizerSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

const Tokenizer = require('../tokenizer.js');
const Configuration = require('../configuration.js');
const Cache = require('../cache.js');

describe('Tokenizer', function () {
let tokenizer;
let configuration;

beforeEach(function () {
Tokenizer.cache = new Cache(10);
configuration = new Configuration();
tokenizer = new Tokenizer(configuration);
});
it('should stop tokenizing at special characters', function () {
tokenizer.data('TEST DATA+', 0);
expect(tokenizer.content()).toEqual('TEST DATA');
});
it('should properly initialize when using cached regexes', function () {
// This test was written specifically for a bug where the default regex
// wasn't set after a configuration with a cache hit.
var cached = new Tokenizer(configuration);
var character = String.fromCharCode(50);

configuration = new Configuration({ decimalMark: 50 });

tokenizer.configure(configuration);
cached.configure(configuration);
tokenizer.data(character, 0);
cached.data(character, 0);

expect(tokenizer.length).toEqual(cached.length);
});
});

0 comments on commit 9a20a97

Please sign in to comment.