chore: 测试断言改为中文

This commit is contained in:
Zhicheng Wang 2018-03-02 08:08:39 +08:00
parent 0dbc49c7cc
commit ee97046824
3 changed files with 16 additions and 16 deletions

View File

@ -3,24 +3,24 @@ import { DictEntry } from './dict-entry';
import { dirs } from './dirs'; import { dirs } from './dirs';
import { gatherFromMarkdownFiles, isTranslation } from './extractor'; import { gatherFromMarkdownFiles, isTranslation } from './extractor';
describe('auto check translations', function () { describe('自动检查翻译结果', function () {
const entries = gatherFromMarkdownFiles(dirs.content) const entries = gatherFromMarkdownFiles(dirs.content)
.filter(isNotCheatSheet) .filter(isNotCheatSheet)
.filter(isNotMarketingDocs) .filter(isNotMarketingDocs)
.filter(isNotCnPages); .filter(isNotCnPages);
it('should not have <code-example> in translation', function () { it('译文里不应该出现 <code-example>', function () {
const codeExamples = entries.filter(entry => entry.translation.indexOf('<code-example') !== -1); const codeExamples = entries.filter(entry => entry.translation.indexOf('<code-example') !== -1);
expect(codeExamples).eql([]); expect(codeExamples).eql([]);
}); });
it('english should not be translations', function () { it('原文中不应该有汉语', function () {
const lines = entries.filter(entry => isTranslation(entry.original)) const lines = entries.filter(entry => isTranslation(entry.original))
.filter(isNotImg); .filter(isNotImg);
expect(lines).eql([]); expect(lines).eql([]);
}); });
it('should have same head level', function () { it('原文和译文应该有相同的标题等级', function () {
const lines = entries const lines = entries
.filter(entry => isHead(entry.original) && isHead(entry.translation)) .filter(entry => isHead(entry.original) && isHead(entry.translation))
.filter(entry => { .filter(entry => {
@ -32,7 +32,7 @@ describe('auto check translations', function () {
expect(lines).eql([]); expect(lines).eql([]);
}); });
it('english should not be <div class', function () { it('原文不应该是以 <div 开头的', function () {
const lines = entries.filter(entry => /^ *<div.*/.test(entry.original)); const lines = entries.filter(entry => /^ *<div.*/.test(entry.original));
expect(lines).eql([]); expect(lines).eql([]);
}); });

View File

@ -2,11 +2,11 @@ import { expect } from 'chai';
import { dirs } from './dirs'; import { dirs } from './dirs';
import { gatherFromMarkdownFiles, gatherTranslations, listMarkdownFiles, splitAndTrim } from './extractor'; import { gatherFromMarkdownFiles, gatherTranslations, listMarkdownFiles, splitAndTrim } from './extractor';
describe('gather to dictionary', () => { describe('从对照翻译文件中采集生成字典', () => {
it('should split empty string to empty array', function () { it('空字符串应该拆分成空数组', function () {
expect(splitAndTrim()).eql([]); expect(splitAndTrim()).eql([]);
}); });
it('should should break by double line break', function () { it('按照双行(忽略空格)拆分对照文本', function () {
const result = splitAndTrim(`a const result = splitAndTrim(`a
@ -19,7 +19,7 @@ describe('gather to dictionary', () => {
c`); c`);
}); });
it('build map of original and translation', () => { it('生成原文和译文的对照表', () => {
const result = gatherTranslations(` const result = gatherTranslations(`
a a
@ -30,18 +30,18 @@ describe('gather to dictionary', () => {
expect(result).eql([{original: 'a', translation: '一'}]); expect(result).eql([{original: 'a', translation: '一'}]);
}); });
it('should gather from real file', function () { it('从真实的文件中采集', function () {
const fs = require('fs'); const fs = require('fs');
const content = fs.readFileSync(dirs.content + 'guide/forms.md', 'utf-8'); const content = fs.readFileSync(dirs.content + 'guide/forms.md', 'utf-8');
const result = gatherTranslations(content); const result = gatherTranslations(content);
expect(result[0]).eql({original: '# Forms', translation: '# 表单'}); expect(result[0]).eql({original: '# Forms', translation: '# 表单'});
}); });
it('should list files recursive', function () { it('递归查找所有 markdown 文件', function () {
expect(listMarkdownFiles(dirs.content).length).greaterThan(10); expect(listMarkdownFiles(dirs.content).length).greaterThan(10);
}); });
it('should gather from directory', () => { it('从对照文本的文件夹中采集生成字典(非测试)', () => {
const entries = gatherFromMarkdownFiles(dirs.content); const entries = gatherFromMarkdownFiles(dirs.content);
const dict = JSON.stringify(entries, null, 2); const dict = JSON.stringify(entries, null, 2);
const fs = require('fs'); const fs = require('fs');

View File

@ -3,15 +3,15 @@ import { dirs } from './dirs';
import { dict, lookup, translate } from './translate'; import { dict, lookup, translate } from './translate';
describe('translate with dict', () => { describe('根据字典进行翻译', () => {
it('should ignore wrong entry', function () { it('忽略明显错误的条目', function () {
expect(dict.filter(entry => /^<div/.test(entry.original))).eql([]); expect(dict.filter(entry => /^<div/.test(entry.original))).eql([]);
}); });
it('translate original english', () => { it('查字典', () => {
expect(lookup('# Forms')[0].translation).eql('# 表单'); expect(lookup('# Forms')[0].translation).eql('# 表单');
}); });
it('should auto translate based on dict', function () { it('自动根据字典翻译单个文件', function () {
const fs = require('fs'); const fs = require('fs');
const content = fs.readFileSync(dirs.content + 'guide/forms.md', 'utf-8'); const content = fs.readFileSync(dirs.content + 'guide/forms.md', 'utf-8');
const result = translate(content); const result = translate(content);