-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.ts
50 lines (43 loc) · 1.29 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as commonmark from "commonmark";
import { readFileSync, readdirSync } from "fs";
import { Node } from "commonmark";
import { expect } from "chai";
import { commonmarkToString } from ".";
import { relative } from "path";
import * as glob from "glob";
var assert = require("assert");
function nodes(root: Node) {
let walker = root.walker();
let event = walker.next();
let nodes: any[] = [];
while (event) {
let curNodeA = event.node;
nodes = [
...nodes,
{
type: curNodeA.type,
literal: curNodeA.literal,
title: curNodeA.title,
info: curNodeA.info,
level: curNodeA.level,
listType: curNodeA.listType,
listDelimiter: curNodeA.listDelimiter
}
];
event = walker.next();
}
return nodes;
}
function testFile(path) {
let reader = new commonmark.Parser();
let parsed = reader.parse(readFileSync(path, "utf8")); // parsed is a 'Node' tree
let reparse = reader.parse(unescape(commonmarkToString(parsed)));
expect(nodes(reparse)).to.eql(nodes(parsed));
}
describe("#commonmarkToString()", function() {
for (const file of glob.sync("./md-tests/*/specification/**/*.md")) {
it(`should produce an markdown document which has a matching AST to ${file}`, function() {
testFile(file);
});
}
});