2023-09-27 23:36:51 +03:00
|
|
|
import { Grammeme, parseEntityReference, parseGrammemes, parseSyntacticReference } from './language';
|
2023-09-21 14:58:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
describe('Testing grammeme parsing', () => {
|
|
|
|
test('empty input',
|
|
|
|
() => {
|
|
|
|
expect(parseGrammemes('').length).toBe(0);
|
|
|
|
expect(parseGrammemes(' ').length).toBe(0);
|
|
|
|
expect(parseGrammemes(' , ').length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('regular grammemes',
|
|
|
|
() => {
|
2023-09-27 23:36:51 +03:00
|
|
|
expect(parseGrammemes('NOUN')).toStrictEqual([Grammeme.NOUN]);
|
|
|
|
expect(parseGrammemes('sing,nomn')).toStrictEqual([Grammeme.sing, Grammeme.nomn]);
|
|
|
|
expect(parseGrammemes('nomn,sing')).toStrictEqual([Grammeme.sing, Grammeme.nomn]);
|
|
|
|
expect(parseGrammemes('nomn,invalid,sing')).toStrictEqual([Grammeme.sing, Grammeme.nomn, 'invalid']);
|
|
|
|
expect(parseGrammemes('invalid,test')).toStrictEqual(['invalid', 'test']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('Testing reference parsing', () => {
|
|
|
|
test('entity reference',
|
|
|
|
() => {
|
|
|
|
expect(parseEntityReference('@{ X1 | NOUN,sing }')).toStrictEqual({entity: 'X1', form: 'NOUN,sing'});
|
|
|
|
expect(parseEntityReference('@{X1|NOUN,sing}')).toStrictEqual({entity: 'X1', form: 'NOUN,sing'});
|
|
|
|
expect(parseEntityReference('@{X111|NOUN,sing}')).toStrictEqual({entity: 'X111', form: 'NOUN,sing'});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('syntactic reference',
|
|
|
|
() => {
|
|
|
|
expect(parseSyntacticReference('@{1|test test}')).toStrictEqual({offset: 1, nominal: 'test test'});
|
|
|
|
expect(parseSyntacticReference('@{101|test test}')).toStrictEqual({offset: 101, nominal: 'test test'});
|
|
|
|
expect(parseSyntacticReference('@{-1|test test}')).toStrictEqual({offset: -1, nominal: 'test test'});
|
|
|
|
expect(parseSyntacticReference('@{-99|test test}')).toStrictEqual({offset: -99, nominal: 'test test'});
|
2023-09-21 14:58:01 +03:00
|
|
|
});
|
|
|
|
});
|