2017-03-30 14:37:30 +02:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
2019-09-16 16:40:37 +02:00
|
|
|
import { MarkerParser } from '../../src/parsers/marker.parser';
|
2017-03-30 14:37:30 +02:00
|
|
|
|
2019-09-16 16:40:37 +02:00
|
|
|
describe('MarkerParser', () => {
|
2017-03-30 14:37:30 +02:00
|
|
|
const componentFilename: string = 'test.component.ts';
|
|
|
|
|
2019-09-16 16:40:37 +02:00
|
|
|
let parser: MarkerParser;
|
2017-03-30 14:37:30 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-09-16 16:40:37 +02:00
|
|
|
parser = new MarkerParser();
|
2017-03-30 14:37:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should extract strings using marker function', () => {
|
|
|
|
const contents = `
|
2019-07-17 13:00:29 +02:00
|
|
|
import { marker } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
|
marker('Hello world');
|
|
|
|
marker(['I', 'am', 'extracted']);
|
2017-03-30 14:37:30 +02:00
|
|
|
otherFunction('But I am not');
|
2019-07-17 13:00:29 +02:00
|
|
|
marker(message || 'binary expression');
|
|
|
|
marker(message ? message : 'conditional operator');
|
|
|
|
marker('FOO.bar');
|
2017-03-30 14:37:30 +02:00
|
|
|
`;
|
|
|
|
const keys = parser.extract(contents, componentFilename).keys();
|
2019-06-13 11:44:30 +02:00
|
|
|
expect(keys).to.deep.equal(['Hello world', 'I', 'am', 'extracted', 'binary expression', 'conditional operator', 'FOO.bar']);
|
2017-03-30 14:37:30 +02:00
|
|
|
});
|
|
|
|
|
2019-09-16 16:58:21 +02:00
|
|
|
it('should extract split strings', () => {
|
|
|
|
const contents = `
|
|
|
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
|
_('Hello ' + 'world');
|
|
|
|
_('This is a ' + 'very ' + 'very ' + 'very ' + 'very ' + 'long line.');
|
|
|
|
_('Mix ' + \`of \` + 'different ' + \`types\`);
|
|
|
|
`;
|
|
|
|
const keys = parser.extract(contents, componentFilename).keys();
|
2019-09-18 14:16:47 +02:00
|
|
|
expect(keys).to.deep.equal(['Hello world', 'This is a very very very very long line.', 'Mix of different types']);
|
2019-09-16 16:58:21 +02:00
|
|
|
});
|
2020-03-22 11:13:16 +01:00
|
|
|
|
2020-04-01 12:19:30 +02:00
|
|
|
it('should extract split strings while keeping html tags', () => {
|
|
|
|
const contents = `
|
|
|
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
|
_('Hello ' + 'world');
|
|
|
|
_('This <em>is</em> a ' + 'very ' + 'very ' + 'very ' + 'very ' + 'long line.');
|
|
|
|
_('Mix ' + \`of \` + 'different ' + \`types\`);
|
|
|
|
`;
|
|
|
|
const keys = parser.extract(contents, componentFilename).keys();
|
|
|
|
expect(keys).to.deep.equal(['Hello world', 'This <em>is</em> a very very very very long line.', 'Mix of different types']);
|
|
|
|
});
|
|
|
|
|
2020-03-22 11:13:16 +01:00
|
|
|
it('should extract the strings', () => {
|
|
|
|
const contents = `
|
|
|
|
import { marker } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
|
|
|
|
|
export class AppModule {
|
|
|
|
constructor() {
|
|
|
|
marker('DYNAMIC_TRAD.val1');
|
|
|
|
marker('DYNAMIC_TRAD.val2');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
const keys = parser.extract(contents, componentFilename).keys();
|
|
|
|
expect(keys).to.deep.equal(['DYNAMIC_TRAD.val1', 'DYNAMIC_TRAD.val2']);
|
|
|
|
});
|
2017-03-30 14:37:30 +02:00
|
|
|
});
|