OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library barback.test.asset_id_test; |
| 6 |
| 7 import 'package:barback/barback.dart'; |
| 8 import 'package:unittest/unittest.dart'; |
| 9 |
| 10 import 'utils.dart'; |
| 11 |
| 12 main() { |
| 13 initConfig(); |
| 14 group("constructor", () { |
| 15 test("normalizes the path", () { |
| 16 var id = new AssetId("app", r"path/././/to/drop/..//asset.txt"); |
| 17 expect(id.path, equals("path/to/asset.txt")); |
| 18 }); |
| 19 |
| 20 test("normalizes backslashes to slashes in the path", () { |
| 21 var id = new AssetId("app", r"path\to/asset.txt"); |
| 22 expect(id.path, equals("path/to/asset.txt")); |
| 23 }); |
| 24 }); |
| 25 |
| 26 group("parse", () { |
| 27 test("parses the package and path", () { |
| 28 var id = new AssetId.parse("package|path/to/asset.txt"); |
| 29 expect(id.package, equals("package")); |
| 30 expect(id.path, equals("path/to/asset.txt")); |
| 31 }); |
| 32 |
| 33 test("throws if there are multiple '|'", () { |
| 34 expect(() => new AssetId.parse("app|path|wtf"), throwsFormatException); |
| 35 }); |
| 36 |
| 37 test("throws if the package name is empty '|'", () { |
| 38 expect(() => new AssetId.parse("|asset.txt"), throwsFormatException); |
| 39 }); |
| 40 |
| 41 test("throws if the path is empty '|'", () { |
| 42 expect(() => new AssetId.parse("app|"), throwsFormatException); |
| 43 }); |
| 44 |
| 45 test("normalizes the path", () { |
| 46 var id = new AssetId.parse(r"app|path/././/to/drop/..//asset.txt"); |
| 47 expect(id.path, equals("path/to/asset.txt")); |
| 48 }); |
| 49 |
| 50 test("normalizes backslashes to slashes in the path", () { |
| 51 var id = new AssetId.parse(r"app|path\to/asset.txt"); |
| 52 expect(id.path, equals("path/to/asset.txt")); |
| 53 }); |
| 54 }); |
| 55 |
| 56 test("equals another ID with the same package and path", () { |
| 57 expect(new AssetId.parse("foo|asset.txt"), equals( |
| 58 new AssetId.parse("foo|asset.txt"))); |
| 59 |
| 60 expect(new AssetId.parse("foo|asset.txt"), isNot(equals( |
| 61 new AssetId.parse("bar|asset.txt")))); |
| 62 |
| 63 expect(new AssetId.parse("foo|asset.txt"), isNot(equals( |
| 64 new AssetId.parse("bar|other.txt")))); |
| 65 }); |
| 66 } |
OLD | NEW |