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