| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  | import { expect } from 'chai'; | 
					
						
							| 
									
										
										
										
											2018-03-01 22:35:54 +08:00
										 |  |  | import { dirs } from './dirs'; | 
					
						
							| 
									
										
										
										
											2018-03-06 17:08:10 +08:00
										 |  |  | import { gatherTranslations, listMarkdownFiles, splitAndTrim, } from './extractor'; | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 08:08:39 +08:00
										 |  |  | describe('从对照翻译文件中采集生成字典', () => { | 
					
						
							|  |  |  |   it('空字符串应该拆分成空数组', function () { | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  |     expect(splitAndTrim()).eql([]); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-03-02 08:08:39 +08:00
										 |  |  |   it('按照双行(忽略空格)拆分对照文本', function () { | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  |     const result = splitAndTrim(`a
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     b | 
					
						
							|  |  |  |     c | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     d`);
 | 
					
						
							|  |  |  |     expect(result[1]).eql(`b
 | 
					
						
							|  |  |  |     c`);
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 08:08:39 +08:00
										 |  |  |   it('生成原文和译文的对照表', () => { | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  |     const result = gatherTranslations(`
 | 
					
						
							|  |  |  |     a | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     一 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     b | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  |     expect(result).eql([{original: 'a', translation: '一'}]); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 11:45:03 +08:00
										 |  |  |   it('处理 html 标签包裹的翻译文本', () => { | 
					
						
							|  |  |  |     const result = gatherTranslations(`
 | 
					
						
							|  |  |  |     <p> | 
					
						
							|  |  |  |     a | 
					
						
							|  |  |  |     </p> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <p> | 
					
						
							|  |  |  |     一 | 
					
						
							|  |  |  | </p> | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  |     expect(result).eql([{original: 'a', translation: '一'}]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-07 09:08:44 +08:00
										 |  |  |   it('处理 a 标签包裹的单行翻译文本', () => { | 
					
						
							|  |  |  |     const result = gatherTranslations(`
 | 
					
						
							|  |  |  |     <a>a</a> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <a>一</a> | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  |     expect(result).eql([{original: '<a>a</a>', translation: '<a>一</a>'}]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 11:01:57 +08:00
										 |  |  |   it('从真实的文件中采集(测试)', function () { | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  |     const fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2018-03-07 08:48:31 +08:00
										 |  |  |     const content = fs.readFileSync(dirs.content + 'guide/forms.md', 'utf-8'); | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  |     const result = gatherTranslations(content); | 
					
						
							| 
									
										
										
										
											2018-03-07 08:48:31 +08:00
										 |  |  |     expect(result[0]).eql({original: '# Forms', translation: '# 表单'}); | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 08:08:39 +08:00
										 |  |  |   it('递归查找所有 markdown 文件', function () { | 
					
						
							| 
									
										
										
										
											2018-03-01 22:35:54 +08:00
										 |  |  |     expect(listMarkdownFiles(dirs.content).length).greaterThan(10); | 
					
						
							| 
									
										
										
										
											2018-03-01 14:07:51 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | }); |