Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: pkg/barback/test/asset_id_test.dart

Issue 22887039: Normalize incoming AssetID paths. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Enable polymer test that should be fixed by this. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library barback.test.asset_id_test; 5 library barback.test.asset_id_test;
6 6
7 import 'package:barback/barback.dart'; 7 import 'package:barback/barback.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'utils.dart'; 10 import 'utils.dart';
11 11
12 main() { 12 main() {
13 initConfig(); 13 initConfig();
14 group("constructor", () {
15
nweiz 2013/08/22 20:57:14 Style nit: extra newline.
Bob Nystrom 2013/08/22 21:37:19 Done.
16 test("normalizes the path", () {
17 var id = new AssetId("app", r"path/././/to/drop/..//asset.txt");
18 expect(id.path, equals("path/to/asset.txt"));
19 });
20
21 test("normalizes backslashes to slashes in the path", () {
22 var id = new AssetId("app", r"path\to/asset.txt");
23 expect(id.path, equals("path/to/asset.txt"));
24 });
25 });
26
14 group("parse", () { 27 group("parse", () {
15 test("parses the package and path", () { 28 test("parses the package and path", () {
16 var id = new AssetId.parse("package|path/to/asset.txt"); 29 var id = new AssetId.parse("package|path/to/asset.txt");
17 expect(id.package, equals("package")); 30 expect(id.package, equals("package"));
18 expect(id.path, equals("path/to/asset.txt")); 31 expect(id.path, equals("path/to/asset.txt"));
19 }); 32 });
20 33
21 test("throws if there are multiple '|'", () { 34 test("throws if there are multiple '|'", () {
22 expect(() => new AssetId.parse("app|path|wtf"), throwsFormatException); 35 expect(() => new AssetId.parse("app|path|wtf"), throwsFormatException);
23 }); 36 });
24 37
25 test("throws if the package name is empty '|'", () { 38 test("throws if the package name is empty '|'", () {
26 expect(() => new AssetId.parse("|asset.txt"), throwsFormatException); 39 expect(() => new AssetId.parse("|asset.txt"), throwsFormatException);
27 }); 40 });
28 41
29 test("throws if the path is empty '|'", () { 42 test("throws if the path is empty '|'", () {
30 expect(() => new AssetId.parse("app|"), throwsFormatException); 43 expect(() => new AssetId.parse("app|"), throwsFormatException);
31 }); 44 });
45
46 test("normalizes the path", () {
47 var id = new AssetId.parse(r"app|path/././/to/drop/..//asset.txt");
48 expect(id.path, equals("path/to/asset.txt"));
49 });
50
51 test("normalizes backslashes to slashes in the path", () {
52 var id = new AssetId.parse(r"app|path\to/asset.txt");
53 expect(id.path, equals("path/to/asset.txt"));
54 });
32 }); 55 });
33 56
34 test("equals another ID with the same package and path", () { 57 test("equals another ID with the same package and path", () {
35 expect(new AssetId.parse("foo|asset.txt"), equals( 58 expect(new AssetId.parse("foo|asset.txt"), equals(
36 new AssetId.parse("foo|asset.txt"))); 59 new AssetId.parse("foo|asset.txt")));
37 60
38 expect(new AssetId.parse("foo|asset.txt"), isNot(equals( 61 expect(new AssetId.parse("foo|asset.txt"), isNot(equals(
39 new AssetId.parse("bar|asset.txt")))); 62 new AssetId.parse("bar|asset.txt"))));
40 63
41 expect(new AssetId.parse("foo|asset.txt"), isNot(equals( 64 expect(new AssetId.parse("foo|asset.txt"), isNot(equals(
42 new AssetId.parse("bar|other.txt")))); 65 new AssetId.parse("bar|other.txt"))));
43 }); 66 });
44 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698