From 6100904a3c996058c23ca84bed1aeff4a086ac0a Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 12 Mar 2018 20:57:20 -0700 Subject: [PATCH 1/2] Deleted typed wrappers, use Dart 2 instead. --- CHANGELOG.md | 6 + lib/src/typed_wrappers.dart | 410 ------------------------- lib/src/wrappers.dart | 21 +- test/typed_wrapper/iterable_test.dart | 354 ---------------------- test/typed_wrapper/list_test.dart | 421 -------------------------- test/typed_wrapper/map_test.dart | 327 -------------------- test/typed_wrapper/queue_test.dart | 141 --------- test/typed_wrapper/set_test.dart | 173 ----------- 8 files changed, 16 insertions(+), 1837 deletions(-) delete mode 100644 lib/src/typed_wrappers.dart delete mode 100644 test/typed_wrapper/iterable_test.dart delete mode 100644 test/typed_wrapper/list_test.dart delete mode 100644 test/typed_wrapper/map_test.dart delete mode 100644 test/typed_wrapper/queue_test.dart delete mode 100644 test/typed_wrapper/set_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 123a255..5d82dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.14.8 + +* Deprecated `Delegating{Name}.typed` static methods in favor of the new Dart 2 + `cast` methods. For example, `DelegatingList.typed(list)` can now just + be written as `list.cast()`. + ## 1.14.7 * Only the Dart 2 dev SDK (`>=2.0.0-dev.22.0`) is now supported. diff --git a/lib/src/typed_wrappers.dart b/lib/src/typed_wrappers.dart deleted file mode 100644 index c42603d..0000000 --- a/lib/src/typed_wrappers.dart +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "dart:collection"; -import "dart:math" as math; - -import "wrappers.dart"; - -typedef F _UnaryFunction(E argument); - -/// The base class for delegating, type-asserting iterables. -/// -/// Subclasses can provide a [_base] that should be delegated to. Unlike -/// [TypeSafeIterable], this allows the base to be created on demand. -abstract class _TypeSafeIterableBase implements Iterable { - /// The base iterable to which operations are delegated. - Iterable get _base; - - _TypeSafeIterableBase(); - - bool any(bool test(E element)) => _base.any(_validate(test)); - - Iterable cast() => new TypeSafeIterable(_base.cast()); - - bool contains(Object element) => _base.contains(element); - - E elementAt(int index) => _base.elementAt(index) as E; - - bool every(bool test(E element)) => _base.every(_validate(test)); - - Iterable expand(Iterable f(E element)) => _base.expand(_validate(f)); - - E get first => _base.first as E; - - E firstWhere(bool test(E element), {E orElse()}) => - _base.firstWhere(_validate(test), orElse: orElse) as E; - - T fold(T initialValue, T combine(T previousValue, E element)) => - _base.fold(initialValue, - (previousValue, element) => combine(previousValue, element as E)); - - Iterable followedBy(Iterable other) => - new TypeSafeIterable(_base.followedBy(other)); - - void forEach(void f(E element)) => _base.forEach(_validate(f)); - - bool get isEmpty => _base.isEmpty; - - bool get isNotEmpty => _base.isNotEmpty; - - Iterator get iterator => _base.map((element) => element as E).iterator; - - String join([String separator = ""]) => _base.join(separator); - - E get last => _base.last as E; - - E lastWhere(bool test(E element), {E orElse()}) => - _base.lastWhere(_validate(test), orElse: orElse) as E; - - int get length => _base.length; - - Iterable map(T f(E element)) => _base.map(_validate(f)); - - E reduce(E combine(E value, E element)) => - _base.reduce((value, element) => combine(value as E, element as E)) as E; - - Iterable retype() => new TypeSafeIterable(_base.retype()); - - E get single => _base.single as E; - - E singleWhere(bool test(E element), {E orElse()}) { - return _base.singleWhere(_validate(test), orElse: orElse) as E; - } - - Iterable skip(int n) => new TypeSafeIterable(_base.skip(n)); - - Iterable skipWhile(bool test(E value)) => - new TypeSafeIterable(_base.skipWhile(_validate(test))); - - Iterable take(int n) => new TypeSafeIterable(_base.take(n)); - - Iterable takeWhile(bool test(E value)) => - new TypeSafeIterable(_base.takeWhile(_validate(test))); - - List toList({bool growable: true}) => - new TypeSafeList(_base.toList(growable: growable)); - - Set toSet() => new TypeSafeSet(_base.toSet()); - - Iterable where(bool test(E element)) => - new TypeSafeIterable(_base.where(_validate(test))); - - Iterable whereType() => _base.whereType(); - - String toString() => _base.toString(); - - /// Returns a version of [function] that asserts that its argument is an - /// instance of `E`. - _UnaryFunction _validate(F function(E value)) => - (value) => function(value as E); -} - -/// An [Iterable] that asserts the types of values in a base iterable. -/// -/// This is instantiated using [DelegatingIterable.typed]. -class TypeSafeIterable extends _TypeSafeIterableBase - implements DelegatingIterable { - final Iterable _base; - - TypeSafeIterable(Iterable base) : _base = base; -} - -/// A [List] that asserts the types of values in a base list. -/// -/// This is instantiated using [DelegatingList.typed]. -class TypeSafeList extends TypeSafeIterable implements DelegatingList { - TypeSafeList(List base) : super(base); - - /// A [List]-typed getter for [_base]. - List get _listBase => _base; - - E operator [](int index) => _listBase[index] as E; - - void operator []=(int index, E value) { - _listBase[index] = value; - } - - List operator +(List other) => new TypeSafeList(_listBase + other); - - void add(E value) { - _listBase.add(value); - } - - void addAll(Iterable iterable) { - _listBase.addAll(iterable); - } - - Map asMap() => new TypeSafeMap(_listBase.asMap()); - - List cast() => new TypeSafeList(_listBase.cast()); - - void clear() { - _listBase.clear(); - } - - void fillRange(int start, int end, [E fillValue]) { - _listBase.fillRange(start, end, fillValue); - } - - set first(E value) { - if (this.isEmpty) throw new RangeError.index(0, this); - this[0] = value; - } - - Iterable getRange(int start, int end) => - new TypeSafeIterable(_listBase.getRange(start, end)); - - int indexOf(E element, [int start = 0]) => _listBase.indexOf(element, start); - - int indexWhere(bool test(E element), [int start = 0]) => - _listBase.indexWhere((e) => test(e as E), start); - - void insert(int index, E element) { - _listBase.insert(index, element); - } - - void insertAll(int index, Iterable iterable) { - _listBase.insertAll(index, iterable); - } - - set last(E value) { - if (this.isEmpty) throw new RangeError.index(0, this); - this[this.length - 1] = value; - } - - int lastIndexOf(E element, [int start]) => - _listBase.lastIndexOf(element, start); - - int lastIndexWhere(bool test(E element), [int start]) => - _listBase.lastIndexWhere((e) => test(e as E), start); - - set length(int newLength) { - _listBase.length = newLength; - } - - bool remove(Object value) => _listBase.remove(value); - - E removeAt(int index) => _listBase.removeAt(index) as E; - - E removeLast() => _listBase.removeLast() as E; - - void removeRange(int start, int end) { - _listBase.removeRange(start, end); - } - - void removeWhere(bool test(E element)) { - _listBase.removeWhere(_validate(test)); - } - - void replaceRange(int start, int end, Iterable iterable) { - _listBase.replaceRange(start, end, iterable); - } - - void retainWhere(bool test(E element)) { - _listBase.retainWhere(_validate(test)); - } - - List retype() => new TypeSafeList(_listBase.retype()); - - Iterable get reversed => new TypeSafeIterable(_listBase.reversed); - - void setAll(int index, Iterable iterable) { - _listBase.setAll(index, iterable); - } - - void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { - _listBase.setRange(start, end, iterable, skipCount); - } - - void shuffle([math.Random random]) { - _listBase.shuffle(random); - } - - void sort([int compare(E a, E b)]) { - if (compare == null) { - _listBase.sort(); - } else { - _listBase.sort((a, b) => compare(a as E, b as E)); - } - } - - List sublist(int start, [int end]) => - new TypeSafeList(_listBase.sublist(start, end)); -} - -/// A [Set] that asserts the types of values in a base set. -/// -/// This is instantiated using [DelegatingSet.typed]. -class TypeSafeSet extends TypeSafeIterable implements DelegatingSet { - TypeSafeSet(Set base) : super(base); - - /// A [Set]-typed getter for [_base]. - Set get _setBase => _base; - - bool add(E value) => _setBase.add(value); - - void addAll(Iterable elements) { - _setBase.addAll(elements); - } - - Set cast() => new TypeSafeSet(_setBase.cast()); - - void clear() { - _setBase.clear(); - } - - bool containsAll(Iterable other) => _setBase.containsAll(other); - - Set difference(Set other) => - new TypeSafeSet(_setBase.difference(other)); - - Set intersection(Set other) => - new TypeSafeSet(_setBase.intersection(other)); - - E lookup(Object element) => _setBase.lookup(element) as E; - - bool remove(Object value) => _setBase.remove(value); - - void removeAll(Iterable elements) { - _setBase.removeAll(elements); - } - - void removeWhere(bool test(E element)) { - _setBase.removeWhere(_validate(test)); - } - - void retainAll(Iterable elements) { - _setBase.retainAll(elements); - } - - void retainWhere(bool test(E element)) { - _setBase.retainWhere(_validate(test)); - } - - Set retype() => new TypeSafeSet(_setBase.retype()); - - Set union(Set other) => new TypeSafeSet(_setBase.union(other)); -} - -/// A [Queue] that asserts the types of values in a base queue. -/// -/// This is instantiated using [DelegatingQueue.typed]. -class TypeSafeQueue extends TypeSafeIterable - implements DelegatingQueue { - TypeSafeQueue(Queue queue) : super(queue); - - /// A [Queue]-typed getter for [_base]. - Queue get _baseQueue => _base; - - void add(E value) { - _baseQueue.add(value); - } - - void addAll(Iterable iterable) { - _baseQueue.addAll(iterable); - } - - void addFirst(E value) { - _baseQueue.addFirst(value); - } - - void addLast(E value) { - _baseQueue.addLast(value); - } - - Queue cast() => new TypeSafeQueue(_baseQueue.cast()); - - void clear() { - _baseQueue.clear(); - } - - bool remove(Object object) => _baseQueue.remove(object); - - void removeWhere(bool test(E element)) { - _baseQueue.removeWhere(_validate(test)); - } - - void retainWhere(bool test(E element)) { - _baseQueue.retainWhere(_validate(test)); - } - - Queue retype() => new TypeSafeQueue(_baseQueue.retype()); - - E removeFirst() => _baseQueue.removeFirst() as E; - - E removeLast() => _baseQueue.removeLast() as E; -} - -/// A [Map] that asserts the types of keys and values in a base map. -/// -/// This is instantiated using [DelegatingMap.typed]. -class TypeSafeMap implements DelegatingMap { - /// The base map to which operations are delegated. - final Map _base; - - TypeSafeMap(Map base) : _base = base; - - V operator [](Object key) => _base[key] as V; - - void operator []=(K key, V value) { - _base[key] = value; - } - - void addAll(Map other) { - _base.addAll(other); - } - - void addEntries(Iterable> entries) { - _base.addEntries(entries); - } - - Map cast() => new TypeSafeMap(_base.cast()); - - void clear() { - _base.clear(); - } - - bool containsKey(Object key) => _base.containsKey(key); - - bool containsValue(Object value) => _base.containsValue(value); - - Iterable> get entries => _base.entries; - - void forEach(void f(K key, V value)) { - _base.forEach((key, value) => f(key as K, value as V)); - } - - bool get isEmpty => _base.isEmpty; - - bool get isNotEmpty => _base.isNotEmpty; - - Iterable get keys => new TypeSafeIterable(_base.keys); - - int get length => _base.length; - - Map map(dynamic transform(K key, V value)) { - return _base as dynamic; - } - - V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent) as V; - - V remove(Object key) => _base.remove(key) as V; - - void removeWhere(bool test(K key, V value)) => - _base.removeWhere((k, v) => test(k as K, v as V)); - - Map retype() => - new TypeSafeMap(_base.retype()); - - Iterable get values => new TypeSafeIterable(_base.values); - - String toString() => _base.toString(); - - V update(K key, V update(V value), {V ifAbsent()}) => - _base.update(key, (v) => update(v as V), ifAbsent: ifAbsent); - - void updateAll(V update(K key, V value)) => - _base.updateAll((k, v) => update(k, v)); -} diff --git a/lib/src/wrappers.dart b/lib/src/wrappers.dart index f210244..cfe97c7 100644 --- a/lib/src/wrappers.dart +++ b/lib/src/wrappers.dart @@ -5,7 +5,6 @@ import "dart:collection"; import "dart:math" as math; -import "typed_wrappers.dart"; import "unmodifiable_wrappers.dart"; typedef K _KeyForValue(V value); @@ -109,8 +108,8 @@ class DelegatingIterable extends _DelegatingIterableBase { /// This forwards all operations to [base], so any changes in [base] will be /// reflected in [this]. If [base] is already an `Iterable`, it's returned /// unmodified. - static Iterable typed(Iterable base) => - base is Iterable ? base : new TypeSafeIterable(base); + @Deprecated('Use iterable.cast instead.') + static Iterable typed(Iterable base) => base.cast(); } /// A [List] that delegates all operations to a base list. @@ -132,8 +131,8 @@ class DelegatingList extends DelegatingIterable implements List { /// This forwards all operations to [base], so any changes in [base] will be /// reflected in [this]. If [base] is already a `List`, it's returned /// unmodified. - static List typed(List base) => - base is List ? base : new TypeSafeList(base); + @Deprecated('Use list.cast instead.') + static List typed(List base) => base.cast(); List get _listBase => _base; @@ -263,8 +262,8 @@ class DelegatingSet extends DelegatingIterable implements Set { /// This forwards all operations to [base], so any changes in [base] will be /// reflected in [this]. If [base] is already a `Set`, it's returned /// unmodified. - static Set typed(Set base) => - base is Set ? base : new TypeSafeSet(base); + @Deprecated('Use set.cast instead.') + static Set typed(Set base) => base.cast(); Set get _setBase => _base; @@ -332,8 +331,8 @@ class DelegatingQueue extends DelegatingIterable implements Queue { /// This forwards all operations to [base], so any changes in [base] will be /// reflected in [this]. If [base] is already a `Queue`, it's returned /// unmodified. - static Queue typed(Queue base) => - base is Queue ? base : new TypeSafeQueue(base); + @Deprecated('Use queue.cast instead.') + static Queue typed(Queue base) => base.cast(); Queue get _baseQueue => _base; @@ -397,8 +396,8 @@ class DelegatingMap implements Map { /// This forwards all operations to [base], so any changes in [base] will be /// reflected in [this]. If [base] is already a `Map`, it's returned /// unmodified. - static Map typed(Map base) => - base is Map ? base : new TypeSafeMap(base); + @Deprecated('Use map.cast instead.') + static Map typed(Map base) => base.cast(); V operator [](Object key) => _base[key]; diff --git a/test/typed_wrapper/iterable_test.dart b/test/typed_wrapper/iterable_test.dart deleted file mode 100644 index a7662d1..0000000 --- a/test/typed_wrapper/iterable_test.dart +++ /dev/null @@ -1,354 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "package:collection/collection.dart"; -import "package:test/test.dart"; - -import '../utils.dart'; - -void main() { - group("with valid types, forwards", () { - var wrapper; - var emptyWrapper; - var singleWrapper; - setUp(() { - wrapper = - DelegatingIterable.typed([1, 2, 3, 4, 5].map((i) => i)); - emptyWrapper = DelegatingIterable.typed([].map((i) => i)); - singleWrapper = DelegatingIterable.typed([1].map((i) => i)); - }); - - test("any()", () { - expect(wrapper.any((i) => i > 3), isTrue); - expect(wrapper.any((i) => i > 5), isFalse); - }); - - test("contains()", () { - expect(wrapper.contains(2), isTrue); - expect(wrapper.contains(6), isFalse); - expect(wrapper.contains("foo"), isFalse); - }); - - test("elementAt()", () { - expect(wrapper.elementAt(1), equals(2)); - expect(wrapper.elementAt(4), equals(5)); - expect(() => wrapper.elementAt(5), throwsRangeError); - expect(() => wrapper.elementAt(-1), throwsRangeError); - }); - - test("every()", () { - expect(wrapper.every((i) => i < 6), isTrue); - expect(wrapper.every((i) => i > 3), isFalse); - }); - - test("expand()", () { - expect(wrapper.expand((i) => [i]), equals([1, 2, 3, 4, 5])); - expect(wrapper.expand((i) => [i, i]), - equals([1, 1, 2, 2, 3, 3, 4, 4, 5, 5])); - }); - - test("first", () { - expect(wrapper.first, equals(1)); - expect(() => emptyWrapper.first, throwsStateError); - }); - - test("firstWhere()", () { - expect(wrapper.firstWhere((i) => i > 3), equals(4)); - expect(() => wrapper.firstWhere((i) => i > 5), throwsStateError); - expect(wrapper.firstWhere((i) => i > 5, orElse: () => -1), equals(-1)); - }); - - test("fold()", () { - expect(wrapper.fold("", (previous, i) => previous + i.toString()), - equals("12345")); - expect(emptyWrapper.fold(null, (previous, i) => previous + i), isNull); - }); - - test("forEach()", () { - var results = []; - wrapper.forEach(results.add); - expect(results, equals([1, 2, 3, 4, 5])); - - emptyWrapper.forEach(expectAsync1((_) {}, count: 0)); - }); - - test("isEmpty", () { - expect(wrapper.isEmpty, isFalse); - expect(emptyWrapper.isEmpty, isTrue); - }); - - test("isNotEmpty", () { - expect(wrapper.isNotEmpty, isTrue); - expect(emptyWrapper.isNotEmpty, isFalse); - }); - - test("iterator", () { - var iterator = wrapper.iterator; - expect(iterator.current, isNull); - expect(iterator.moveNext(), isTrue); - expect(iterator.current, equals(1)); - expect(iterator.moveNext(), isTrue); - expect(iterator.current, equals(2)); - expect(iterator.moveNext(), isTrue); - expect(iterator.current, equals(3)); - expect(iterator.moveNext(), isTrue); - expect(iterator.current, equals(4)); - expect(iterator.moveNext(), isTrue); - expect(iterator.current, equals(5)); - expect(iterator.moveNext(), isFalse); - expect(iterator.current, isNull); - }); - - test("join()", () { - expect(wrapper.join(), "12345"); - expect(wrapper.join("-"), "1-2-3-4-5"); - }); - - test("last", () { - expect(wrapper.last, equals(5)); - expect(() => emptyWrapper.last, throwsStateError); - }); - - test("lastWhere()", () { - expect(wrapper.lastWhere((i) => i > 3), equals(5)); - expect(() => wrapper.lastWhere((i) => i > 5), throwsStateError); - expect(wrapper.lastWhere((i) => i > 5, orElse: () => -1), equals(-1)); - }); - - test("length", () { - expect(wrapper.length, equals(5)); - expect(emptyWrapper.length, equals(0)); - }); - - test("map()", () { - expect(wrapper.map((i) => i + 1), equals([2, 3, 4, 5, 6])); - expect(wrapper.map((i) => i / 2), equals([0.5, 1.0, 1.5, 2.0, 2.5])); - }); - - test("reduce()", () { - expect(wrapper.reduce((value, i) => value + i), equals(15)); - expect( - () => emptyWrapper.reduce((value, i) => value + i), throwsStateError); - }); - - test("single", () { - expect(() => wrapper.single, throwsStateError); - expect(singleWrapper.single, equals(1)); - }); - - test("singleWhere()", () { - expect(() => wrapper.singleWhere((i) => i.isOdd), throwsStateError); - expect(singleWrapper.singleWhere((i) => i.isOdd), equals(1)); - expect( - () => singleWrapper.singleWhere((i) => i.isEven), throwsStateError); - }); - - test("skip()", () { - expect(wrapper.skip(3), equals([4, 5])); - expect(wrapper.skip(10), isEmpty); - expect(() => wrapper.skip(-1), throwsRangeError); - }); - - test("skipWhile()", () { - expect(wrapper.skipWhile((i) => i < 3), equals([3, 4, 5])); - expect(wrapper.skipWhile((i) => i < 10), isEmpty); - }); - - test("take()", () { - expect(wrapper.take(3), equals([1, 2, 3])); - expect(wrapper.take(10), equals([1, 2, 3, 4, 5])); - expect(() => wrapper.take(-1), throwsRangeError); - }); - - test("takeWhile()", () { - expect(wrapper.takeWhile((i) => i < 3), equals([1, 2])); - expect(wrapper.takeWhile((i) => i < 10), equals([1, 2, 3, 4, 5])); - }); - - test("toList()", () { - expect(wrapper.toList(), equals([1, 2, 3, 4, 5])); - expect(wrapper.toList(growable: false), equals([1, 2, 3, 4, 5])); - expect( - () => wrapper.toList(growable: false).add(6), throwsUnsupportedError); - }); - - test("toSet()", () { - expect(wrapper.toSet(), unorderedEquals([1, 2, 3, 4, 5])); - expect(DelegatingIterable.typed([1, 1, 2, 2]).toSet(), - unorderedEquals([1, 2])); - }); - - test("where()", () { - expect(wrapper.where((i) => i.isOdd), equals([1, 3, 5])); - expect(wrapper.where((i) => i.isEven), equals([2, 4])); - }); - - test("toString()", () { - expect(wrapper.toString(), equals("(1, 2, 3, 4, 5)")); - expect(emptyWrapper.toString(), equals("()")); - }); - }); - - group("with invalid types", () { - var wrapper; - var singleWrapper; - setUp(() { - wrapper = DelegatingIterable - .typed(["foo", "bar", "baz"].map((element) => element)); - singleWrapper = DelegatingIterable - .typed(["foo"].map((element) => element)); - }); - - group("throws a CastError for", () { - test("any()", () { - expect(() => wrapper.any(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("elementAt()", () { - expect(() => wrapper.elementAt(1), throwsCastError); - }); - - test("every()", () { - expect(() => wrapper.every(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("expand()", () { - var lazy = wrapper.expand(expectAsync1((_) => [], count: 0)); - expect(() => lazy.first, throwsCastError); - }); - - test("first", () { - expect(() => wrapper.first, throwsCastError); - }); - - test("firstWhere()", () { - expect(() => wrapper.firstWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("fold()", () { - expect( - () => wrapper.fold(null, expectAsync2((_, __) => null, count: 0)), - throwsCastError); - }); - - test("forEach()", () { - expect(() => wrapper.forEach(expectAsync1((_) {}, count: 0)), - throwsCastError); - }); - - test("iterator", () { - var iterator = wrapper.iterator; - expect(iterator.current, isNull); - expect(() => iterator.moveNext(), throwsCastError); - }); - - test("last", () { - expect(() => wrapper.last, throwsCastError); - }); - - test("lastWhere()", () { - expect(() => wrapper.lastWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("map()", () { - var lazy = wrapper.map(expectAsync1((_) => null, count: 0)); - expect(() => lazy.first, throwsCastError); - }); - - test("reduce()", () { - expect(() => wrapper.reduce(expectAsync2((_, __) => null, count: 0)), - throwsCastError); - }); - - test("single", () { - expect(() => singleWrapper.single, throwsCastError); - }); - - test("singleWhere()", () { - expect(() { - singleWrapper.singleWhere(expectAsync1((_) => false, count: 0)); - }, throwsCastError); - }); - - test("skip()", () { - var lazy = wrapper.skip(1); - expect(() => lazy.first, throwsCastError); - }); - - test("skipWhile()", () { - var lazy = wrapper.skipWhile(expectAsync1((_) => false, count: 0)); - expect(() => lazy.first, throwsCastError); - }); - - test("take()", () { - var lazy = wrapper.take(1); - expect(() => lazy.first, throwsCastError); - }); - - test("takeWhile()", () { - var lazy = wrapper.takeWhile(expectAsync1((_) => false, count: 0)); - expect(() => lazy.first, throwsCastError); - }); - - test("toList()", () { - var list = wrapper.toList(); - expect(() => list.first, throwsCastError); - }); - - test("toSet()", () { - var asSet = wrapper.toSet(); - expect(() => asSet.first, throwsCastError); - }); - - test("where()", () { - var lazy = wrapper.where(expectAsync1((_) => false, count: 0)); - expect(() => lazy.first, throwsCastError); - }); - }); - - group("doesn't throw a CastError for", () { - test("contains()", () { - expect(wrapper.contains(1), isFalse); - expect(wrapper.contains("foo"), isTrue); - }); - - test("elementAt()", () { - expect(() => wrapper.elementAt(-1), throwsRangeError); - expect(() => wrapper.elementAt(10), throwsRangeError); - }); - - test("isEmpty", () { - expect(wrapper.isEmpty, isFalse); - }); - - test("isNotEmpty", () { - expect(wrapper.isNotEmpty, isTrue); - }); - - test("join()", () { - expect(wrapper.join(), "foobarbaz"); - }); - - test("length", () { - expect(wrapper.length, equals(3)); - }); - - test("single", () { - expect(() => wrapper.single, throwsStateError); - }); - - test("skip()", () { - expect(() => wrapper.skip(-1), throwsRangeError); - }); - - test("toString()", () { - expect(wrapper.toString(), equals("(foo, bar, baz)")); - }); - }); - }, skip: isDart2 ? false : 'Requires a Dart2 runtime'); -} diff --git a/test/typed_wrapper/list_test.dart b/test/typed_wrapper/list_test.dart deleted file mode 100644 index fcb784a..0000000 --- a/test/typed_wrapper/list_test.dart +++ /dev/null @@ -1,421 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:math' as math; - -import "package:collection/collection.dart"; -import "package:test/test.dart"; - -import '../utils.dart'; - -void main() { - group("with valid types, forwards", () { - var wrapper; - var emptyWrapper; - setUp(() { - wrapper = DelegatingList.typed([1, 2, 3, 4, 5]); - emptyWrapper = DelegatingList.typed([]); - }); - - test("[]", () { - expect(wrapper[0], equals(1)); - expect(wrapper[1], equals(2)); - expect(() => wrapper[-1], throwsRangeError); - expect(() => wrapper[10], throwsRangeError); - }); - - test("[]=", () { - wrapper[1] = 10; - wrapper[3] = 15; - expect(wrapper, equals([1, 10, 3, 15, 5])); - expect(() => wrapper[-1] = 10, throwsRangeError); - expect(() => wrapper[10] = 10, throwsRangeError); - }); - - test("add()", () { - wrapper.add(6); - wrapper.add(7); - expect(wrapper, equals([1, 2, 3, 4, 5, 6, 7])); - }); - - test("addAll()", () { - wrapper.addAll([6, 7, 8]); - expect(wrapper, equals([1, 2, 3, 4, 5, 6, 7, 8])); - }); - - test("asMap()", () { - expect(wrapper.asMap(), equals({0: 1, 1: 2, 2: 3, 3: 4, 4: 5})); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("fillRange()", () { - wrapper.fillRange(2, 4); - expect(wrapper, equals([1, 2, null, null, 5])); - - wrapper.fillRange(1, 2, 7); - expect(wrapper, equals([1, 7, null, null, 5])); - - expect(() => wrapper.fillRange(-1, 2), throwsRangeError); - expect(() => wrapper.fillRange(1, 10), throwsRangeError); - expect(() => wrapper.fillRange(4, 2), throwsRangeError); - expect(() => wrapper.fillRange(10, 12), throwsRangeError); - }); - - test("getRange()", () { - expect(wrapper.getRange(2, 4), equals([3, 4])); - expect(wrapper.getRange(1, 2), equals([2])); - - expect(() => wrapper.getRange(-1, 2), throwsRangeError); - expect(() => wrapper.getRange(1, 10), throwsRangeError); - expect(() => wrapper.getRange(4, 2), throwsRangeError); - expect(() => wrapper.getRange(10, 12), throwsRangeError); - }); - - test("indexOf()", () { - expect(wrapper.indexOf(4), equals(3)); - expect(wrapper.indexOf(10), equals(-1)); - expect(wrapper.indexOf(4, 2), equals(3)); - expect(wrapper.indexOf(4, 4), equals(-1)); - }); - - test("insert()", () { - wrapper.insert(3, 10); - expect(wrapper, equals([1, 2, 3, 10, 4, 5])); - - wrapper.insert(0, 15); - expect(wrapper, equals([15, 1, 2, 3, 10, 4, 5])); - - expect(() => wrapper.insert(-1, 0), throwsRangeError); - expect(() => wrapper.insert(10, 0), throwsRangeError); - }); - - test("insertAll()", () { - wrapper.insertAll(3, [10, 11, 12]); - expect(wrapper, equals([1, 2, 3, 10, 11, 12, 4, 5])); - - wrapper.insertAll(0, [15, 16, 17]); - expect(wrapper, equals([15, 16, 17, 1, 2, 3, 10, 11, 12, 4, 5])); - - expect(() => wrapper.insertAll(-1, []), throwsRangeError); - expect(() => wrapper.insertAll(100, []), throwsRangeError); - }); - - test("lastIndexOf()", () { - expect(wrapper.lastIndexOf(4), equals(3)); - expect(wrapper.lastIndexOf(10), equals(-1)); - expect(wrapper.lastIndexOf(4, 4), equals(3)); - expect(wrapper.lastIndexOf(4, 2), equals(-1)); - }); - - test("length=", () { - wrapper.length = 10; - expect(wrapper, equals([1, 2, 3, 4, 5, null, null, null, null, null])); - - wrapper.length = 3; - expect(wrapper, equals([1, 2, 3])); - }); - - test("remove()", () { - expect(wrapper.remove(3), isTrue); - expect(wrapper, equals([1, 2, 4, 5])); - - expect(wrapper.remove(3), isFalse); - expect(wrapper.remove("foo"), isFalse); - }); - - test("removeAt()", () { - expect(wrapper.removeAt(3), equals(4)); - expect(wrapper, equals([1, 2, 3, 5])); - - expect(() => wrapper.removeAt(-1), throwsRangeError); - expect(() => wrapper.removeAt(10), throwsRangeError); - }); - - test("removeLast()", () { - expect(wrapper.removeLast(), equals(5)); - expect(wrapper, equals([1, 2, 3, 4])); - - // See sdk#26087. We want this to pass with the current implementation and - // with the fix. - expect(() => emptyWrapper.removeLast(), - anyOf(throwsStateError, throwsRangeError)); - }); - - test("removeRange()", () { - wrapper.removeRange(2, 4); - expect(wrapper, equals([1, 2, 5])); - - expect(() => wrapper.removeRange(-1, 2), throwsRangeError); - expect(() => wrapper.removeRange(1, 10), throwsRangeError); - expect(() => wrapper.removeRange(4, 2), throwsRangeError); - expect(() => wrapper.removeRange(10, 12), throwsRangeError); - }); - - test("removeWhere()", () { - wrapper.removeWhere((i) => i.isOdd); - expect(wrapper, equals([2, 4])); - }); - - test("replaceRange()", () { - wrapper.replaceRange(2, 4, [10, 11, 12]); - expect(wrapper, equals([1, 2, 10, 11, 12, 5])); - - expect(() => wrapper.replaceRange(-1, 2, []), throwsRangeError); - expect(() => wrapper.replaceRange(1, 10, []), throwsRangeError); - expect(() => wrapper.replaceRange(4, 2, []), throwsRangeError); - expect(() => wrapper.replaceRange(10, 12, []), throwsRangeError); - }); - - test("retainWhere()", () { - wrapper.retainWhere((i) => i.isOdd); - expect(wrapper, equals([1, 3, 5])); - }); - - test("reversed", () { - expect(wrapper.reversed, equals([5, 4, 3, 2, 1])); - }); - - test("setAll()", () { - wrapper.setAll(2, [10, 11]); - expect(wrapper, equals([1, 2, 10, 11, 5])); - - expect(() => wrapper.setAll(-1, []), throwsRangeError); - expect(() => wrapper.setAll(10, []), throwsRangeError); - }); - - test("setRange()", () { - wrapper.setRange(2, 4, [10, 11, 12]); - expect(wrapper, equals([1, 2, 10, 11, 5])); - - wrapper.setRange(2, 4, [10, 11, 12], 1); - expect(wrapper, equals([1, 2, 11, 12, 5])); - - expect(() => wrapper.setRange(-1, 2, []), throwsRangeError); - expect(() => wrapper.setRange(1, 10, []), throwsRangeError); - expect(() => wrapper.setRange(4, 2, []), throwsRangeError); - expect(() => wrapper.setRange(10, 12, []), throwsRangeError); - expect(() => wrapper.setRange(2, 4, []), throwsStateError); - }); - - test("shuffle()", () { - wrapper.shuffle(new math.Random(1234)); - expect(wrapper, equals([1, 2, 3, 4, 5]..shuffle(new math.Random(1234)))); - }); - - test("sort()", () { - wrapper.sort((a, b) => b.compareTo(a)); - expect(wrapper, equals([5, 4, 3, 2, 1])); - - wrapper.sort(); - expect(wrapper, equals([1, 2, 3, 4, 5])); - }); - - test("sublist()", () { - expect(wrapper.sublist(2), equals([3, 4, 5])); - expect(wrapper.sublist(2, 4), equals([3, 4])); - }); - }); - - group("with invalid types", () { - List inner; - var wrapper; - setUp(() { - inner = ["foo", "bar", "baz"]; - wrapper = DelegatingList.typed(inner); - }); - - group("throws a CastError for", () { - test("[]", () { - expect(() => wrapper[0], throwsCastError); - }); - - test("asMap()", () { - var map = wrapper.asMap(); - expect(() => map[1], throwsCastError); - }); - - test("getRange()", () { - var lazy = wrapper.getRange(1, 2); - expect(() => lazy.first, throwsCastError); - }); - - test("removeAt()", () { - expect(() => wrapper.removeAt(2), throwsCastError); - }); - - test("removeLast()", () { - expect(() => wrapper.removeLast(), throwsCastError); - }); - - test("removeWhere()", () { - expect(() => wrapper.removeWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("retainWhere()", () { - expect(() => wrapper.retainWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("reversed", () { - var lazy = wrapper.reversed; - expect(() => lazy.first, throwsCastError); - }); - - test("sort()", () { - expect(() => wrapper.sort(expectAsync2((_, __) => 0, count: 0)), - throwsCastError); - }); - - test("sublist()", () { - var list = wrapper.sublist(1); - expect(() => list[0], throwsCastError); - }); - }); - - group("doesn't throw a CastError for", () { - test("[]", () { - expect(() => wrapper[-1], throwsRangeError); - expect(() => wrapper[10], throwsRangeError); - }); - - test("[]=", () { - wrapper[1] = 10; - expect(inner, equals(["foo", 10, "baz"])); - expect(() => wrapper[-1] = 10, throwsRangeError); - expect(() => wrapper[10] = 10, throwsRangeError); - }); - - test("add()", () { - wrapper.add(6); - wrapper.add(7); - expect(inner, equals(["foo", "bar", "baz", 6, 7])); - }); - - test("addAll()", () { - wrapper.addAll([6, 7, 8]); - expect(inner, equals(["foo", "bar", "baz", 6, 7, 8])); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("fillRange()", () { - wrapper.fillRange(1, 3, 7); - expect(inner, equals(["foo", 7, 7])); - - expect(() => wrapper.fillRange(-1, 2), throwsRangeError); - expect(() => wrapper.fillRange(1, 10), throwsRangeError); - expect(() => wrapper.fillRange(4, 2), throwsRangeError); - expect(() => wrapper.fillRange(10, 12), throwsRangeError); - }); - - test("getRange()", () { - expect(() => wrapper.getRange(-1, 2), throwsRangeError); - expect(() => wrapper.getRange(1, 10), throwsRangeError); - expect(() => wrapper.getRange(4, 2), throwsRangeError); - expect(() => wrapper.getRange(10, 12), throwsRangeError); - }); - - test("indexOf()", () { - expect(wrapper.indexOf(4), equals(-1)); - }); - - test("insert()", () { - wrapper.insert(0, 15); - expect(inner, equals([15, "foo", "bar", "baz"])); - - expect(() => wrapper.insert(-1, 0), throwsRangeError); - expect(() => wrapper.insert(10, 0), throwsRangeError); - }); - - test("insertAll()", () { - wrapper.insertAll(0, [15, 16, 17]); - expect(inner, equals([15, 16, 17, "foo", "bar", "baz"])); - - expect(() => wrapper.insertAll(-1, []), throwsRangeError); - expect(() => wrapper.insertAll(100, []), throwsRangeError); - }); - - test("lastIndexOf()", () { - expect(wrapper.lastIndexOf(4), equals(-1)); - }); - - test("length=", () { - wrapper.length = 5; - expect(inner, equals(["foo", "bar", "baz", null, null])); - - wrapper.length = 1; - expect(inner, equals(["foo"])); - }); - - test("remove()", () { - expect(wrapper.remove(3), isFalse); - expect(wrapper.remove("foo"), isTrue); - expect(inner, equals(["bar", "baz"])); - }); - - test("removeAt()", () { - expect(() => wrapper.removeAt(-1), throwsRangeError); - expect(() => wrapper.removeAt(10), throwsRangeError); - }); - - test("removeRange()", () { - wrapper.removeRange(1, 3); - expect(inner, equals(["foo"])); - - expect(() => wrapper.removeRange(-1, 2), throwsRangeError); - expect(() => wrapper.removeRange(1, 10), throwsRangeError); - expect(() => wrapper.removeRange(4, 2), throwsRangeError); - expect(() => wrapper.removeRange(10, 12), throwsRangeError); - }); - - test("replaceRange()", () { - wrapper.replaceRange(1, 2, [10, 11, 12]); - expect(inner, equals(["foo", 10, 11, 12, "baz"])); - - expect(() => wrapper.replaceRange(-1, 2, []), throwsRangeError); - expect(() => wrapper.replaceRange(1, 10, []), throwsRangeError); - expect(() => wrapper.replaceRange(4, 2, []), throwsRangeError); - expect(() => wrapper.replaceRange(10, 12, []), throwsRangeError); - }); - - test("setAll()", () { - wrapper.setAll(1, [10, 11]); - expect(inner, equals(["foo", 10, 11])); - - expect(() => wrapper.setAll(-1, []), throwsRangeError); - expect(() => wrapper.setAll(10, []), throwsRangeError); - }); - - test("setRange()", () { - wrapper.setRange(1, 2, [10, 11, 12]); - expect(inner, equals(["foo", 10, "baz"])); - - expect(() => wrapper.setRange(-1, 2, []), throwsRangeError); - expect(() => wrapper.setRange(1, 10, []), throwsRangeError); - expect(() => wrapper.setRange(4, 2, []), throwsRangeError); - expect(() => wrapper.setRange(10, 12, []), throwsRangeError); - expect(() => wrapper.setRange(1, 2, []), throwsStateError); - }); - - test("shuffle()", () { - wrapper.shuffle(new math.Random(1234)); - expect(inner, - equals(["foo", "bar", "baz"]..shuffle(new math.Random(1234)))); - }); - - test("sort()", () { - wrapper.sort(); - expect(inner, equals(["bar", "baz", "foo"])); - }); - }); - }, skip: isDart2 ? false : 'Requires a Dart2 runtime'); -} diff --git a/test/typed_wrapper/map_test.dart b/test/typed_wrapper/map_test.dart deleted file mode 100644 index 96ccf17..0000000 --- a/test/typed_wrapper/map_test.dart +++ /dev/null @@ -1,327 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "package:collection/collection.dart"; -import "package:test/test.dart"; - -import '../utils.dart'; - -void main() { - group("with valid types, forwards", () { - var wrapper; - var emptyWrapper; - setUp(() { - wrapper = DelegatingMap.typed( - {"foo": 1, "bar": 2, "baz": 3, "bang": 4}); - emptyWrapper = DelegatingMap.typed({}); - }); - - test("[]", () { - expect(wrapper["foo"], equals(1)); - expect(wrapper["bar"], equals(2)); - expect(wrapper["qux"], isNull); - expect(wrapper[1], isNull); - }); - - test("[]=", () { - wrapper["foo"] = 5; - expect(wrapper, equals({"foo": 5, "bar": 2, "baz": 3, "bang": 4})); - - wrapper["qux"] = 6; - expect( - wrapper, equals({"foo": 5, "bar": 2, "baz": 3, "bang": 4, "qux": 6})); - }); - - test("addAll()", () { - wrapper.addAll({"bar": 5, "qux": 6}); - expect( - wrapper, equals({"foo": 1, "bar": 5, "baz": 3, "bang": 4, "qux": 6})); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("containsKey()", () { - expect(wrapper.containsKey("foo"), isTrue); - expect(wrapper.containsKey("qux"), isFalse); - expect(wrapper.containsKey(1), isFalse); - }); - - test("containsValue()", () { - expect(wrapper.containsValue(1), isTrue); - expect(wrapper.containsValue(7), isFalse); - expect(wrapper.containsValue("foo"), isFalse); - }); - - test("forEach()", () { - var results = []; - wrapper.forEach((key, value) => results.add([key, value])); - expect( - results, - unorderedEquals([ - ["foo", 1], - ["bar", 2], - ["baz", 3], - ["bang", 4] - ])); - - emptyWrapper.forEach(expectAsync2((_, __) {}, count: 0)); - }); - - test("isEmpty", () { - expect(wrapper.isEmpty, isFalse); - expect(emptyWrapper.isEmpty, isTrue); - }); - - test("isNotEmpty", () { - expect(wrapper.isNotEmpty, isTrue); - expect(emptyWrapper.isNotEmpty, isFalse); - }); - - test("keys", () { - expect(wrapper.keys, unorderedEquals(["foo", "bar", "baz", "bang"])); - expect(emptyWrapper.keys, isEmpty); - }); - - test("length", () { - expect(wrapper.length, equals(4)); - expect(emptyWrapper.length, equals(0)); - }); - - test("putIfAbsent()", () { - expect(wrapper.putIfAbsent("foo", expectAsync1((_) => null, count: 0)), - equals(1)); - - expect(wrapper.putIfAbsent("qux", () => 6), equals(6)); - expect( - wrapper, equals({"foo": 1, "bar": 2, "baz": 3, "bang": 4, "qux": 6})); - }); - - test("remove()", () { - expect(wrapper.remove("foo"), equals(1)); - expect(wrapper, equals({"bar": 2, "baz": 3, "bang": 4})); - - expect(wrapper.remove("foo"), isNull); - expect(wrapper.remove(3), isNull); - }); - - test("values", () { - expect(wrapper.values, unorderedEquals([1, 2, 3, 4])); - expect(emptyWrapper.values, isEmpty); - }); - - test("toString()", () { - expect( - wrapper.toString(), - allOf([ - startsWith("{"), - contains("foo: 1"), - contains("bar: 2"), - contains("baz: 3"), - contains("bang: 4"), - endsWith("}") - ])); - }); - }); - - group("with invalid key types", () { - Map inner; - var wrapper; - setUp(() { - inner = {1: 1, 2: 2, 3: 3, 4: 4}; - wrapper = DelegatingMap.typed(inner); - }); - - group("throws a CastError for", () { - test("forEach()", () { - expect(() => wrapper.forEach(expectAsync2((_, __) {}, count: 0)), - throwsCastError); - }); - - test("keys", () { - var lazy = wrapper.keys; - expect(() => lazy.first, throwsCastError); - }); - }); - - group("doesn't throw a CastError for", () { - test("[]", () { - expect(wrapper["foo"], isNull); - expect(wrapper[1], equals(1)); - expect(wrapper[7], isNull); - }); - - test("[]=", () { - wrapper["foo"] = 5; - expect(inner, equals({"foo": 5, 1: 1, 2: 2, 3: 3, 4: 4})); - }); - - test("addAll()", () { - wrapper.addAll({"foo": 1, "bar": 2}); - expect(inner, equals({"foo": 1, "bar": 2, 1: 1, 2: 2, 3: 3, 4: 4})); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("containsKey()", () { - expect(wrapper.containsKey(1), isTrue); - expect(wrapper.containsKey(7), isFalse); - expect(wrapper.containsKey("foo"), isFalse); - }); - - test("containsValue()", () { - expect(wrapper.containsValue(1), isTrue); - expect(wrapper.containsValue(7), isFalse); - expect(wrapper.containsValue("foo"), isFalse); - }); - - test("isEmpty", () { - expect(wrapper.isEmpty, isFalse); - }); - - test("isNotEmpty", () { - expect(wrapper.isNotEmpty, isTrue); - }); - - test("length", () { - expect(wrapper.length, equals(4)); - }); - - test("putIfAbsent()", () { - expect(wrapper.putIfAbsent("foo", () => 1), equals(1)); - expect(inner, equals({"foo": 1, 1: 1, 2: 2, 3: 3, 4: 4})); - }); - - test("remove()", () { - expect(wrapper.remove(1), equals(1)); - expect(inner, equals({2: 2, 3: 3, 4: 4})); - - expect(wrapper.remove("foo"), isNull); - expect(wrapper.remove(7), isNull); - }); - - test("values", () { - expect(wrapper.values, unorderedEquals([1, 2, 3, 4])); - }); - - test("toString()", () { - expect( - wrapper.toString(), - allOf([ - startsWith("{"), - contains("1: 1"), - contains("2: 2"), - contains("3: 3"), - contains("4: 4"), - endsWith("}") - ])); - }); - }); - }, skip: isDart2 ? false : 'Requires a Dart2 runtime'); - - group("with invalid value types", () { - Map inner; - var wrapper; - setUp(() { - inner = {"foo": "bar", "baz": "bang"}; - wrapper = DelegatingMap.typed(inner); - }); - - group("throws a CastError for", () { - test("forEach()", () { - expect(() => wrapper.forEach(expectAsync2((_, __) {}, count: 0)), - throwsCastError); - }); - - test("[]", () { - expect(() => wrapper["foo"], throwsCastError); - expect(wrapper["qux"], isNull); - }); - - test("putIfAbsent()", () { - expect(() => wrapper.putIfAbsent("foo", () => 1), throwsCastError); - }); - - test("remove()", () { - expect(() => wrapper.remove("foo"), throwsCastError); - }); - - test("values", () { - var lazy = wrapper.values; - expect(() => lazy.first, throwsCastError); - }); - }); - - group("doesn't throw a CastError for", () { - test("[]=", () { - wrapper["foo"] = 5; - expect(inner, equals({"foo": 5, "baz": "bang"})); - }); - - test("addAll()", () { - wrapper.addAll({"foo": 1, "qux": 2}); - expect(inner, equals({"foo": 1, "baz": "bang", "qux": 2})); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("containsKey()", () { - expect(wrapper.containsKey("foo"), isTrue); - expect(wrapper.containsKey(1), isFalse); - expect(wrapper.containsKey("qux"), isFalse); - }); - - test("containsValue()", () { - expect(wrapper.containsValue("bar"), isTrue); - expect(wrapper.containsValue(1), isFalse); - expect(wrapper.containsValue("foo"), isFalse); - }); - - test("isEmpty", () { - expect(wrapper.isEmpty, isFalse); - }); - - test("isNotEmpty", () { - expect(wrapper.isNotEmpty, isTrue); - }); - - test("keys", () { - expect(wrapper.keys, unorderedEquals(["foo", "baz"])); - }); - - test("length", () { - expect(wrapper.length, equals(2)); - }); - - test("putIfAbsent()", () { - expect(wrapper.putIfAbsent("qux", () => 1), equals(1)); - expect(inner, equals({"foo": "bar", "baz": "bang", "qux": 1})); - }); - - test("remove()", () { - expect(wrapper.remove("qux"), isNull); - expect(wrapper.remove(7), isNull); - }); - - test("toString()", () { - expect( - wrapper.toString(), - allOf([ - startsWith("{"), - contains("foo: bar"), - contains("baz: bang"), - endsWith("}") - ])); - }); - }); - }, skip: isDart2 ? false : 'Requires a Dart2 runtime'); -} diff --git a/test/typed_wrapper/queue_test.dart b/test/typed_wrapper/queue_test.dart deleted file mode 100644 index 0a716fe..0000000 --- a/test/typed_wrapper/queue_test.dart +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "dart:collection"; - -import "package:collection/collection.dart"; -import "package:test/test.dart"; - -import '../utils.dart'; - -void main() { - group("with valid types, forwards", () { - var wrapper; - var emptyWrapper; - setUp(() { - wrapper = - DelegatingQueue.typed(new Queue.from([1, 2, 3, 4, 5])); - emptyWrapper = DelegatingQueue.typed(new Queue()); - }); - - test("add()", () { - wrapper.add(6); - wrapper.add(7); - expect(wrapper, equals([1, 2, 3, 4, 5, 6, 7])); - }); - - test("addAll()", () { - wrapper.addAll([6, 7, 8]); - expect(wrapper, equals([1, 2, 3, 4, 5, 6, 7, 8])); - }); - - test("addFirst()", () { - wrapper.addFirst(6); - wrapper.addFirst(7); - expect(wrapper, equals([7, 6, 1, 2, 3, 4, 5])); - }); - - test("addLast()", () { - wrapper.addLast(6); - wrapper.addLast(7); - expect(wrapper, equals([1, 2, 3, 4, 5, 6, 7])); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("remove()", () { - expect(wrapper.remove(3), isTrue); - expect(wrapper, equals([1, 2, 4, 5])); - - expect(wrapper.remove(3), isFalse); - expect(wrapper.remove("foo"), isFalse); - }); - - test("removeWhere()", () { - wrapper.removeWhere((i) => i.isOdd); - expect(wrapper, equals([2, 4])); - }); - - test("retainWhere()", () { - wrapper.retainWhere((i) => i.isOdd); - expect(wrapper, equals([1, 3, 5])); - }); - - test("removeLast()", () { - expect(wrapper.removeLast(), equals(5)); - expect(wrapper, equals([1, 2, 3, 4])); - - expect(() => emptyWrapper.removeLast(), throwsStateError); - }); - - test("removeFirst()", () { - expect(wrapper.removeFirst(), equals(1)); - expect(wrapper, equals([2, 3, 4, 5])); - - expect(() => emptyWrapper.removeFirst(), throwsStateError); - }); - }); - - group("with invalid types", () { - Queue inner; - var wrapper; - setUp(() { - inner = new Queue.from(["foo", "bar", "baz"]); - wrapper = DelegatingQueue.typed(inner); - }); - - group("throws a CastError for", () { - test("removeLast()", () { - expect(() => wrapper.removeLast(), throwsCastError); - }); - - test("removeFirst()", () { - expect(() => wrapper.removeFirst(), throwsCastError); - }); - - test("removeWhere()", () { - expect(() => wrapper.removeWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("retainWhere()", () { - expect(() => wrapper.retainWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - }); - - group("doesn't throw a CastError for", () { - test("add()", () { - wrapper.add(6); - wrapper.add(7); - expect(inner, equals(["foo", "bar", "baz", 6, 7])); - }); - - test("addAll()", () { - wrapper.addAll([6, 7, 8]); - expect(inner, equals(["foo", "bar", "baz", 6, 7, 8])); - }); - - test("addFirst()", () { - wrapper.addFirst(6); - wrapper.addFirst(7); - expect(inner, equals([7, 6, "foo", "bar", "baz"])); - }); - - test("addLast()", () { - wrapper.addLast(6); - wrapper.addLast(7); - expect(inner, equals(["foo", "bar", "baz", 6, 7])); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - }); - }, skip: isDart2 ? false : 'Requires a Dart2 runtime'); -} diff --git a/test/typed_wrapper/set_test.dart b/test/typed_wrapper/set_test.dart deleted file mode 100644 index 37e3cd3..0000000 --- a/test/typed_wrapper/set_test.dart +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "package:collection/collection.dart"; -import "package:test/test.dart"; - -import '../utils.dart'; - -void main() { - group("with valid types, forwards", () { - var wrapper; - setUp(() { - wrapper = DelegatingSet.typed(new Set.from([1, 2, 3, 4, 5])); - }); - - test("add()", () { - wrapper.add(1); - wrapper.add(6); - expect(wrapper, unorderedEquals([1, 2, 3, 4, 5, 6])); - }); - - test("addAll()", () { - wrapper.addAll([1, 6, 7]); - expect(wrapper, unorderedEquals([1, 2, 3, 4, 5, 6, 7])); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("containsAll()", () { - expect(wrapper.containsAll([1, 3, 5]), isTrue); - expect(wrapper.containsAll([1, 3, 6]), isFalse); - expect(wrapper.containsAll([1, 3, "foo"]), isFalse); - }); - - test("difference()", () { - expect(wrapper.difference(new Set.from([1, 3, 6])), - unorderedEquals([2, 4, 5])); - }); - - test("intersection()", () { - expect(wrapper.intersection(new Set.from([1, 3, 6, "foo"])), - unorderedEquals([1, 3])); - }); - - test("lookup()", () { - expect(wrapper.lookup(1), equals(1)); - expect(wrapper.lookup(7), isNull); - expect(wrapper.lookup("foo"), isNull); - }); - - test("remove()", () { - expect(wrapper.remove(3), isTrue); - expect(wrapper, unorderedEquals([1, 2, 4, 5])); - - expect(wrapper.remove(3), isFalse); - expect(wrapper.remove("foo"), isFalse); - }); - - test("removeAll()", () { - wrapper.removeAll([1, 3, 6, "foo"]); - expect(wrapper, unorderedEquals([2, 4, 5])); - }); - - test("removeWhere()", () { - wrapper.removeWhere((i) => i.isOdd); - expect(wrapper, unorderedEquals([2, 4])); - }); - - test("retainAll()", () { - wrapper.retainAll([1, 3, 6, "foo"]); - expect(wrapper, unorderedEquals([1, 3])); - }); - - test("retainWhere()", () { - wrapper.retainWhere((i) => i.isOdd); - expect(wrapper, unorderedEquals([1, 3, 5])); - }); - - test("union()", () { - expect(wrapper.union(new Set.from([5, 6, 7])), - unorderedEquals([1, 2, 3, 4, 5, 6, 7])); - }); - }); - - group("with invalid types", () { - Set inner; - var wrapper; - setUp(() { - inner = new Set.from(["foo", "bar", "baz"]); - wrapper = DelegatingSet.typed(inner); - }); - - group("throws a CastError for", () { - test("difference()", () { - var result = wrapper.difference(new Set.from([1, 3, 6])); - expect(() => result.first, throwsCastError); - }); - - test("intersection()", () { - var result = wrapper.intersection(new Set.from([1, 3, 6, "foo"])); - expect(() => result.first, throwsCastError); - }); - - test("lookup()", () { - expect(() => wrapper.lookup("foo"), throwsCastError); - }); - - test("removeWhere()", () { - expect(() => wrapper.removeWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("retainWhere()", () { - expect(() => wrapper.retainWhere(expectAsync1((_) => false, count: 0)), - throwsCastError); - }); - - test("union()", () { - var result = wrapper.union(new Set.from([5, 6, 7])); - expect(() => result.first, throwsCastError); - }); - }); - - group("doesn't throw a CastError for", () { - test("add()", () { - wrapper.add(6); - expect(inner, unorderedEquals(["foo", "bar", "baz", 6])); - }); - - test("addAll()", () { - wrapper.addAll([6, 7]); - expect(inner, unorderedEquals(["foo", "bar", "baz", 6, 7])); - }); - - test("clear()", () { - wrapper.clear(); - expect(wrapper, isEmpty); - }); - - test("containsAll()", () { - expect(wrapper.containsAll(["foo", "bar"]), isTrue); - expect(wrapper.containsAll(["foo", "bar", 1]), isFalse); - }); - - test("lookup()", () { - expect(wrapper.lookup(1), isNull); - expect(wrapper.lookup("zap"), isNull); - }); - - test("remove()", () { - expect(wrapper.remove("foo"), isTrue); - expect(inner, unorderedEquals(["bar", "baz"])); - - expect(wrapper.remove(3), isFalse); - expect(wrapper.remove("foo"), isFalse); - }); - - test("removeAll()", () { - wrapper.removeAll([1, "foo", "baz"]); - expect(inner, unorderedEquals(["bar"])); - }); - - test("retainAll()", () { - wrapper.retainAll([1, "foo", "baz"]); - expect(inner, unorderedEquals(["foo", "baz"])); - }); - }); - }, skip: isDart2 ? false : 'Requires a Dart2 runtime'); -} From 3a2186485cb328cf19cceda9744f93e47ad6b8d7 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 12 Mar 2018 21:27:51 -0700 Subject: [PATCH 2/2] Address feedback. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d82dbb..cab5521 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ ## 1.14.8 * Deprecated `Delegating{Name}.typed` static methods in favor of the new Dart 2 - `cast` methods. For example, `DelegatingList.typed(list)` can now just - be written as `list.cast()`. + `cast` methods. For example, `DelegatingList.typed(list)` can now be + written as `list.cast()`. ## 1.14.7