Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix two tests to be Dart 2 type-safe.

Clean up test/wrapper_test.dart signficantly.
Add enough type annotations to test/unmodifiable_collection_test.dart
to get the necessary inference.
Update dependency on SDK to allow using the new `Invocation` constructor.
  • Loading branch information
lrhn authored May 7, 2018
1 parent cfd3888 commit 3683039
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 208 deletions.
7 changes: 4 additions & 3 deletions pkgs/collection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.14.10

* Fix the parameter names in overridden methods to match the source.
* Fix the parameter names in overridden methods to match the source.
* Make tests Dart 2 type-safe.

## 1.14.9

Expand All @@ -13,7 +14,7 @@

* Deprecated `Delegating{Name}.typed` static methods in favor of the new Dart 2
`cast` methods. For example, `DelegatingList.typed<String>(list)` can now be
written as `list.cast<String>()`.
written as `list.cast<String>()`.

## 1.14.7

Expand All @@ -37,7 +38,7 @@
## 1.14.4

* Add implementation stubs of upcoming Dart 2.0 core library methods, namely
new methods for classes that implement `Iterable`, `List`, `Map`, `Queue`,
new methods for classes that implement `Iterable`, `List`, `Map`, `Queue`,
and `Set`.

## 1.14.3
Expand Down
4 changes: 2 additions & 2 deletions pkgs/collection/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ homepage: https://www.github.com/dart-lang/collection

environment:
# Required for Dart 2.0 collection changes.
sdk: '>=2.0.0-dev.36.0 <2.0.0'
sdk: '>=2.0.0-dev.49.0 <2.0.0'

dev_dependencies:
build_runner: ^0.8.0
build_test: ^0.10.0
build_web_compilers: ^0.3.1
test: ^0.12.0
test: ^0.12.35
45 changes: 23 additions & 22 deletions pkgs/collection/test/unmodifiable_collection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ main() {
testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "empty");
aSet = new Set();
testUnmodifiableSet(aSet, const UnmodifiableSetView.empty(), "const empty");
aSet = new Set.from([42]);
aSet = new Set.of([42]);
testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single-42");
aSet = new Set.from([7]);
aSet = new Set.of([7]);
testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "single!42");
aSet = new Set.from([1, 42, 10]);
aSet = new Set.of([1, 42, 10]);
testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three-42");
aSet = new Set.from([1, 7, 10]);
aSet = new Set.of([1, 7, 10]);
testUnmodifiableSet(aSet, new UnmodifiableSetView(aSet), "three!42");
}

Expand Down Expand Up @@ -311,8 +311,8 @@ void testReadList(List original, List wrapped, String name) {
});
}

void testNoWriteList(List original, List wrapped, String name) {
List copy = new List.from(original);
void testNoWriteList(List<int> original, List<int> wrapped, String name) {
var copy = new List.of(original);

testThrows(name, thunk) {
test(name, () {
Expand Down Expand Up @@ -345,7 +345,7 @@ void testNoWriteList(List original, List wrapped, String name) {
}

void testWriteList(List<int> original, List wrapped, String name) {
var copy = new List<int>.from(original);
var copy = new List.of(original);

test("$name - []=", () {
if (original.isNotEmpty) {
Expand All @@ -361,7 +361,7 @@ void testWriteList(List<int> original, List wrapped, String name) {
});

test("$name - sort", () {
List sortCopy = new List.from(original);
List sortCopy = new List.of(original);
sortCopy.sort();
wrapped.sort();
expect(original, orderedEquals(sortCopy));
Expand Down Expand Up @@ -391,8 +391,9 @@ void testWriteList(List<int> original, List wrapped, String name) {
});
}

void testNoChangeLengthList(List original, List wrapped, String name) {
List copy = new List.from(original);
void testNoChangeLengthList(
List<int> original, List<int> wrapped, String name) {
var copy = new List.of(original);

void testThrows(String name, thunk) {
test(name, () {
Expand Down Expand Up @@ -455,8 +456,8 @@ void testNoChangeLengthList(List original, List wrapped, String name) {
});
}

void testReadSet(Set original, Set wrapped, String name) {
Set copy = new Set.from(original);
void testReadSet(Set<int> original, Set<int> wrapped, String name) {
var copy = new Set.of(original);

test("$name - containsAll", () {
expect(wrapped.containsAll(copy), isTrue);
Expand All @@ -468,27 +469,27 @@ void testReadSet(Set original, Set wrapped, String name) {
test("$name - intersection", () {
expect(wrapped.intersection(new Set()), isEmpty);
expect(wrapped.intersection(copy), unorderedEquals(original));
expect(wrapped.intersection(new Set.from([42])),
new Set.from(original.contains(42) ? [42] : []));
expect(wrapped.intersection(new Set.of([42])),
new Set.of(original.contains(42) ? [42] : []));
});

test("$name - union", () {
expect(wrapped.union(new Set()), unorderedEquals(original));
expect(wrapped.union(copy), unorderedEquals(original));
expect(wrapped.union(new Set.from([42])),
equals(original.union(new Set.from([42]))));
expect(wrapped.union(new Set.of([42])),
equals(original.union(new Set.of([42]))));
});

test("$name - difference", () {
expect(wrapped.difference(new Set()), unorderedEquals(original));
expect(wrapped.difference(copy), isEmpty);
expect(wrapped.difference(new Set.from([42])),
equals(original.difference(new Set.from([42]))));
expect(wrapped.difference(new Set.of([42])),
equals(original.difference(new Set.of([42]))));
});
}

void testNoChangeSet(Set original, Set wrapped, String name) {
List originalElements = original.toList();
void testNoChangeSet(Set<int> original, Set<int> wrapped, String name) {
var originalElements = original.toList();

testThrows(name, thunk) {
test(name, () {
Expand Down Expand Up @@ -588,8 +589,8 @@ void testReadMap(Map<int, int> original, Map<int, int> wrapped, String name) {
});
}

testNoChangeMap(Map original, Map wrapped, String name) {
Map copy = new Map.from(original);
testNoChangeMap(Map<int, int> original, Map<int, int> wrapped, String name) {
var copy = new Map.of(original);

testThrows(name, thunk) {
test(name, () {
Expand Down
Loading

0 comments on commit 3683039

Please sign in to comment.