|
| 1 | +// Copyright (c) 2016, 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 | +@TestOn('vm') |
| 5 | +import 'package:test/test.dart'; |
| 6 | + |
| 7 | +import 'package:build/build.dart'; |
| 8 | + |
| 9 | +// Forked from `barback/test/asset_id_test.dart`. |
| 10 | +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")); |
| 15 | + }); |
| 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")); |
| 20 | + }); |
| 21 | + }); |
| 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")); |
| 28 | + }); |
| 29 | + |
| 30 | + test("throws if there are multiple '|'", () { |
| 31 | + expect(() => new AssetId.parse("app|path|wtf"), throwsFormatException); |
| 32 | + }); |
| 33 | + |
| 34 | + test("throws if the package name is empty '|'", () { |
| 35 | + expect(() => new AssetId.parse("|asset.txt"), throwsFormatException); |
| 36 | + }); |
| 37 | + |
| 38 | + test("throws if the path is empty '|'", () { |
| 39 | + expect(() => new AssetId.parse("app|"), throwsFormatException); |
| 40 | + }); |
| 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")); |
| 45 | + }); |
| 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")); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + test("equals another ID with the same package and path", () { |
| 54 | + expect(new AssetId.parse("foo|asset.txt"), equals( |
| 55 | + new AssetId.parse("foo|asset.txt"))); |
| 56 | + |
| 57 | + expect(new AssetId.parse("foo|asset.txt"), isNot(equals( |
| 58 | + new AssetId.parse("bar|asset.txt")))); |
| 59 | + |
| 60 | + expect(new AssetId.parse("foo|asset.txt"), isNot(equals( |
| 61 | + new AssetId.parse("bar|other.txt")))); |
| 62 | + }); |
| 63 | + |
| 64 | + test("identical assets are treated as the same in a Map/Set", () { |
| 65 | + var id1 = new AssetId('a', 'web/a.txt'); |
| 66 | + var id2 = new AssetId('a', 'web/a.txt'); |
| 67 | + |
| 68 | + expect({id1: true}.containsKey(id2), isTrue); |
| 69 | + expect(new Set<AssetId>.from([id1]), contains(id2)); |
| 70 | + }); |
| 71 | +} |
0 commit comments