Select Git revision
dictionary-parser.test.mjs
-
Millicent Billette authoredMillicent Billette authored
dictionary-parser.test.mjs 4.94 KiB
import test from 'ava';
import * as app from './dictionary-parser.mjs';
test('parse remove ref:: lines', t => {
t.is(app.parse('ref::truc',false), '');
});
test('parse handle <ref>', t => {
t.is(app.parse(`ref::truc\nref::bidule\n<ref> <ref>`,false), '(truc|bidule) (truc|bidule)');
t.is(app.parse(`ref::(truc|bidule)\n<ref> <ref>`,false), '(truc|bidule) (truc|bidule)');
});
test('parse handle <ref> complex inclusion', t => {
t.is(app.parse(`ref::a<ref2>\n<ref>\nref2::(b|c)`,false), 'a(b|c)');
});
test('parse detect infinite recursion with <ref> and throw', t => {
t.throws(()=>app.parse(`ref::a<ref>\n<ref>`,false));
});
test('parse detect infinite recursion with nested <ref> and throw', t => {
t.throws(()=>app.parse(`ref::a<ref2>\n<ref>\nref2::b<ref>`,false));
});
test('parse handle [ -_]', t => {
t.is(app.parse('[ -_]',false), '( |-|_)');
});
test('parse handle [a-f]', t => {
t.is(app.parse('[a-f]',false), '(a|b|c|d|e|f)');
t.is(app.parse('[7-9]',false), '(7|8|9)');
t.is(app.parse('[C-F]',false), '(C|D|E|F)');
});
test('parse handle [a-c-]', t => {
t.is(app.parse('[a-c-]',false), '(a|b|c|-)');
});
test('parse handle {qty}', t => {
t.is(app.parse('a{5}',false), 'aaaaa');
});
test('parse handle {min,max}', t => {
t.is(app.parse('b{3,5}',false), 'bbb(|b)(|b)');
});
test('parse handle (string){qty}', t => {
t.is(app.parse(`c'est (toto|tata){0,2}`,false), `c'est (|toto|tata)(|toto|tata)`);
});
test('parse handle nested (s|t(ri|ng)){qty}', t => {
t.is(app.parse(`(s|t(ri|ng)){1,2}`,false), `(s|t(ri|ng))(|s|t(ri|ng))`);
});
test('parse handle plop:\\:', t => {
t.is(app.parse('plop:\\:ici',false), 'plop::ici');
t.is(app.parse('plop\\::ici',false), 'plop::ici');
t.is(app.parse('plop::ici',false), '');
});
test('parse handle [\\]*]', t => {
t.is(app.parse('[\\]*]',false), '(]|*)');
});
test('parse handle escaping common chr \\a', t => {
t.is(app.parse('\\a',false), 'a');
});
test('parse handle =ref>', t => {
t.is(app.parse(`ref::truc\nref::bidule\n=ref> =ref>`,false), '(truc truc|bidule bidule)');
t.is(app.parse(`ref::(truc|bidule)\n=ref> =ref>`,false), '(truc truc|bidule bidule)');
});
test('parse handle =ref> without generating duplication', t => {
t.is(app.parse(`ref::(truc|bidule)\n(=ref> =ref>|machin)`,false), '(truc truc|machin|bidule bidule)');
});
test('parse handle multiple =ref>', t => {
t.is(
app.parse(`=ref> =ref2> =ref> =ref2>\nref::(truc|bidule)\nref2::(machin|chose)`,false),
'(truc machin truc machin|bidule machin bidule machin|truc chose truc chose|bidule chose bidule chose)');
});
test('parse handle multi-level =ref>', t => {