Skip to content
Snippets Groups Projects
Select Git revision
  • 7f94cc255d2eea22542fe6b9ec9fef6e8dbc253d
  • main default protected
  • ts
  • raw-crypt
  • v3.5.8 protected
  • v3.5.7 protected
  • v3.5.6 protected
  • v3.5.5 protected
  • v3.5.4 protected
  • v3.5.3 protected
  • v3.5.2 protected
  • v3.5.1 protected
  • v3.5.0 protected
  • v3.4.2 protected
  • v3.4.1 protected
  • v3.4.0 protected
  • v3.3.3 protected
  • v3.3.2 protected
  • v3.3.1 protected
  • v3.3.0 protected
  • v3.2.0 protected
  • v3.1.0 protected
  • v3.0.2 protected
  • v3.0.1 protected
24 results

dictionary-parser.test.mjs

Blame
  • 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 => {