angular-cn/aio/tools/translator/extractor.spec.ts

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-03-01 01:07:51 -05:00
import { expect } from 'chai';
2018-03-01 09:35:54 -05:00
import { dirs } from './dirs';
2018-03-01 01:07:51 -05:00
import { gatherFromMarkdownFiles, gatherTranslations, listMarkdownFiles, splitAndTrim } from './extractor';
describe('gather to dictionary', () => {
it('should split empty string to empty array', function () {
expect(splitAndTrim()).eql([]);
});
it('should should break by double line break', function () {
const result = splitAndTrim(`a
b
c
d`);
expect(result[1]).eql(`b
c`);
});
it('build map of original and translation', () => {
const result = gatherTranslations(`
a
b
`);
expect(result).eql([{original: 'a', translation: '一'}]);
});
it('should gather from real file', function () {
const fs = require('fs');
2018-03-01 09:35:54 -05:00
const content = fs.readFileSync(dirs.content + 'guide/forms.md', 'utf-8');
2018-03-01 01:07:51 -05:00
const result = gatherTranslations(content);
expect(result[0]).eql({original: '# Forms', translation: '# 表单'});
});
it('should list files recursive', function () {
2018-03-01 09:35:54 -05:00
expect(listMarkdownFiles(dirs.content).length).greaterThan(10);
2018-03-01 01:07:51 -05:00
});
2018-03-01 01:07:51 -05:00
it('should gather from directory', () => {
2018-03-01 09:35:54 -05:00
const entries = gatherFromMarkdownFiles(dirs.content);
2018-03-01 01:07:51 -05:00
const dict = JSON.stringify(entries, null, 2);
const fs = require('fs');
2018-03-01 09:35:54 -05:00
fs.writeFileSync(dirs.here + 'dict-3.json', dict, 'utf-8');
2018-03-01 01:07:51 -05:00
expect(entries.length).greaterThan(100);
});
2018-03-01 01:07:51 -05:00
});