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

60 lines
1.8 KiB
TypeScript
Raw Normal View History

import { expect } from 'chai';
import { DictEntry } from './dict-entry';
2018-03-01 09:35:54 -05:00
import { dirs } from './dirs';
import { gatherFromMarkdownFiles, isTranslation } from './extractor';
describe('auto check translations', function () {
2018-03-01 09:35:54 -05:00
const entries = gatherFromMarkdownFiles(dirs.content)
.filter(isNotCheatSheet)
.filter(isNotMarketingDocs)
.filter(isNotCnPages);
it('should not have <code-example> in translation', function () {
const codeExamples = entries.filter(entry => entry.translation.indexOf('<code-example') !== -1);
expect(codeExamples).eql([]);
});
it('english should not be translations', function () {
const lines = entries.filter(entry => isTranslation(entry.original))
.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;
});
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([]);
});
});
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);
}
function isHead(line: string): boolean {
return /^#/.test(line);
}