From 9b23914f403aa450aade26be4b244db3f1332a35 Mon Sep 17 00:00:00 2001 From: arunkumar Date: Thu, 25 Feb 2021 16:48:33 +0530 Subject: [PATCH] more test cases added. --- test/AST_To_Markdown.test.js | 26 +++++++++++++++++------ test/index.test.js | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/test/AST_To_Markdown.test.js b/test/AST_To_Markdown.test.js index 114f2e9..94ea869 100644 --- a/test/AST_To_Markdown.test.js +++ b/test/AST_To_Markdown.test.js @@ -1,10 +1,11 @@ const expect = require("chai").expect; -const Compile = require("../lib/compileASTtoMarkdown"); +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(Compile(input)).to.equal("**bold**"); + expect(ASTtoMarkdown(input)).to.equal("**bold**"); }); it("sample ast - 2", function () { @@ -13,7 +14,7 @@ describe("Compiling AST to Markdown", function () { { type: "text", children: ["simple"] }, { type: "italics", children: ["AST"] }, ]; - expect(Compile(input)).to.equal("**my**simple_AST_"); + expect(ASTtoMarkdown(input)).to.equal("**my**simple_AST_"); }); it("sentence ast", function () { @@ -28,7 +29,7 @@ describe("Compiling AST to Markdown", function () { }, { type: "text", children: ["."] }, ]; - expect(Compile(input)).to.equal( + expect(ASTtoMarkdown(input)).to.equal( "**Arunkumar** is the ==Best Boy== not the _~~Worst Boy~~_.", ); }); @@ -37,7 +38,7 @@ describe("Compiling AST to Markdown", function () { const input = [ { type: "url", children: ["The Feathers"], url: "feathers.studio" }, ]; - expect(Compile(input)).to.equal("[The Feathers](feathers.studio)"); + expect(ASTtoMarkdown(input)).to.equal("[The Feathers](feathers.studio)"); }); it("Nested ast", function () { @@ -65,8 +66,21 @@ describe("Compiling AST to Markdown", function () { ], }, ]; - expect(Compile(input)).to.equal( + 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); + }); }); diff --git a/test/index.test.js b/test/index.test.js index dfde6f1..68cf861 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,5 +1,6 @@ const expect = require("chai").expect; const Parse = require("../lib/index"); +const ASTtoMarkdown = require("../lib/compileASTtoMarkdown"); describe("Parser Checks", function () { it("Bold Test", function () { @@ -86,4 +87,53 @@ describe("Parser Checks", function () { }, ]); }); + + 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); + }); });