forked from Silverquark/dance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.test.ts
34 lines (27 loc) · 1.32 KB
/
utils.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
import * as assert from "assert";
import * as fs from "fs";
import * as vscode from "vscode";
import { execAll } from "./build-utils";
import { ExpectedDocument, resolve } from "./utils";
function stringifySelection(selection: vscode.Selection) {
return `${selection.anchor.line}:${selection.anchor.character} → `
+ `${selection.active.line}:${selection.active.character}`;
}
suite("Testing utilities tests", function () {
suite("ExpectedDocument#parse", function () {
const readmePath = resolve("test/README.md"),
readmeContents = fs.readFileSync(readmePath, "utf-8"),
re = /^(\d+)\..*?\[(.+?)\].*?:\n( +)```\n([\s\S]+?)\n\3```/gm;
for (const [_, n, selectionsString, indent, indentedCode] of execAll(re, readmeContents)) {
const expectedSelections = selectionsString.split(", "),
code = indentedCode.replace(new RegExp("^" + indent, "gm"), "");
test(`example ${n}`, function () {
const document = ExpectedDocument.parse(code),
actualSelections = document.selections.map(stringifySelection);
const actual = actualSelections.map((s, i) => `selection #${i}: ${s}`).join("\n"),
expected = expectedSelections.map((s, i) => `selection #${i}: ${s}`).join("\n");
assert.strictEqual(actual, expected);
});
}
});
});