Browse Source

Test cases added for compileHTML

develop
arunkumar 4 years ago
parent
commit
a7380470be
  1. 14
      test/compileHTML.test.js
  2. 74
      test/compileText.test.js
  3. 17
      test/index.test.js

14
test/compileHTML.test.js

@ -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");
// });
// });

74
test/compileText.test.js

@ -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",
);
});
});

17
test/index.test.js

@ -56,19 +56,16 @@ describe("Parser Checks", function () {
]); ]);
}); });
it("Bold text inside the Bold text", function () {
expect(Parse("**Outer**InnerBold**Bold**")).to.eql([
{ type: "bold", children: ["Outer"] },
{ type: "text", children: ["InnerBold"] },
{ type: "bold", children: ["Bold"] },
]);
});
it("Nested Check 1", function () { it("Nested Check 1", function () {
expect( expect(
Parse( Parse(
"**Bold_Italics~~strikethrough==underline==strikethrough~~Italics_Bold**", "**Bold_Italics~~strikethrough==underline==strikethrough~~Italics_Bold**",
), ),[
{
type: 'underline',
children: [ 'The', { type: 'bold', children: [ 'KING' ] }, 'Maker' ]
}
]
).to.eql([ ).to.eql([
{ {
type: "bold", type: "bold",
@ -94,6 +91,4 @@ describe("Parser Checks", function () {
}, },
]); ]);
}); });
it("");
}); });

Loading…
Cancel
Save