@@ -201,6 +201,61 @@ void main() {
201201 })));
202202 });
203203
204+ group ("compileString()'s importer option" , () {
205+ test ("loads relative imports from the entrypoint" , () {
206+ var css = compileString ('@import "orange";' ,
207+ importer: TestImporter ((url) => Uri .parse ("u:$url " ), (url) {
208+ var color = url.path;
209+ return ImporterResult ('.$color {color: $color }' , indented: false );
210+ }));
211+
212+ expect (css, equals (".orange {\n color: orange;\n }" ));
213+ });
214+
215+ test ("loads imports relative to the entrypoint's URL" , () {
216+ var css = compileString ('@import "baz/qux";' ,
217+ importer: TestImporter ((url) => url.resolve ("bang" ), (url) {
218+ return ImporterResult ('a {result: "${url .path }"}' , indented: false );
219+ }),
220+ url: Uri .parse ("u:foo/bar" ));
221+
222+ expect (css, equals ('a {\n result: "foo/baz/bang";\n }' ));
223+ });
224+
225+ test ("doesn't load absolute imports" , () {
226+ var css = compileString ('@import "u:orange";' ,
227+ importer: TestImporter ((_) => throw "Should not be called" ,
228+ (_) => throw "Should not be called" ),
229+ importers: [
230+ TestImporter ((url) => url, (url) {
231+ var color = url.path;
232+ return ImporterResult ('.$color {color: $color }' , indented: false );
233+ })
234+ ]);
235+
236+ expect (css, equals (".orange {\n color: orange;\n }" ));
237+ });
238+
239+ test ("doesn't load from other importers" , () {
240+ var css = compileString ('@import "u:midstream";' ,
241+ importer: TestImporter ((_) => throw "Should not be called" ,
242+ (_) => throw "Should not be called" ),
243+ importers: [
244+ TestImporter ((url) => url, (url) {
245+ if (url.path == "midstream" ) {
246+ return ImporterResult ("@import 'orange';" , indented: false );
247+ } else {
248+ var color = url.path;
249+ return ImporterResult ('.$color {color: $color }' ,
250+ indented: false );
251+ }
252+ })
253+ ]);
254+
255+ expect (css, equals (".orange {\n color: orange;\n }" ));
256+ });
257+ });
258+
204259 group ("currentLoadFromImport is" , () {
205260 test ("true from an @import" , () {
206261 compileString ('@import "foo"' , importers: [FromImportImporter (true )]);
0 commit comments