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

49 lines
1.4 KiB
TypeScript
Raw Normal View History

import { expect } from 'chai';
2018-03-01 09:35:54 -05:00
import { dirs } from './dirs';
2018-03-02 19:13:52 -05:00
import { gatherFromMarkdownFiles } from './extractor';
import {
isHead,
isNotCheatSheet,
isNotCnPages,
isNotImg,
isNotMarketingDocs,
originalIsNotChinese,
originalIsNotSpecialDivTag,
2018-03-02 19:13:52 -05:00
translationHasNotCodeExample,
} from './utils';
2018-03-01 19:08:39 -05:00
describe('自动检查翻译结果', function () {
2018-03-01 09:35:54 -05:00
const entries = gatherFromMarkdownFiles(dirs.content)
.filter(isNotCheatSheet)
.filter(isNotMarketingDocs)
.filter(isNotCnPages);
2018-03-01 19:08:39 -05:00
it('译文里不应该出现 <code-example>', function () {
2018-03-02 19:13:52 -05:00
const codeExamples = entries.filter(translationHasNotCodeExample);
expect(codeExamples).eql([]);
});
2018-03-01 19:08:39 -05:00
it('原文中不应该有汉语', function () {
2018-03-02 19:13:52 -05:00
const lines = entries.filter(originalIsNotChinese)
.filter(isNotImg);
expect(lines).eql([]);
});
2018-03-01 19:08:39 -05:00
it('原文和译文应该有相同的标题等级', 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
2018-03-01 19:08:39 -05:00
it('原文不应该是以 <div 开头的', function () {
const lines = entries.filter(originalIsNotSpecialDivTag);
2018-03-01 09:52:16 -05:00
expect(lines).eql([]);
});
});