-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathinvalid-html-test.ts
254 lines (236 loc) · 6.37 KB
/
invalid-html-test.ts
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import {
jitSuite,
preprocess,
RenderTest,
syntaxErrorFor,
test,
} from '@glimmer-workspace/integration-tests';
class CompileErrorTests extends RenderTest {
static suiteName = 'compile errors';
@test
'A helpful error message is provided for unclosed elements'() {
this.assert.throws(
() => {
preprocess('\n<div class="my-div" \n foo={{bar}}>\n<span>\n</span>\n', {
meta: { moduleName: 'test-module' },
});
},
syntaxErrorFor(
'Unclosed element `div`',
'<div class="my-div" \n foo={{bar}}>',
'test-module',
2,
0
)
);
this.assert.throws(
() => {
preprocess('\n<div class="my-div">\n<span>\n', {
meta: { moduleName: 'test-module' },
});
},
syntaxErrorFor('Unclosed element `span`', '<span>', 'test-module', 3, 0)
);
}
@test
'A helpful error message is provided for unmatched end tags'() {
this.assert.throws(
() => {
preprocess('</p>', { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor('Closing tag </p> without an open tag', '</p>', 'test-module', 1, 0)
);
this.assert.throws(
() => {
preprocess('<em>{{ foo }}</em> \n {{ bar }}\n</div>', {
meta: { moduleName: 'test-module' },
});
},
syntaxErrorFor('Closing tag </div> without an open tag', '</div>', 'test-module', 3, 0)
);
}
@test
'A helpful error message is provided for end tags for void elements'() {
this.assert.throws(
() => {
preprocess('<input></input>', { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor(
'<input> elements do not need end tags. You should remove it',
'</input>',
'test-module',
1,
7
)
);
this.assert.throws(
() => {
preprocess('<div>\n <input></input>\n</div>', { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor(
'<input> elements do not need end tags. You should remove it',
'</input>',
'test-module',
2,
9
)
);
this.assert.throws(
() => {
preprocess('\n\n</br>', { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor(
'<br> elements do not need end tags. You should remove it',
'</br>',
'test-module',
3,
0
)
);
}
@test
'A helpful error message is provided for end tags with attributes'() {
this.assert.throws(
() => {
preprocess('<div>\nSomething\n\n</div foo="bar">', { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor(
'Invalid end tag: closing tag must not have attributes',
'</div foo="bar"',
'test-module',
4,
0
)
);
}
@test
'A helpful error message is provided for mismatched start/end tags'() {
this.assert.throws(
() => {
preprocess('<div>\n<p>\nSomething\n\n</div>', { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor(
'Closing tag </div> did not match last open tag <p> (on line 2)',
'</div>',
'test-module',
5,
0
)
);
}
@test
'error line numbers include comment lines'() {
this.assert.throws(
() => {
preprocess('<div>\n<p>\n{{! some comment}}\n\n</div>', {
meta: { moduleName: 'test-module' },
});
},
syntaxErrorFor(
'Closing tag </div> did not match last open tag <p> (on line 2)',
'</div>',
'test-module',
5,
0
)
);
}
@test
'error line numbers include mustache only lines'() {
this.assert.throws(
() => {
preprocess('<div>\n<p>\n{{someProp}}\n\n</div>', { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor(
'Closing tag </div> did not match last open tag <p> (on line 2)',
'</div>',
'test-module',
5,
0
)
);
}
@test
'error line numbers include block lines'() {
this.assert.throws(
() => {
preprocess('<div>\n<p>\n{{#some-comment}}\n{{/some-comment}}\n</div>', {
meta: { moduleName: 'test-module' },
});
},
syntaxErrorFor(
'Closing tag </div> did not match last open tag <p> (on line 2)',
'</div>',
'test-module',
5,
0
)
);
}
@test
'error line numbers include whitespace control mustaches'() {
this.assert.throws(
() => {
preprocess('<div>\n<p>\n{{someProp~}}\n\n</div>{{some-comment}}', {
meta: { moduleName: 'test-module' },
});
},
syntaxErrorFor(
'Closing tag </div> did not match last open tag <p> (on line 2)',
'</div>',
'test-module',
5,
0
)
);
}
@test
'error line numbers include multiple mustache lines'() {
this.assert.throws(
() => {
preprocess('<div>\n<p>\n{{some-comment}}</div>{{some-comment}}', {
meta: { moduleName: 'test-module' },
});
},
syntaxErrorFor(
'Closing tag </div> did not match last open tag <p> (on line 2)',
'</div>',
'test-module',
3,
16
)
);
}
@test
'Unquoted attribute with expression throws an exception'() {
this.assert.throws(
() => preprocess('<img class=foo{{bar}}>', { meta: { moduleName: 'test-module' } }),
expectedError('class=foo{{bar}}', 1, 5)
);
this.assert.throws(
() => preprocess('<img class={{foo}}{{bar}}>', { meta: { moduleName: 'test-module' } }),
expectedError('class={{foo}}{{bar}}', 1, 5)
);
this.assert.throws(
() => preprocess('<img \nclass={{foo}}bar>', { meta: { moduleName: 'test-module' } }),
expectedError('class={{foo}}bar', 2, 0)
);
this.assert.throws(
() =>
preprocess('<div \nclass\n=\n{{foo}}&bar ></div>', {
meta: { moduleName: 'test-module' },
}),
expectedError('class\n=\n{{foo}}&bar', 2, 0)
);
function expectedError(code: string, line: number, column: number) {
return syntaxErrorFor(
`An unquoted attribute value must be a string or a mustache, preceded by whitespace or a '=' character, and followed by whitespace, a '>' character, or '/>'`,
code,
'test-module',
line,
column
);
}
}
}
jitSuite(CompileErrorTests);