angular-cn/aio/content/dict/extractor.spec.ts
2018-03-01 20:09:22 +08:00

51 lines
1.4 KiB
TypeScript

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