@@ -64,6 +64,46 @@ void main() {
64
64
process, errorId, "Missing mandatory field Importer.importer" );
65
65
await process.shouldExit (76 );
66
66
});
67
+
68
+ group ("for an importer with nonCanonicalScheme set:" , () {
69
+ test ("path" , () async {
70
+ process.send (compileString ("a {b: c}" , importers: [
71
+ InboundMessage_CompileRequest_Importer (
72
+ path: "somewhere" , nonCanonicalScheme: ["u" ])
73
+ ]));
74
+ await expectParamsError (
75
+ process,
76
+ errorId,
77
+ "Importer.non_canonical_scheme may only be set along with "
78
+ "Importer.importer.importer_id" );
79
+ await process.shouldExit (76 );
80
+ });
81
+
82
+ test ("file importer" , () async {
83
+ process.send (compileString ("a {b: c}" , importers: [
84
+ InboundMessage_CompileRequest_Importer (
85
+ fileImporterId: 1 , nonCanonicalScheme: ["u" ])
86
+ ]));
87
+ await expectParamsError (
88
+ process,
89
+ errorId,
90
+ "Importer.non_canonical_scheme may only be set along with "
91
+ "Importer.importer.importer_id" );
92
+ await process.shouldExit (76 );
93
+ });
94
+
95
+ test ("unset" , () async {
96
+ process.send (compileString ("a {b: c}" ,
97
+ importer: InboundMessage_CompileRequest_Importer (
98
+ nonCanonicalScheme: ["u" ])));
99
+ await expectParamsError (
100
+ process,
101
+ errorId,
102
+ "Importer.non_canonical_scheme may only be set along with "
103
+ "Importer.importer.importer_id" );
104
+ await process.shouldExit (76 );
105
+ });
106
+ });
67
107
});
68
108
69
109
group ("canonicalization" , () {
@@ -156,6 +196,86 @@ void main() {
156
196
await process.close ();
157
197
});
158
198
199
+ group ("the containing URL" , () {
200
+ test ("is unset for a potentially canonical scheme" , () async {
201
+ process.send (compileString ('@import "u:orange"' , importers: [
202
+ InboundMessage_CompileRequest_Importer (importerId: 1 )
203
+ ]));
204
+
205
+ var request = await getCanonicalizeRequest (process);
206
+ expect (request.hasContainingUrl (), isFalse);
207
+ await process.close ();
208
+ });
209
+
210
+ group ("for a non-canonical scheme" , () {
211
+ test ("is set to the original URL" , () async {
212
+ process.send (compileString ('@import "u:orange"' ,
213
+ importers: [
214
+ InboundMessage_CompileRequest_Importer (
215
+ importerId: 1 , nonCanonicalScheme: ["u" ])
216
+ ],
217
+ url: "x:original.scss" ));
218
+
219
+ var request = await getCanonicalizeRequest (process);
220
+ expect (request.containingUrl, equals ("x:original.scss" ));
221
+ await process.close ();
222
+ });
223
+
224
+ test ("is unset to the original URL is unset" , () async {
225
+ process.send (compileString ('@import "u:orange"' , importers: [
226
+ InboundMessage_CompileRequest_Importer (
227
+ importerId: 1 , nonCanonicalScheme: ["u" ])
228
+ ]));
229
+
230
+ var request = await getCanonicalizeRequest (process);
231
+ expect (request.hasContainingUrl (), isFalse);
232
+ await process.close ();
233
+ });
234
+ });
235
+
236
+ group ("for a schemeless load" , () {
237
+ test ("is set to the original URL" , () async {
238
+ process.send (compileString ('@import "orange"' ,
239
+ importers: [
240
+ InboundMessage_CompileRequest_Importer (importerId: 1 )
241
+ ],
242
+ url: "x:original.scss" ));
243
+
244
+ var request = await getCanonicalizeRequest (process);
245
+ expect (request.containingUrl, equals ("x:original.scss" ));
246
+ await process.close ();
247
+ });
248
+
249
+ test ("is unset to the original URL is unset" , () async {
250
+ process.send (compileString ('@import "u:orange"' , importers: [
251
+ InboundMessage_CompileRequest_Importer (importerId: 1 )
252
+ ]));
253
+
254
+ var request = await getCanonicalizeRequest (process);
255
+ expect (request.hasContainingUrl (), isFalse);
256
+ await process.close ();
257
+ });
258
+ });
259
+ });
260
+
261
+ test (
262
+ "fails if the importer returns a canonical URL with a non-canonical "
263
+ "scheme" , () async {
264
+ process.send (compileString ("@import 'other'" , importers: [
265
+ InboundMessage_CompileRequest_Importer (
266
+ importerId: 1 , nonCanonicalScheme: ["u" ])
267
+ ]));
268
+
269
+ var request = await getCanonicalizeRequest (process);
270
+ process.send (InboundMessage (
271
+ canonicalizeResponse: InboundMessage_CanonicalizeResponse (
272
+ id: request.id, url: "u:other" )));
273
+
274
+ await _expectImportError (
275
+ process, contains ('a scheme declared as non-canonical' ));
276
+ await process.close ();
277
+ });
278
+
159
279
test ("attempts importers in order" , () async {
160
280
process.send (compileString ("@import 'other'" , importers: [
161
281
for (var i = 0 ; i < 10 ; i++ )
@@ -474,6 +594,44 @@ void main() {
474
594
await process.close ();
475
595
});
476
596
});
597
+
598
+ group ("fails compilation for an invalid scheme:" , () {
599
+ test ("empty" , () async {
600
+ process.send (compileString ("a {b: c}" , importers: [
601
+ InboundMessage_CompileRequest_Importer (
602
+ importerId: 1 , nonCanonicalScheme: ["" ])
603
+ ]));
604
+
605
+ var failure = await getCompileFailure (process);
606
+ expect (failure.message,
607
+ equals ('"" isn\' t a valid URL scheme (for example "file").' ));
608
+ await process.close ();
609
+ });
610
+
611
+ test ("uppercase" , () async {
612
+ process.send (compileString ("a {b: c}" , importers: [
613
+ InboundMessage_CompileRequest_Importer (
614
+ importerId: 1 , nonCanonicalScheme: ["U" ])
615
+ ]));
616
+
617
+ var failure = await getCompileFailure (process);
618
+ expect (failure.message,
619
+ equals ('"U" isn\' t a valid URL scheme (for example "file").' ));
620
+ await process.close ();
621
+ });
622
+
623
+ test ("colon" , () async {
624
+ process.send (compileString ("a {b: c}" , importers: [
625
+ InboundMessage_CompileRequest_Importer (
626
+ importerId: 1 , nonCanonicalScheme: ["u:" ])
627
+ ]));
628
+
629
+ var failure = await getCompileFailure (process);
630
+ expect (failure.message,
631
+ equals ('"u:" isn\' t a valid URL scheme (for example "file").' ));
632
+ await process.close ();
633
+ });
634
+ });
477
635
}
478
636
479
637
/// Handles a `CanonicalizeRequest` and returns a response with a generic
0 commit comments