Browse Source

more test cases added.

develop
arunkumar 4 years ago
parent
commit
9b23914f40
  1. 26
      test/AST_To_Markdown.test.js
  2. 50
      test/index.test.js

26
test/AST_To_Markdown.test.js

@ -1,10 +1,11 @@
const expect = require("chai").expect; 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 () { describe("Compiling AST to Markdown", function () {
it("sample ast - 1", function () { it("sample ast - 1", function () {
const input = [{ type: "bold", children: ["bold"] }]; const input = [{ type: "bold", children: ["bold"] }];
expect(Compile(input)).to.equal("**bold**"); expect(ASTtoMarkdown(input)).to.equal("**bold**");
}); });
it("sample ast - 2", function () { it("sample ast - 2", function () {
@ -13,7 +14,7 @@ describe("Compiling AST to Markdown", function () {
{ type: "text", children: ["simple"] }, { type: "text", children: ["simple"] },
{ type: "italics", children: ["AST"] }, { type: "italics", children: ["AST"] },
]; ];
expect(Compile(input)).to.equal("**my**simple_AST_"); expect(ASTtoMarkdown(input)).to.equal("**my**simple_AST_");
}); });
it("sentence ast", function () { it("sentence ast", function () {
@ -28,7 +29,7 @@ describe("Compiling AST to Markdown", function () {
}, },
{ type: "text", children: ["."] }, { type: "text", children: ["."] },
]; ];
expect(Compile(input)).to.equal( expect(ASTtoMarkdown(input)).to.equal(
"**Arunkumar** is the ==Best Boy== not the _~~Worst Boy~~_.", "**Arunkumar** is the ==Best Boy== not the _~~Worst Boy~~_.",
); );
}); });
@ -37,7 +38,7 @@ describe("Compiling AST to Markdown", function () {
const input = [ const input = [
{ type: "url", children: ["The Feathers"], url: "feathers.studio" }, { 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 () { 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**", "**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);
});
}); });

50
test/index.test.js

@ -1,5 +1,6 @@
const expect = require("chai").expect; const expect = require("chai").expect;
const Parse = require("../lib/index"); const Parse = require("../lib/index");
const ASTtoMarkdown = require("../lib/compileASTtoMarkdown");
describe("Parser Checks", function () { describe("Parser Checks", function () {
it("Bold Test", 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);
});
}); });

Loading…
Cancel
Save