| 
									
										
										
										
											2018-08-27 02:01:18 +02:00
										 |  |  | import { tap, expect } from '@pushrocks/tapbundle'; | 
					
						
							| 
									
										
										
										
											2016-11-13 23:11:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 02:01:18 +02:00
										 |  |  | import * as smartfm from '../ts/index'; | 
					
						
							| 
									
										
										
										
											2016-11-13 23:11:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 02:01:18 +02:00
										 |  |  | let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' }); | 
					
						
							| 
									
										
										
										
											2017-05-27 23:02:51 +02:00
										 |  |  | tap.test('.parse()', async () => { | 
					
						
							|  |  |  |   let testString = `---
 | 
					
						
							| 
									
										
										
										
											2016-11-13 23:11:49 +01:00
										 |  |  | testKey: testValue | 
					
						
							|  |  |  | testKey2: testValue2 | 
					
						
							|  |  |  | --- | 
					
						
							| 
									
										
										
										
											2017-05-27 23:02:51 +02:00
										 |  |  | # some markdown | 
					
						
							| 
									
										
										
										
											2018-08-27 02:01:18 +02:00
										 |  |  | `;
 | 
					
						
							|  |  |  |   let parsedString = testSmartfm.parse(testString); | 
					
						
							|  |  |  |   expect(parsedString.data).to.have.property('testKey', 'testValue'); | 
					
						
							|  |  |  |   expect(parsedString.data).to.have.property('testKey2', 'testValue2'); | 
					
						
							|  |  |  |   expect(parsedString.orig.toString()).to.equal(testString); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2019-09-04 14:13:42 +02:00
										 |  |  | tap.test('should stringify data', async () => { | 
					
						
							| 
									
										
										
										
											2018-08-27 02:01:18 +02:00
										 |  |  |   let testStringPure = `# some markdown heading\nsome first row`; | 
					
						
							|  |  |  |   let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' }); | 
					
						
							|  |  |  |   let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n'; | 
					
						
							|  |  |  |   expect(resultString).to.equal(testStringCombined); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-05-27 23:02:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-04 14:13:42 +02:00
										 |  |  | tap.test('should parse a normal frontmatter file', async () => { | 
					
						
							| 
									
										
										
										
											2019-09-04 15:45:18 +02:00
										 |  |  |   const normalFile = `---
 | 
					
						
							|  |  |  | heythere: awesome | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | really  | 
					
						
							|  |  |  | `;
 | 
					
						
							|  |  |  |   let result = testSmartfm.parse(normalFile); | 
					
						
							|  |  |  |   expect(result.data.heythere).to.equal('awesome') | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tap.test('should parse a commented out frontmatter file', async () => { | 
					
						
							|  |  |  |   const commentedFile = `# ---
 | 
					
						
							|  |  |  | # heythere: awesome | 
					
						
							|  |  |  | # --- | 
					
						
							|  |  |  | really  | 
					
						
							|  |  |  | `;
 | 
					
						
							|  |  |  |   let result = testSmartfm.parseFromComments('# ', commentedFile); | 
					
						
							|  |  |  |   console.log(result); | 
					
						
							| 
									
										
										
										
											2019-09-04 14:13:42 +02:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 02:01:18 +02:00
										 |  |  | tap.start(); |