forked from smooth80/webpack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformatLocation.unittest.js
81 lines (79 loc) · 1.09 KB
/
formatLocation.unittest.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
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
"use strict";
const formatLocation = require("../lib/formatLocation");
describe("formatLocation", () => {
const testCases = [
{
name: "undefined",
loc: undefined,
result: ""
},
{
name: "null",
loc: null,
result: ""
},
{
name: "line-column",
loc: {
start: {
line: 1,
column: 2
},
end: {
line: 3,
column: 4
}
},
result: "1:2-3:4"
},
{
name: "line-column (same line)",
loc: {
start: {
line: 1,
column: 2
},
end: {
line: 1,
column: 4
}
},
result: "1:2-4"
},
{
name: "line-column (start only)",
loc: {
start: {
line: 5,
column: 6
}
},
result: "5:6"
},
{
name: "line",
loc: {
start: {
line: 10
},
end: {
line: 20
}
},
result: "10-20"
},
{
name: "line",
loc: {
start: null,
end: /f/
},
result: ""
}
];
testCases.forEach(testCase => {
it(`should format location correctly for ${testCase.name}`, () => {
expect(formatLocation(testCase.loc)).toEqual(testCase.result);
});
});
});