You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							85 lines
						
					
					
						
							2.2 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							85 lines
						
					
					
						
							2.2 KiB
						
					
					
				| const expect = require("chai").expect; | |
| const CompileHTML = require("../lib/compileHTML"); | |
| 
 | |
| describe("Compile AST to HTML String", function () { | |
| 	it("Simple AST", function () { | |
| 		const ast = [ | |
| 			{ type: "bold", children: ["my"] }, | |
| 			{ type: "text", children: ["simple"] }, | |
| 			{ type: "italics", children: ["AST"] }, | |
| 		]; | |
| 		const expectedOutput = | |
| 			'<p><span class="bold">my</span><span class="text">simple</span><span class="italics">AST</span></p>'; | |
| 		expect(CompileHTML(ast)).to.eql(expectedOutput); | |
| 	}); | |
| 
 | |
| 	it("Nested AST", function () { | |
| 		const ast = [ | |
| 			{ | |
| 				type: "bold", | |
| 				children: [ | |
| 					"Bold", | |
| 					{ | |
| 						type: "italics", | |
| 						children: [ | |
| 							"Italics", | |
| 							{ | |
| 								type: "strikethrough", | |
| 								children: [ | |
| 									"strikethrough", | |
| 									{ type: "underline", children: ["underline"] }, | |
| 									"strikethrough", | |
| 								], | |
| 							}, | |
| 							"Italics", | |
| 						], | |
| 					}, | |
| 					"Bold", | |
| 				], | |
| 			}, | |
| 		]; | |
| 		const expectedOutput = | |
| 			'<p><span class="bold">Bold<span class="italics">Italics<span class="strikethrough">strikethrough<span class="underline">underline</span>strikethrough</span>Italics</span>Bold</span></p>'; | |
| 		expect(CompileHTML(ast)).to.eql(expectedOutput); | |
| 	}); | |
| 
 | |
| 	it("Link AST", function () { | |
| 		const ast = [ | |
| 			{ type: "url", children: ["The Feathers"], url: "feathers.studio" }, | |
| 		]; | |
| 		const expectedOutput = | |
| 			'<p><a href="feathers.studio" class="url">The Feathers</a></p>'; | |
| 		expect(CompileHTML(ast)).to.eql(expectedOutput); | |
| 	}); | |
| 
 | |
| 	it("Formatted Link AST - 1", function () { | |
| 		const ast = [ | |
| 			{ | |
| 				type: "url", | |
| 				children: [{ type: "bold", children: ["The Feathers"] }], | |
| 				url: "feathers.studio", | |
| 			}, | |
| 		]; | |
| 		const expectedOutput = | |
| 			'<p><a href="feathers.studio" class="url"><span class="bold">The Feathers</span></a></p>'; | |
| 		expect(CompileHTML(ast)).to.eql(expectedOutput); | |
| 	}); | |
| 
 | |
| 	it("Formatted Link AST - 2", function () { | |
| 		const ast = [ | |
| 			{ | |
| 				type: "url", | |
| 				children: [ | |
| 					{ | |
| 						type: "bold", | |
| 						children: ["The ", { type: "underline", children: ["Feathers"] }], | |
| 					}, | |
| 				], | |
| 				url: "feathers.studio", | |
| 			}, | |
| 		]; | |
| 		const expectedOutput = | |
| 			'<p><a href="feathers.studio" class="url"><span class="bold">The <span class="underline">Feathers</span></span></a></p>'; | |
| 		expect(CompileHTML(ast)).to.eql(expectedOutput); | |
| 	}); | |
| });
 | |
| 
 |