-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCodeLocation.test.mjs
87 lines (72 loc) · 2.35 KB
/
CodeLocation.test.mjs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { deepStrictEqual, throws } from "assert";
import CodeLocation from "./CodeLocation.mjs";
import CodePosition from "./CodePosition.mjs";
export default (tests) => {
tests.add(
"`CodeLocation` with argument 1 `start` not a `CodePosition` instance.",
() => {
throws(() => {
new CodeLocation(true);
}, new TypeError("Argument 1 `start` must be a `CodePosition` instance."));
}
);
tests.add(
"`CodeLocation` with argument 2 `end` not a `CodePosition` instance.",
() => {
throws(() => {
new CodeLocation(new CodePosition(1, 1), true);
}, new TypeError("Argument 2 `end` must be a `CodePosition` instance."));
}
);
tests.add("`CodeLocation` with argument 2 `end` an undefined value.", () => {
let end;
throws(() => {
new CodeLocation(new CodePosition(1, 1), end);
}, new TypeError("Argument 2 `end` must be a `CodePosition` instance."));
});
tests.add(
"`CodeLocation` with argument 2 `end` not at or beyond the start position.",
() => {
throws(() => {
new CodeLocation(new CodePosition(2, 1), new CodePosition(1, 1));
}, new TypeError("Argument 2 `end` must be a code position at or beyond the start code position."));
}
);
tests.add("`CodeLocation` without an end position.", () => {
const start = new CodePosition(1, 1);
deepStrictEqual(Object.entries(new CodeLocation(start)), [
["start", start],
]);
});
tests.add("`CodeLocation` with an end position, at start position.", () => {
const start = new CodePosition(1, 1);
const end = new CodePosition(1, 1);
deepStrictEqual(Object.entries(new CodeLocation(start, end)), [
["start", start],
["end", end],
]);
});
tests.add(
"`CodeLocation` with an end position, beyond start position.",
() => {
const start = new CodePosition(1, 1);
const end = new CodePosition(2, 1);
deepStrictEqual(Object.entries(new CodeLocation(start, end)), [
["start", start],
["end", end],
]);
}
);
tests.add("`CodeLocation` instance properties are frozen.", () => {
const codeLocation = new CodeLocation(
new CodePosition(1, 1),
new CodePosition(2, 1)
);
throws(() => {
codeLocation.start = true;
}, TypeError);
throws(() => {
codeLocation.end = true;
}, TypeError);
});
};