angular-docs-cn/aio/content/dict/extractor.spec.ts

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-03-01 14:07:51 +08:00
import { expect } from 'chai';
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 20:11:12 +08:00
const content = fs.readFileSync(__dirname + '/../guide/forms.md', 'utf-8');
2018-03-01 14:07:51 +08:00
const result = gatherTranslations(content);
expect(result[0]).eql({original: '# Forms', translation: '# 表单'});
});
it('should list files recursive', function () {
2018-03-01 20:11:12 +08:00
expect(listMarkdownFiles(__dirname + '/../').length).greaterThan(10);
2018-03-01 14:07:51 +08:00
});
it('should gather from directory', () => {
2018-03-01 20:11:12 +08:00
const entries = gatherFromMarkdownFiles(__dirname + '/../');
2018-03-01 14:07:51 +08:00
const dict = JSON.stringify(entries, null, 2);
const fs = require('fs');
2018-03-01 20:11:12 +08:00
fs.writeFileSync(__dirname + '/../dict/dict-2.json', dict, 'utf-8');
2018-03-01 14:07:51 +08:00
expect(entries.length).greaterThan(100);
});
});