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