mirror of
https://github.com/tenrok/BBob.git
synced 2026-05-18 12:39:39 +03:00
772d422d77
* feat(parser): first iteration of new lexer * feat(parser): convert token string props to number props * refactor(parser): optimize char grabber * refactor(parser): working on new lexer * refactor(parser): convert token string props to number props * refactor(parser): rebuild lexer, add tag attrs parsing * refactor(parser): rework word parsing and tag parsing * refactor(parser): rework to pass tests * refactor(parser): rework tag parsing * refactor(parser): rework escape tags parsing * refactor(parser): rework tests * refactor(parser): all test pass * refactor(parser): make lexer faster by move mode switching in loop * refactor(parser): remove all state map objects * refactor(parser): order of parsing states * refactor(parser): state switching without return * refactor(parser): rename buffers to chars * refactor(lexer): reduce function calls * feat(lexer): add new parser tests and code to pass it * fix(utils): remove unused variable in char grabber * feat(lexer): add test for new lexer bug * chore(*): add lexer and lexer2 to benchmark * chore(lexer): add some debug info for char grabber * feat(parser): add new test for single attributes without values * fix(lexer): paired tags tests * refactor(lexer): comment breaking changes tests for future releases * feat(core): improve tests * refactor(parser): add more tests, reduce char grabber size * refactor(parser): reduce utils size * refactor(parser): remove unused code from tag parsing code * refactor(parser): remove unused code from word to tag transforming code * chore(benchmark): fix benchmark imports
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
import Token, { TYPE_WORD, TYPE_TAG, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_SPACE, TYPE_NEW_LINE } from '../src/Token'
|
|
|
|
describe('Token', () => {
|
|
test('isEmpty', () => {
|
|
const token = new Token();
|
|
|
|
expect(token.isEmpty()).toBeTruthy()
|
|
});
|
|
test('isText', () => {
|
|
const token = new Token(TYPE_WORD);
|
|
|
|
expect(token.isText()).toBeTruthy();
|
|
});
|
|
test('isTag', () => {
|
|
const token = new Token(TYPE_TAG);
|
|
|
|
expect(token.isTag()).toBeTruthy();
|
|
});
|
|
test('isAttrName', () => {
|
|
const token = new Token(TYPE_ATTR_NAME);
|
|
|
|
expect(token.isAttrName()).toBeTruthy();
|
|
});
|
|
test('isAttrValue', () => {
|
|
const token = new Token(TYPE_ATTR_VALUE);
|
|
|
|
expect(token.isAttrValue()).toBeTruthy();
|
|
});
|
|
test('isStart', () => {
|
|
const token = new Token(TYPE_TAG, 'my-tag');
|
|
|
|
expect(token.isStart()).toBeTruthy();
|
|
});
|
|
test('isEnd', () => {
|
|
const token = new Token(TYPE_TAG, '/my-tag');
|
|
|
|
expect(token.isEnd()).toBeTruthy();
|
|
});
|
|
test('getName', () => {
|
|
const token = new Token(TYPE_TAG, '/my-tag');
|
|
|
|
expect(token.getName()).toBe('my-tag');
|
|
});
|
|
test('getValue', () => {
|
|
const token = new Token(TYPE_TAG, '/my-tag');
|
|
|
|
expect(token.getValue()).toBe('/my-tag');
|
|
});
|
|
test('getLine', () => {
|
|
const token = new Token(TYPE_TAG, '/my-tag', 12);
|
|
|
|
expect(token.getLine()).toBe(12);
|
|
});
|
|
test('getColumn', () => {
|
|
const token = new Token(TYPE_TAG, '/my-tag', 12, 14);
|
|
|
|
expect(token.getColumn()).toBe(14);
|
|
});
|
|
test('toString', () => {
|
|
const tokenEnd = new Token(TYPE_TAG, '/my-tag', 12, 14);
|
|
|
|
expect(tokenEnd.toString()).toBe('[/my-tag]');
|
|
|
|
const tokenStart = new Token(TYPE_TAG, 'my-tag', 12, 14);
|
|
|
|
expect(tokenStart.toString()).toBe('[my-tag]');
|
|
});
|
|
});
|