Skip to content

Commit

Permalink
chore: extend lexer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Nov 3, 2023
1 parent 02830d4 commit fe21797
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/N3Lexer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,20 @@ describe('Lexer', () => {
{ type: 'eof', line: 1 })
);

it('should tokenize a split left implication as inverse of [=>] when isImpliedBy is disabled',
shouldTokenize(new Lexer({ isImpliedBy: false }), streamOf('<a> <', '= <b> '),
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'inverse', value: '>', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'eof', line: 1 }));

it('should tokenize a left implication as inverse of [=>] when isImpliedBy is disabled',
shouldTokenize(new Lexer({ isImpliedBy: false }), streamOf('<a> <= <b> '),
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'inverse', value: '>', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'eof', line: 1 }));

it(
'should tokenize paths',
shouldTokenize(':joe!fam:mother!loc:office!loc:zip :joe!fam:mother^fam:mother',
Expand Down Expand Up @@ -1038,6 +1052,52 @@ describe('Lexer', () => {
{ type: 'eof', line: 3 })
);

it('should tokenize an RDF-star annotated statement',
shouldTokenize('<a> <b> <c> {| <d> <e> |}',
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'IRI', value: 'c', line: 1 },
{ type: '{|', line: 1 },
{ type: 'IRI', value: 'd', line: 1 },
{ type: 'IRI', value: 'e', line: 1 },
{ type: '|}', line: 1 },
{ type: 'eof', line: 1 }));

it('should tokenize an RDF-star annotated statement with multiple annotations',
shouldTokenize('<a> <b> <c> {| <d> <e>; <f> <g> |}',
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'IRI', value: 'c', line: 1 },
{ type: '{|', line: 1 },
{ type: 'IRI', value: 'd', line: 1 },
{ type: 'IRI', value: 'e', line: 1 },
{ type: ';', line: 1 },
{ type: 'IRI', value: 'f', line: 1 },
{ type: 'IRI', value: 'g', line: 1 },
{ type: '|}', line: 1 },
{ type: 'eof', line: 1 }));

it('should tokenize an RDF-star annotated statement with multiple annotations, one containing a blank node',
shouldTokenize('<a> <b> <c> {| <d> [ <e> "f" ]; <f> <g> |}',
{ type: 'IRI', value: 'a', line: 1 },
{ type: 'IRI', value: 'b', line: 1 },
{ type: 'IRI', value: 'c', line: 1 },
{ type: '{|', line: 1 },
{ type: 'IRI', value: 'd', line: 1 },
{ type: '[', value: '', line: 1 },
{ type: 'IRI', value: 'e', line: 1 },
{ type: 'literal', value: 'f', line: 1 },
{ type: ']', value: '', line: 1 },
{ type: ';', line: 1 },
{ type: 'IRI', value: 'f', line: 1 },
{ type: 'IRI', value: 'g', line: 1 },
{ type: '|}', line: 1 },
{ type: 'eof', line: 1 }));

it('should not tokenize an annotated statement that is not closed',
shouldNotTokenize('<a> <b> <c> {| <d> [ <e> "f" ]; <f> <g> |',
'Unexpected "|" on line 1.'));

it(
'should not tokenize a wrongly closed RDF* statement with IRIs',
shouldNotTokenize('<<<http://ex.org/?bla#foo> \n\t<http://ex.org/?bla#bar> \n\t<http://ex.org/?bla#boo>> .',
Expand Down

0 comments on commit fe21797

Please sign in to comment.