forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatLocation.unittest.js
96 lines (94 loc) · 1.33 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use strict";
const should = require("should");
const formatLocation = require("../lib/formatLocation");
describe("formatLocation", () => {
const testCases = [{
name: "undefined",
loc: undefined,
result: ""
}, {
name: "null",
loc: null,
result: ""
}, {
name: "string",
loc: "str",
result: "str"
}, {
name: "number",
loc: 12,
result: "12"
}, {
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: "start-end string",
loc: {
start: "start",
end: "end"
},
result: "start-end"
}, {
name: "start-end number",
loc: {
start: 9,
end: 7
},
result: "9-7"
}, {
name: "line",
loc: {
start: {
line: 10
},
end: {
index: 20
}
},
result: "10:?-+20"
}, {
name: "line",
loc: {
start: null,
end: /f/
},
result: ""
}];
testCases.forEach(testCase => {
it(`should format location correctly for ${testCase.name}`, () => {
formatLocation(testCase.loc).should.be.eql(testCase.result);
});
});
});