const expect = require("chai").expect; const Parse = require("../lib/index"); const ASTtoMarkdown = require("../lib/compileASTtoMarkdown"); describe("Parser Checks", function () { it("Bold Test", function () { expect(Parse("**bold**")).to.eql([ { type: "bold", children: ["bold"], }, ]); }); it("Strikethrough Test", function () { expect(Parse("~~strikethrough~~")).to.eql([ { type: "strikethrough", children: ["strikethrough"], }, ]); }); it("Italics Test", function () { expect(Parse("_italics_")).to.eql([ { type: "italics", children: ["italics"], }, ]); }); it("Underline Test", function () { expect(Parse("==Underline==")).to.eql([ { type: "underline", children: ["Underline"], }, ]); }); it("url Test", function () { expect(Parse("[The Feathers](feathers.studio)")).to.eql([ { type: "url", children: ["The Feathers"], url: "feathers.studio", }, ]); }); 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 () { expect( Parse( "**Bold_Italics~~strikethrough==underline==strikethrough~~Italics_Bold**", ), ).to.eql([ { type: "bold", children: [ "Bold", { type: "italics", children: [ "Italics", { type: "strikethrough", children: [ "strikethrough", { type: "underline", children: ["underline"] }, "strikethrough", ], }, "Italics", ], }, "Bold", ], }, ]); }); it("AST -> Markdown -> AST", function () { const input = [ { type: "bold", children: ["Sunset"] }, { type: "text", children: [" is the time of day when our "] }, { type: "underline", children: ["sky meets the outer space solar winds"], }, { type: "text", children: [". There are "] }, { type: "italics", children: ["blue"] }, { type: "text", children: [", "] }, { type: "italics", children: ["pink"] }, { type: "text", children: [", and "] }, { type: "italics", children: ["purple"] }, { type: "text", children: [" swirls, spinning and twisting, like "], }, { type: "underline", children: ["clouds of balloons caught in a whirlwind"], }, { type: "text", children: [ ". The sun moves slowly to hide behind the line of horizon, while the moon races to take its place in prominence atop the night sky. People slow to a crawl, entranced, fully forgetting the deeds that must still be done. ", ], }, { type: "italics", children: [ { type: "underline", children: [ { type: "bold", children: [ "There is a coolness, a calmness, when the sun does set", ], }, ], }, ], }, { type: "text", children: ["."] }, ]; expect(Parse(ASTtoMarkdown(input))).to.deep.equal(input); }); });