-
Notifications
You must be signed in to change notification settings - Fork 8
/
CodePosition.test.mjs
48 lines (39 loc) · 1.29 KB
/
CodePosition.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
import { deepStrictEqual, throws } from "assert";
import CodePosition from "./CodePosition.mjs";
export default (tests) => {
tests.add("`CodePosition` with argument 1 `line` not a number.", () => {
throws(() => {
new CodePosition(true);
}, new TypeError("Argument 1 `line` must be a number."));
});
tests.add("`CodePosition` with argument 1 `line` < 1.", () => {
throws(() => {
new CodePosition(0);
}, new RangeError("Argument 1 `line` must be >= 1."));
});
tests.add("`CodePosition` with argument 2 `column` not a number.", () => {
throws(() => {
new CodePosition(1, true);
}, new TypeError("Argument 2 `column` must be a number."));
});
tests.add("`CodePosition` with argument 2 `column` < 1.", () => {
throws(() => {
new CodePosition(1, 0);
}, new RangeError("Argument 2 `column` must be >= 1."));
});
tests.add("`CodePosition` with arguments valid.", () => {
deepStrictEqual(Object.entries(new CodePosition(2, 3)), [
["line", 2],
["column", 3],
]);
});
tests.add("`CodePosition` instance properties are frozen.", () => {
const codePosition = new CodePosition(1, 1);
throws(() => {
codePosition.line = 2;
}, TypeError);
throws(() => {
codePosition.column = 2;
}, TypeError);
});
};