Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ca6307

Browse files
committed
Make basic test
1 parent f02a3e3 commit 0ca6307

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/index.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { expect } from "chai";
2+
import defaultParser, {Node, TextNode} from "../src/index";
3+
4+
describe("bbcode-ast tests", () => {
5+
it("Should parse tag-free text", () => {
6+
const parsed = defaultParser.parse("Hello world!")
7+
expect(parsed.children.length).to.equal(1);
8+
expect(parsed.children[0].name).to.equal("TextNode");
9+
expect((parsed.children[0] as TextNode).text).to.equal("Hello world!");
10+
expect(parsed.toString()).to.equal("Hello world!");
11+
})
12+
13+
it("Should parse simple tag", () => {
14+
const parsed = defaultParser.parse("[b]Hello world![/b]")
15+
expect(parsed.children.length).to.equal(1);
16+
expect(parsed.children[0].name).to.equal("b");
17+
expect((parsed.children[0] as Node).children.length).to.equal(1);
18+
expect((parsed.children[0] as Node).children[0].name).to.equal("TextNode");
19+
expect(((parsed.children[0] as Node).children[0] as TextNode).text).to.equal("Hello world!");
20+
expect(parsed.toString()).to.equal("[b]Hello world![/b]");
21+
})
22+
})

0 commit comments

Comments
 (0)