const expect = require("chai").expect; const ASTtoMarkdown = require("../lib/compileASTtoMarkdown"); const MarkdownToAST = require("../lib/index"); describe("Compiling AST to Markdown", function () { it("sample ast - 1", function () { const input = [{ type: "bold", children: ["bold"] }]; expect(ASTtoMarkdown(input)).to.equal("**bold**"); }); it("sample ast - 2", function () { const input = [ { type: "bold", children: ["my"] }, { type: "text", children: ["simple"] }, { type: "italics", children: ["AST"] }, ]; expect(ASTtoMarkdown(input)).to.equal("**my**simple_AST_"); }); it("sentence ast", function () { const input = [ { type: "bold", children: ["Arunkumar"] }, { type: "text", children: [" is the "] }, { type: "underline", children: ["Best Boy"] }, { type: "text", children: [" not the "] }, { type: "italics", children: [{ type: "strikethrough", children: ["Worst Boy"] }], }, { type: "text", children: ["."] }, ]; expect(ASTtoMarkdown(input)).to.equal( "**Arunkumar** is the ==Best Boy== not the _~~Worst Boy~~_.", ); }); it("link ast", function () { const input = [ { type: "url", children: ["The Feathers"], url: "feathers.studio" }, ]; expect(ASTtoMarkdown(input)).to.equal("[The Feathers](feathers.studio)"); }); it("Nested ast", function () { const input = [ { type: "bold", children: [ "Bold", { type: "italics", children: [ "Italics", { type: "strikethrough", children: [ "Strikethrough", { type: "underline", children: ["Underline"] }, "Strikethrough", ], }, "Italics", ], }, "Bold", ], }, ]; expect(ASTtoMarkdown(input)).to.equal( "**Bold_Italics~~Strikethrough==Underline==Strikethrough~~Italics_Bold**", ); }); it("Markdown -> AST -> Markdown (1)", function () { const input = "_Checking about the **Latest Trends** in **Development World** makes ourselves ==Progressive==_, [check @ here](https://dev.to). _Moreover, **Typo** is the ==Time killing Error== in Development. So **Avoid ~~typos~~**._"; expect(ASTtoMarkdown(MarkdownToAST(input))).to.equal(input); }); it("Markdown -> AST -> Markdown (2)", function () { const input = "**Sunset** is the time of day when our ==sky meets the outer space solar winds==. There are _blue_, _pink_, and _purple_ swirls, spinning and twisting, like ==clouds of balloons caught in a whirlwind==. 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. _==**There is a coolness, a calmness, when the sun does set**==_."; expect(ASTtoMarkdown(MarkdownToAST(input))).to.equal(input); }); });