@@ -8,114 +8,81 @@ import 'package:build/build.dart';
8
8
9
9
// Forked from `barback/test/asset_id_test.dart`.
10
10
void main () {
11
- group (" constructor" , () {
12
- test (" normalizes the path" , () {
13
- var id = new AssetId (" app" , r" path/././/to/drop/..//asset.txt" );
14
- expect (id.path, equals (" path/to/asset.txt" ));
11
+ group (' constructor' , () {
12
+ test (' normalizes the path' , () {
13
+ var id = new AssetId (' app' , r' path/././/to/drop/..//asset.txt' );
14
+ expect (id.path, equals (' path/to/asset.txt' ));
15
15
});
16
16
17
- test (" normalizes backslashes to slashes in the path" , () {
18
- var id = new AssetId (" app" , r" path\to/asset.txt" );
19
- expect (id.path, equals (" path/to/asset.txt" ));
17
+ test (' normalizes backslashes to slashes in the path' , () {
18
+ var id = new AssetId (' app' , r' path\to/asset.txt' );
19
+ expect (id.path, equals (' path/to/asset.txt' ));
20
20
});
21
21
});
22
22
23
- group (" parse" , () {
24
- test (" parses the package and path" , () {
25
- var id = new AssetId .parse (" package|path/to/asset.txt" );
26
- expect (id.package, equals (" package" ));
27
- expect (id.path, equals (" path/to/asset.txt" ));
23
+ group (' parse' , () {
24
+ test (' parses the package and path' , () {
25
+ var id = new AssetId .parse (' package|path/to/asset.txt' );
26
+ expect (id.package, equals (' package' ));
27
+ expect (id.path, equals (' path/to/asset.txt' ));
28
28
});
29
29
30
- test (" throws if there are multiple '|'" , () {
31
- expect (() => new AssetId .parse (" app|path|wtf" ), throwsFormatException);
30
+ test (' throws if there are multiple "|"' , () {
31
+ expect (() => new AssetId .parse (' app|path|wtf' ), throwsFormatException);
32
32
});
33
33
34
- test (" throws if the package name is empty '|'" , () {
35
- expect (() => new AssetId .parse (" |asset.txt" ), throwsFormatException);
34
+ test (' throws if the package name is empty "|"' , () {
35
+ expect (() => new AssetId .parse (' |asset.txt' ), throwsFormatException);
36
36
});
37
37
38
- test (" throws if the path is empty '|'" , () {
39
- expect (() => new AssetId .parse (" app|" ), throwsFormatException);
38
+ test (' throws if the path is empty "|"' , () {
39
+ expect (() => new AssetId .parse (' app|' ), throwsFormatException);
40
40
});
41
41
42
- test (" normalizes the path" , () {
43
- var id = new AssetId .parse (r" app|path/././/to/drop/..//asset.txt" );
44
- expect (id.path, equals (" path/to/asset.txt" ));
42
+ test (' normalizes the path' , () {
43
+ var id = new AssetId .parse (r' app|path/././/to/drop/..//asset.txt' );
44
+ expect (id.path, equals (' path/to/asset.txt' ));
45
45
});
46
46
47
- test (" normalizes backslashes to slashes in the path" , () {
48
- var id = new AssetId .parse (r" app|path\to/asset.txt" );
49
- expect (id.path, equals (" path/to/asset.txt" ));
47
+ test (' normalizes backslashes to slashes in the path' , () {
48
+ var id = new AssetId .parse (r' app|path\to/asset.txt' );
49
+ expect (id.path, equals (' path/to/asset.txt' ));
50
50
});
51
51
});
52
52
53
- group ("resolve" , () {
54
- test ("should parse a package: URI" , () {
55
- var id = new AssetId . resolve ( r"package:app/app .dart" );
56
- expect (id, new AssetId ( "app" , "lib/app .dart" ));
53
+ group ('to URI' , () {
54
+ test ('uses ` package:` URIs inside lib/' , () {
55
+ expect ( new AssetId ( 'foo' , 'lib/bar .dart' ).uri,
56
+ Uri . parse ( 'package:foo/bar .dart' ));
57
57
});
58
58
59
- test ("should parse a package: URI with a long path" , () {
60
- var id = new AssetId . resolve ( r"package:app/src/some/path .dart" );
61
- expect (id, new AssetId ( "app" , "lib/src/some/path .dart" ));
59
+ test ('uses `asset:` URIs outside lib/' , () async {
60
+ expect ( new AssetId ( 'foo' , 'web/main .dart' ).uri,
61
+ Uri . parse ( 'asset:foo/web/main .dart' ));
62
62
});
63
63
64
- test ("should parse an asset: URI" , () {
65
- var id = new AssetId .resolve (r"asset:app/test/foo_test.dart" );
66
- expect (id, new AssetId ("app" , "test/foo_test.dart" ));
67
- });
68
-
69
- test ("should throw for a file: URI" , () {
70
- expect (() => new AssetId .resolve (r"file://localhost/etc/fstab1" ),
71
- throwsUnsupportedError);
72
- });
73
-
74
- test ("should throw for a dart: URI" , () {
75
- expect (() => new AssetId .resolve (r"dart:collection" ),
76
- throwsUnsupportedError);
77
- });
78
-
79
- test ("should throw parsing a relative package URI without an origin" , () {
80
- expect (() => new AssetId .resolve ("some/relative/path.dart" ),
81
- throwsArgumentError);
82
- });
83
-
84
- test ("should parse a relative URI within the test/ folder" , () {
85
- var id = new AssetId .resolve ("common.dart" ,
86
- from: new AssetId ("app" , "test/some_test.dart" ));
87
- expect (id, new AssetId ("app" , "test/common.dart" ));
88
- });
89
-
90
- test ("should parse a relative package URI" , () {
91
- var id = new AssetId .resolve ("some/relative/path.dart" ,
92
- from: new AssetId ("app" , "lib/app.dart" ));
93
- expect (id, new AssetId ("app" , "lib/some/relative/path.dart" ));
94
- });
95
-
96
- test ("should parse a relative package URI pointing back" , () {
97
- var id = new AssetId .resolve ("../src/some/path.dart" ,
98
- from: new AssetId ("app" , "folder/folder.dart" ));
99
- expect (id, new AssetId ("app" , "src/some/path.dart" ));
64
+ test ('handles characters that are valid in a file path' , () {
65
+ expect (new AssetId ('foo' , 'lib/#bar.dart' ).uri,
66
+ Uri .parse ('package:foo/%23bar.dart' ));
100
67
});
101
68
});
102
69
103
- test (" equals another ID with the same package and path" , () {
104
- expect (new AssetId .parse (" foo|asset.txt" ),
105
- equals (new AssetId .parse (" foo|asset.txt" )));
70
+ test (' equals another ID with the same package and path' , () {
71
+ expect (new AssetId .parse (' foo|asset.txt' ),
72
+ equals (new AssetId .parse (' foo|asset.txt' )));
106
73
107
- expect (new AssetId .parse (" foo|asset.txt" ),
108
- isNot (equals (new AssetId .parse (" bar|asset.txt" ))));
74
+ expect (new AssetId .parse (' foo|asset.txt' ),
75
+ isNot (equals (new AssetId .parse (' bar|asset.txt' ))));
109
76
110
- expect (new AssetId .parse (" foo|asset.txt" ),
111
- isNot (equals (new AssetId .parse (" bar|other.txt" ))));
77
+ expect (new AssetId .parse (' foo|asset.txt' ),
78
+ isNot (equals (new AssetId .parse (' bar|other.txt' ))));
112
79
});
113
80
114
- test (" identical assets are treated as the same in a Map/Set" , () {
81
+ test (' identical assets are treated as the same in a Map/Set' , () {
115
82
var id1 = new AssetId ('a' , 'web/a.txt' );
116
83
var id2 = new AssetId ('a' , 'web/a.txt' );
117
84
118
85
expect ({id1: true }.containsKey (id2), isTrue);
119
- expect (new Set < AssetId >. from ( [id1]), contains (id2));
86
+ expect ([id1]. toSet ( ), contains (id2));
120
87
});
121
88
}
0 commit comments