@tanishiking/aho-corasick
Version:
TypeScript implementation of the Aho-Corasick algorithm for efficient string matching
38 lines (37 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var state_1 = require("./state");
describe('State', function () {
describe('addState', function () {
it('can construct sequence of characters', function () {
var rootState = new state_1.State(0);
rootState.addState('a').addState('b').addState('c');
var stateA = rootState.nextState('a');
expect(stateA.depth).toBe(1);
var stateB = stateA.nextState('b');
expect(stateB.depth).toBe(2);
var stateC = stateB.nextState('c');
expect(stateC.depth).toBe(3);
});
});
describe('getStates', function () {
it('can retrieve all states that are reachable with one step', function () {
var rootState = new state_1.State(0);
rootState.addState('a').addState('d');
rootState.addState('b');
rootState.addState('c');
rootState.getStates().forEach(function (state) {
expect(state.depth).toBe(1);
});
});
});
describe('getTransitions', function () {
it('can retrieve all transitions', function () {
var rootState = new state_1.State(0);
rootState.addState('a').addState('d');
rootState.addState('b');
rootState.addState('c');
expect(rootState.getTransitions()).toEqual(['a', 'b', 'c']);
});
});
});