/
location.js
43 lines (36 loc) 路 1.07 KB
/
location.js
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
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;
describeSkipPublish("getLineInfo", () => {
let getLineInfo;
beforeAll(async () => {
({ getLineInfo } = await import("../../../lib/util/location.js"));
});
const input = "a\nb\nc\nd\ne\nf\ng\nh\ni";
it("reports correct position", () => {
expect(getLineInfo(input, 7)).toEqual({
column: 1,
line: 4,
});
});
it("reports correct position for first line", () => {
expect(getLineInfo(input, 0)).toEqual({
column: 0,
line: 1,
});
});
const inputArray = ["a", "b", "c", "d", "e", "f", "g", "h", "i"];
const singleCharLineEndings = ["\n", "\r", "\u2028", "\u2029"];
singleCharLineEndings.forEach(ending => {
it(`supports ${escape(ending)} line ending`, () => {
expect(getLineInfo(inputArray.join(ending), 7)).toEqual({
column: 1,
line: 4,
});
});
});
it(`supports ${escape("\r\n")} line ending`, () => {
expect(getLineInfo(inputArray.join("\r\n"), 7)).toEqual({
column: 1,
line: 3,
});
});
});