-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patherrorsUtils.test.ts
More file actions
131 lines (124 loc) · 4.03 KB
/
Copy patherrorsUtils.test.ts
File metadata and controls
131 lines (124 loc) · 4.03 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import fs from "fs";
import path from "path";
import { compileModule } from "../compiler";
import { printLoc } from "../errorUtils";
const DIR = path.join(__dirname, "../../fixtures/errors");
const testCases = fs.readdirSync(DIR);
testCases.forEach((filename: string) => {
const testFunc = filename.startsWith("only.") ? test.only : test;
const testName = filename.replace(/^only\./, "");
testFunc(`${testName}`, async () => {
const eel = fs.readFileSync(path.join(DIR, filename), { encoding: "utf8" });
let compilerError = null;
try {
await compileModule({
pools: { main: new Set() },
functions: { run: { pool: "main", code: eel } },
});
} catch (e) {
compilerError = e;
}
// TODO: Assert that error is a user or compiler error
expect(compilerError).not.toBe(null);
expect(compilerError.message).toMatchSnapshot();
// We prepend a newline here so that the error starts on a newline rather
// than a '"' in the snapshot and our underline alinment is easy to see.
expect("\n" + compilerError.sourceContext).toMatchSnapshot();
});
});
describe("printLoc", () => {
test("One line", () => {
const frame = printLoc(
{ first_line: 1, first_column: 6, last_line: 1, last_column: 11 },
"Hello there this is a string"
);
expect("\n" + frame + "\n").toMatchInlineSnapshot(`
"
> 1 | Hello there this is a string
| ^^^^^
"
`);
});
test("One line within multiple lines", () => {
const frame = printLoc(
{ first_line: 4, first_column: 6, last_line: 4, last_column: 11 },
[
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
].join("\n")
);
expect("\n" + frame + "\n").toMatchInlineSnapshot(`
"
3 | Hello there this is a string
> 4 | Hello there this is a string
| ^^^^^
5 | Hello there this is a string
"
`);
});
test("One line within multiple lines + 2 lines of context", () => {
const frame = printLoc(
{ first_line: 4, first_column: 6, last_line: 4, last_column: 11 },
[
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
].join("\n"),
2
);
expect("\n" + frame + "\n").toMatchInlineSnapshot(`
"
2 | Hello there this is a string
3 | Hello there this is a string
> 4 | Hello there this is a string
| ^^^^^
5 | Hello there this is a string
6 | Hello there this is a string
"
`);
});
test("Multiple lines", () => {
const frame = printLoc(
{ first_line: 1, first_column: 6, last_line: 2, last_column: 11 },
"Hello there this is a string\nHello there this is a string"
);
expect("\n" + frame + "\n").toMatchInlineSnapshot(`
"
> 1 | Hello there this is a string
> 2 | Hello there this is a string
"
`);
});
test("Multiple lines within multiple lines", () => {
const frame = printLoc(
{ first_line: 3, first_column: 6, last_line: 5, last_column: 11 },
[
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
"Hello there this is a string",
].join("\n")
);
expect("\n" + frame + "\n").toMatchInlineSnapshot(`
"
2 | Hello there this is a string
> 3 | Hello there this is a string
> 4 | Hello there this is a string
> 5 | Hello there this is a string
6 | Hello there this is a string
"
`);
});
});