Skip to content

Commit

Permalink
code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Feb 4, 2016
1 parent 765f90e commit 8415c13
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ build/
.pub/
pubspec.lock

# Generated by tool/create_all_test.dart
tool/test_all.dart

# Include .packages files from tests which are hand coded
!test/fixtures/**/.packages
5 changes: 0 additions & 5 deletions lib/src/asset/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ class Asset {

Asset(this.id, this.stringContents);

bool operator ==(other) =>
other is Asset &&
other.id == id &&
other.stringContents == stringContents;

String toString() => 'Asset: $id';
}
6 changes: 3 additions & 3 deletions lib/src/asset/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class CachedAssetReader extends AssetReader {
final AssetCache _cache;
final AssetReader _reader;
/// Cache of ongoing reads by [AssetId].
final Map<AssetId, Future<String>> _pendingReads = {};
final _pendingReads = <AssetId, Future<String>>{};
/// Cache of ongoing hasInput checks by [AssetId].
final Map<AssetId, Future<bool>> _pendingHasInputChecks = {};
final _pendingHasInputChecks = <AssetId, Future<bool>>{};

CachedAssetReader(this._cache, this._reader);

@override
Future<bool> hasInput(AssetId id) {
if (_cache.contains(id)) return new Future.value(true);

_pendingHasInputChecks.putIfAbsent(id, () async {
var exists = await _reader.hasInput(id);
_pendingHasInputChecks.remove(id);
Expand Down
8 changes: 4 additions & 4 deletions test/asset/cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ main() {

test('put throws if the asset exists and overwrite == false', () {
var asset = makeAsset('${a.id}');
expect(() => cache.put(asset), throwsA(argumentError));
expect(() => cache.put(asset), throwsArgumentError);
});

test('put doesn\'t throw if the asset exists and overwrite == true', () {
Expand Down Expand Up @@ -91,7 +91,7 @@ main() {
test('reads add values to the cache', () async {
childReaderAssets[a.id] = a.stringContents;
await reader.readAsString(a.id);
expect(cache.get(a.id), equals(a));
expect(cache.get(a.id), equalsAsset(a));
childReaderAssets.remove(a.id);
expect(await reader.readAsString(a.id), a.stringContents);
});
Expand Down Expand Up @@ -163,12 +163,12 @@ main() {

test('multiple sync writes for the same asset throws', () async {
writer.writeAsString(a);
expect(() => writer.writeAsString(a), throwsA(argumentError));
expect(() => writer.writeAsString(a), throwsArgumentError);
});

test('multiple async writes for the same asset throws', () async {
await writer.writeAsString(a);
expect(() => writer.writeAsString(a), throwsA(argumentError));
expect(() => writer.writeAsString(a), throwsArgumentError);
});
});
}
19 changes: 18 additions & 1 deletion test/common/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ import 'package:test/test.dart';

import 'package:build/build.dart';

final argumentError = new isInstanceOf<ArgumentError>();
final assetNotFoundException = new isInstanceOf<AssetNotFoundException>();
final invalidInputException = new isInstanceOf<InvalidInputException>();
final invalidOutputException = new isInstanceOf<InvalidOutputException>();
final packageNotFoundException = new isInstanceOf<PackageNotFoundException>();

equalsAsset(Asset expected) => new _AssetMatcher(expected);

class _AssetMatcher extends Matcher {
final Asset _expected;

const _AssetMatcher(this._expected);

@override
bool matches(item, _) =>
item is Asset &&
item.id == _expected.id &&
item.stringContents == _expected.stringContents;

@override
Description describe(Description description) =>
description.addDescriptionOf(_expected);
}

0 comments on commit 8415c13

Please sign in to comment.