2018-03-01 09:19:59 -05:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import { DictEntry } from './dict-entry';
|
2018-03-01 09:35:54 -05:00
|
|
|
import { dirs } from './dirs';
|
2018-03-01 09:19:59 -05:00
|
|
|
import { gatherFromMarkdownFiles, isTranslation } from './extractor';
|
|
|
|
|
|
|
|
describe('auto check translations', function () {
|
2018-03-01 09:35:54 -05:00
|
|
|
const entries = gatherFromMarkdownFiles(dirs.content)
|
2018-03-01 09:28:13 -05:00
|
|
|
.filter(isNotCheatSheet)
|
|
|
|
.filter(isNotMarketingDocs)
|
|
|
|
.filter(isNotCnPages);
|
|
|
|
|
2018-03-01 09:19:59 -05:00
|
|
|
it('should not have <code-example> in translation', function () {
|
|
|
|
const codeExamples = entries.filter(entry => entry.translation.indexOf('<code-example') !== -1);
|
|
|
|
expect(codeExamples).eql([]);
|
|
|
|
});
|
2018-03-01 09:28:13 -05:00
|
|
|
|
2018-03-01 09:19:59 -05:00
|
|
|
it('english should not be translations', function () {
|
|
|
|
const lines = entries.filter(entry => isTranslation(entry.original))
|
2018-03-01 09:28:13 -05:00
|
|
|
.filter(isNotImg);
|
|
|
|
expect(lines).eql([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have same head level', function () {
|
|
|
|
const lines = entries
|
|
|
|
.filter(entry => isHead(entry.original) && isHead(entry.translation))
|
|
|
|
.filter(entry => {
|
|
|
|
const originalLevel = entry.original.replace(/^(#+).*$/, '$1').length;
|
|
|
|
const translationLevel = entry.translation.replace(/^(#+).*$/, '$1').length;
|
|
|
|
return originalLevel !== translationLevel;
|
|
|
|
});
|
|
|
|
|
2018-03-01 09:19:59 -05:00
|
|
|
expect(lines).eql([]);
|
|
|
|
});
|
2018-03-01 09:52:16 -05:00
|
|
|
|
|
|
|
it('english should not be <div class', function () {
|
|
|
|
const lines = entries.filter(entry => /^ *<div.*/.test(entry.original));
|
|
|
|
expect(lines).eql([]);
|
|
|
|
});
|
2018-03-01 09:19:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
function isNotImg(entry: DictEntry): boolean {
|
|
|
|
return !/^<(img|figure)/.test(entry.translation);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isNotCheatSheet(entry: DictEntry): boolean {
|
|
|
|
return !/cheatsheet.md$/.test(entry.sourceFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isNotMarketingDocs(entry: DictEntry): boolean {
|
|
|
|
return !/marketing\/docs.md$/.test(entry.sourceFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isNotCnPages(entry: DictEntry): boolean {
|
|
|
|
return !/cn\/.*?.md$/.test(entry.sourceFile);
|
|
|
|
}
|
2018-03-01 09:28:13 -05:00
|
|
|
|
|
|
|
function isHead(line: string): boolean {
|
|
|
|
return /^#/.test(line);
|
|
|
|
}
|