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

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

Issue 18650004: Make Assets know their ID. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't make AssetSet implement Set<T>. Created 7 years, 5 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
(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_set_test;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import 'package:barback/barback.dart';
11 import 'package:barback/src/asset_set.dart';
12 import 'package:unittest/unittest.dart';
13
14 import 'utils.dart';
15
16 main() {
17 initConfig();
18
19 var fooId = new AssetId.parse("app|foo.txt");
20 var barId = new AssetId.parse("app|bar.txt");
21
22 group("[] operator", () {
23 test("gets an asset with the given ID", () {
24 var set = new AssetSet();
25 var foo = new MockAsset(fooId, "foo");
26 set.add(foo);
27
28 expect(set[fooId], equals(foo));
29 });
30
31 test("returns null if no asset with the ID is in the set", () {
32 var set = new AssetSet();
33 expect(set[fooId], isNull);
34 });
35 });
36
37 group(".add()", () {
38 test("adds the asset to the set", () {
39 var set = new AssetSet();
40 var foo = new MockAsset(fooId, "foo");
41 set.add(foo);
42 expect(set.contains(foo), isTrue);
43 });
44
45 test("replaces a previously added asset with that ID", () {
46 var set = new AssetSet();
47 set.add(new MockAsset(fooId, "before"));
48 set.add(new MockAsset(fooId, "after"));
49 expect(set[fooId].contents, equals("after"));
50 });
51
52 test("returns the added item", () {
53 var set = new AssetSet();
54 var foo = new MockAsset(fooId, "foo");
55 expect(set.add(foo), equals(foo));
56 });
57 });
58
59 group(".addAll()", () {
60 test("adds the assets to the set", () {
61 var set = new AssetSet();
62 var foo = new MockAsset(fooId, "foo");
63 var bar = new MockAsset(barId, "bar");
64 set.addAll([foo, bar]);
65 expect(set.contains(foo), isTrue);
66 expect(set.contains(bar), isTrue);
67 });
68
69 test("replaces assets earlier in the sequence with later ones", () {
70 var set = new AssetSet();
71 var foo1 = new MockAsset(fooId, "before");
72 var foo2 = new MockAsset(fooId, "after");
73 set.addAll([foo1, foo2]);
74 expect(set[fooId].contents, equals("after"));
75 });
76 });
77
78 group(".clear()", () {
79 test("empties the set", () {
80 var set = new AssetSet();
81 var foo = new MockAsset(fooId, "foo");
82 set.add(foo);
83 set.clear();
84
85 expect(set.length, equals(0));
86 expect(set.contains(foo), isFalse);
87 });
88 });
89
90 group(".contains()", () {
91 test("returns true if the asset is in the set", () {
92 var set = new AssetSet();
93 var foo = new MockAsset(fooId, "foo");
94 var bar = new MockAsset(barId, "bar");
95 set.add(foo);
96
97 expect(set.contains(foo), isTrue);
98 expect(set.contains(bar), isFalse);
99 });
100 });
101
102 group(".containsId()", () {
103 test("returns true if an asset with the ID is in the set", () {
104 var set = new AssetSet();
105 var foo = new MockAsset(fooId, "foo");
106 set.add(foo);
107
108 expect(set.containsId(fooId), isTrue);
109 expect(set.containsId(barId), isFalse);
110 });
111 });
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698