arunkumar
4 years ago
3 changed files with 94 additions and 11 deletions
@ -0,0 +1,14 @@ |
|||||
|
const expect = require("chai").expect; |
||||
|
const CompileText = require("../lib/compileText"); |
||||
|
|
||||
|
// describe("Compile AST to HTML String", function () {
|
||||
|
// it("Simple AST", function () {
|
||||
|
// const ast = [
|
||||
|
// { type: 'bold', children: [ 'arun' ] },
|
||||
|
// { type: 'text', children: [ 'bold' ] },
|
||||
|
// { type: 'text', children: [ 'son' ] }
|
||||
|
// ];
|
||||
|
// const expectedOutput =
|
||||
|
// expect(CompileText(ast)).to.eql("TheKINGMaker");
|
||||
|
// });
|
||||
|
// });
|
@ -0,0 +1,74 @@ |
|||||
|
const expect = require("chai").expect; |
||||
|
const CompileText = require("../lib/compileText"); |
||||
|
|
||||
|
describe("Compile AST to Raw String", function () { |
||||
|
it("Simple AST", function () { |
||||
|
const ast = [ |
||||
|
{ |
||||
|
type: "underline", |
||||
|
children: ["The", { type: "bold", children: ["KING"] }, "Maker"], |
||||
|
}, |
||||
|
]; |
||||
|
expect(CompileText(ast)).to.eql("TheKINGMaker"); |
||||
|
}); |
||||
|
|
||||
|
it("Link AST", function () { |
||||
|
const ast = [ |
||||
|
{ type: "url", children: ["The Feathers"], url: "feathers.studio" }, |
||||
|
]; |
||||
|
expect(CompileText(ast)).to.eql("The Feathers feathers.studio"); |
||||
|
}); |
||||
|
|
||||
|
it("Formatted Link AST", function () { |
||||
|
const ast = [ |
||||
|
{ |
||||
|
type: "url", |
||||
|
children: [ |
||||
|
{ |
||||
|
type: "bold", |
||||
|
children: ["The ", { type: "underline", children: ["Feathers"] }], |
||||
|
}, |
||||
|
], |
||||
|
url: "feathers.studio", |
||||
|
}, |
||||
|
]; |
||||
|
expect(CompileText(ast)).to.eql("The Feathers feathers.studio"); |
||||
|
}); |
||||
|
|
||||
|
// it("Wrongly Formatted Link AST", function () {
|
||||
|
// const ast = [
|
||||
|
// { type: "bold", children: ["[The ==Feathers==](feathers.studio)"] },
|
||||
|
// ];
|
||||
|
// expect(CompileText(ast)).to.eql("[The ==Feathers==](feathers.studio)");
|
||||
|
// });
|
||||
|
|
||||
|
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", |
||||
|
], |
||||
|
}, |
||||
|
]; |
||||
|
expect(CompileText(ast)).to.equal( |
||||
|
"BoldItalicsstrikethroughunderlinestrikethroughItalicsBold", |
||||
|
); |
||||
|
}); |
||||
|
}); |
Loading…
Reference in new issue