mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +03:00
feat(parser): rewrite lexer to make it faster (#50)
* 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
This commit is contained in:
committed by
GitHub
parent
fda6ddd6ee
commit
772d422d77
@@ -1,4 +1,7 @@
|
||||
import { iterate } from '../src/utils';
|
||||
import { iterate, match } from '../src/utils';
|
||||
|
||||
const stringify = val => JSON.stringify(val);
|
||||
|
||||
|
||||
describe('@bbob/core utils', () => {
|
||||
test('iterate', () => {
|
||||
@@ -16,14 +19,47 @@ describe('@bbob/core utils', () => {
|
||||
return node;
|
||||
});
|
||||
|
||||
expect(resultArr).toEqual([{
|
||||
one: true,
|
||||
pass: 1,
|
||||
content: [{ oneInside: true, pass: 1, }]
|
||||
}, {
|
||||
two: true,
|
||||
pass: 1,
|
||||
content: [{ twoInside: true, pass: 1, }]
|
||||
}]);
|
||||
const expected = [
|
||||
{
|
||||
one: true,
|
||||
content: [{ oneInside: true, pass: 1, }],
|
||||
pass: 1,
|
||||
}, {
|
||||
two: true,
|
||||
content: [{ twoInside: true, pass: 1, }],
|
||||
pass: 1,
|
||||
}
|
||||
];
|
||||
|
||||
expect(stringify(resultArr)).toEqual(stringify(expected));
|
||||
});
|
||||
test('match', () => {
|
||||
const testArr = [
|
||||
{ tag: 'mytag1', one: 1 },
|
||||
{ tag: 'mytag2', two: 1 },
|
||||
{ tag: 'mytag3', three: 1 },
|
||||
{ tag: 'mytag4', four: 1 },
|
||||
{ tag: 'mytag5', five: 1 },
|
||||
{ tag: 'mytag6', six: 1 },
|
||||
];
|
||||
|
||||
testArr.match = match;
|
||||
|
||||
const resultArr = testArr.match([{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
|
||||
node.pass = 1;
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
const expected = [
|
||||
{ tag: 'mytag1', one: 1, pass: 1 },
|
||||
{ tag: 'mytag2', two: 1, pass: 1 },
|
||||
{ tag: 'mytag3', three: 1 },
|
||||
{ tag: 'mytag4', four: 1 },
|
||||
{ tag: 'mytag5', five: 1 },
|
||||
{ tag: 'mytag6', six: 1 },
|
||||
];
|
||||
|
||||
expect(stringify(resultArr)).toEqual(stringify(expected))
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user