-
Notifications
You must be signed in to change notification settings - Fork 8
/
codePositionToIndex.test.mjs
81 lines (71 loc) · 1.99 KB
/
codePositionToIndex.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
import { strictEqual, throws } from "assert";
import CodePosition from "./CodePosition.mjs";
import codePositionToIndex from "./codePositionToIndex.mjs";
export default (tests) => {
tests.add(
"`codePositionToIndex` with argument 1 `codePosition` not a `CodePosition` instance.",
() => {
throws(() => {
codePositionToIndex(true);
}, new TypeError("Argument 1 `codePosition` must be a `CodePosition` instance."));
}
);
tests.add(
"`codePositionToIndex` with argument 2 `code` not a string.",
() => {
throws(() => {
codePositionToIndex(new CodePosition(1, 1), true);
}, new TypeError("Argument 2 `code` must be a string."));
}
);
tests.add(
"`codePositionToIndex` with argument 2 `code` not a populated string.",
() => {
throws(() => {
codePositionToIndex(new CodePosition(1, 1), "");
}, new TypeError("Argument 2 `code` must be a populated string."));
}
);
tests.add("`codePositionToIndex` with singleline code, start.", () => {
strictEqual(codePositionToIndex(new CodePosition(1, 1), "abc"), 0);
});
tests.add("`codePositionToIndex` with singleline code, between.", () => {
strictEqual(codePositionToIndex(new CodePosition(1, 2), "abc"), 1);
});
tests.add("`codePositionToIndex` with singleline code, end.", () => {
strictEqual(codePositionToIndex(new CodePosition(1, 3), "abc"), 2);
});
tests.add("`codePositionToIndex` with multiline code, start.", () => {
strictEqual(
codePositionToIndex(
new CodePosition(1, 1),
`abc
def
hij`
),
0
);
});
tests.add("`codePositionToIndex` with multiline code, between.", () => {
strictEqual(
codePositionToIndex(
new CodePosition(2, 2),
`abc
def
hij`
),
5
);
});
tests.add("`codePositionToIndex` with multiline code, end.", () => {
strictEqual(
codePositionToIndex(
new CodePosition(3, 3),
`abc
def
hij`
),
10
);
});
};