diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51aaf51f..ac62fe04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [2.18.0, dev] + sdk: [3.1.0, dev] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d diff --git a/CHANGELOG.md b/CHANGELOG.md index c27f014f..05b08995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Adds `shuffled` to `IterableExtension`. - Shuffle `IterableExtension.sample` results. +- Require Dart `^3.1.0` +- Mark "mixin" classes as `mixin`. ## 1.18.0 diff --git a/analysis_options.yaml b/analysis_options.yaml index ea2d1c47..3321f3b1 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:lints/recommended.yaml +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: @@ -6,24 +6,11 @@ analyzer: linter: rules: - - always_declare_return_types - - avoid_dynamic_calls - avoid_unused_constructor_parameters - cancel_subscriptions - - directives_ordering - - lines_longer_than_80_chars - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - no_runtimeType_toString - - omit_local_variable_types - package_api_docs - - prefer_relative_imports - - prefer_single_quotes - - test_types_in_equals - - throw_in_finally - - type_annotate_public_apis - - unawaited_futures - unnecessary_await_in_return - - unnecessary_lambdas - - use_super_parameters diff --git a/lib/algorithms.dart b/lib/algorithms.dart index 7054141e..71a9f67b 100644 --- a/lib/algorithms.dart +++ b/lib/algorithms.dart @@ -7,4 +7,4 @@ library dart.pkg.collection.algorithms; export 'src/algorithms.dart' - show binarySearch, insertionSort, lowerBound, mergeSort, shuffle, reverse; + show binarySearch, insertionSort, lowerBound, mergeSort, reverse, shuffle; diff --git a/lib/collection.dart b/lib/collection.dart index f6f4ae3c..73ec1797 100644 --- a/lib/collection.dart +++ b/lib/collection.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. export 'src/algorithms.dart' - show binarySearch, insertionSort, lowerBound, mergeSort, shuffle, reverse; + show binarySearch, insertionSort, lowerBound, mergeSort, reverse, shuffle; export 'src/boollist.dart'; export 'src/canonicalized_map.dart'; export 'src/combined_wrappers/combined_iterable.dart'; diff --git a/lib/src/comparators.dart b/lib/src/comparators.dart index 0d223c9f..6e5d3631 100644 --- a/lib/src/comparators.dart +++ b/lib/src/comparators.dart @@ -99,7 +99,7 @@ int compareAsciiUpperCase(String a, String b) { bUpperCase -= _asciiCaseBit; } if (aUpperCase != bUpperCase) return (aUpperCase - bUpperCase).sign; - if (defaultResult == 0) defaultResult = (aChar - bChar); + if (defaultResult == 0) defaultResult = aChar - bChar; } if (b.length > a.length) return -1; return defaultResult.sign; diff --git a/lib/src/empty_unmodifiable_set.dart b/lib/src/empty_unmodifiable_set.dart index 12e6f4f5..74fd39a1 100644 --- a/lib/src/empty_unmodifiable_set.dart +++ b/lib/src/empty_unmodifiable_set.dart @@ -34,7 +34,7 @@ class EmptyUnmodifiableSet extends IterableBase E singleWhere(bool Function(E) test, {E Function()? orElse}) => orElse != null ? orElse() : throw StateError('No element'); @override - Iterable whereType() => Iterable.empty(); + Iterable whereType() => Iterable.empty(); @override Set toSet() => {}; @override diff --git a/lib/src/equality.dart b/lib/src/equality.dart index 826446d8..0e1df23d 100644 --- a/lib/src/equality.dart +++ b/lib/src/equality.dart @@ -138,10 +138,10 @@ class IterableEquality implements Equality> { var c = _elementEquality.hash(element); hash = (hash + c) & _hashMask; hash = (hash + (hash << 10)) & _hashMask; - hash ^= (hash >> 6); + hash ^= hash >> 6; } hash = (hash + (hash << 3)) & _hashMask; - hash ^= (hash >> 11); + hash ^= hash >> 11; hash = (hash + (hash << 15)) & _hashMask; return hash; } @@ -190,10 +190,10 @@ class ListEquality implements Equality> { var c = _elementEquality.hash(list[i]); hash = (hash + c) & _hashMask; hash = (hash + (hash << 10)) & _hashMask; - hash ^= (hash >> 6); + hash ^= hash >> 6; } hash = (hash + (hash << 3)) & _hashMask; - hash ^= (hash >> 11); + hash ^= hash >> 11; hash = (hash + (hash << 15)) & _hashMask; return hash; } @@ -240,7 +240,7 @@ abstract class _UnorderedEquality> hash = (hash + c) & _hashMask; } hash = (hash + (hash << 3)) & _hashMask; - hash ^= (hash >> 11); + hash ^= hash >> 11; hash = (hash + (hash << 15)) & _hashMask; return hash; } @@ -349,7 +349,7 @@ class MapEquality implements Equality> { hash = (hash + 3 * keyHash + 7 * valueHash) & _hashMask; } hash = (hash + (hash << 3)) & _hashMask; - hash ^= (hash >> 11); + hash ^= hash >> 11; hash = (hash + (hash << 15)) & _hashMask; return hash; } diff --git a/lib/src/unmodifiable_wrappers.dart b/lib/src/unmodifiable_wrappers.dart index c3c65d57..3b211c07 100644 --- a/lib/src/unmodifiable_wrappers.dart +++ b/lib/src/unmodifiable_wrappers.dart @@ -25,7 +25,7 @@ class NonGrowableListView extends DelegatingList /// Mixin class that implements a throwing version of all list operations that /// change the List's length. -abstract class NonGrowableListMixin implements List { +abstract mixin class NonGrowableListMixin implements List { static Never _throw() { throw UnsupportedError('Cannot change the length of a fixed-length list'); } @@ -116,7 +116,7 @@ class UnmodifiableSetView extends DelegatingSet /// Mixin class that implements a throwing version of all set operations that /// change the Set. -abstract /*mixin*/ class UnmodifiableSetMixin implements Set { +abstract mixin class UnmodifiableSetMixin implements Set { static Never _throw() { throw UnsupportedError('Cannot modify an unmodifiable Set'); } @@ -164,7 +164,7 @@ abstract /*mixin*/ class UnmodifiableSetMixin implements Set { /// Mixin class that implements a throwing version of all map operations that /// change the Map. -abstract /*mixin*/ class UnmodifiableMapMixin implements Map { +abstract mixin class UnmodifiableMapMixin implements Map { static Never _throw() { throw UnsupportedError('Cannot modify an unmodifiable Map'); } diff --git a/lib/src/wrappers.dart b/lib/src/wrappers.dart index bbd5dab1..859d0bcc 100644 --- a/lib/src/wrappers.dart +++ b/lib/src/wrappers.dart @@ -793,7 +793,7 @@ class MapValueSet extends _DelegatingIterableBase implements Set { @override void removeWhere(bool Function(V) test) { - var toRemove = []; + var toRemove = []; _baseMap.forEach((key, value) { if (test(value)) toRemove.add(key); }); @@ -811,7 +811,7 @@ class MapValueSet extends _DelegatingIterableBase implements Set { valuesToRetain.add(_baseMap[key] ?? null as V); } - var keysToRemove = []; + var keysToRemove = []; _baseMap.forEach((k, v) { if (!valuesToRetain.contains(v)) keysToRemove.add(k); }); diff --git a/pubspec.yaml b/pubspec.yaml index b7c9919f..4d70d7ce 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,8 +9,8 @@ topics: - collections environment: - sdk: ">=2.18.0 <4.0.0" + sdk: ^3.1.0 dev_dependencies: - lints: ^2.0.1 + dart_flutter_team_lints: ^2.0.0 test: ^1.16.0 diff --git a/test/algorithms_test.dart b/test/algorithms_test.dart index c2ffb7f2..41603dd8 100644 --- a/test/algorithms_test.dart +++ b/test/algorithms_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. /// Tests algorithm utilities. +library; + import 'dart:math'; import 'package:collection/collection.dart'; @@ -13,7 +15,7 @@ void main() { void testShuffle(List list) { var copy = list.toList(); shuffle(list); - expect(UnorderedIterableEquality().equals(list, copy), isTrue); + expect(const UnorderedIterableEquality().equals(list, copy), isTrue); } test('Shuffle 0', () { @@ -270,25 +272,25 @@ void main() { test('$name2: Same #$n', () { var list = List.generate(n, (i) => OC(i, 0)); // Should succeed. Bad implementations of, e.g., quicksort can diverge. - sort(list, ocOrder, compareInt); + sort(list, _ocOrder, _compareInt); }); test('$name: Pre-sorted #$n', () { var list = List.generate(n, (i) => OC(-i, i)); var expected = list.toList(); - sort(list, ocOrder, compareInt); + sort(list, _ocOrder, _compareInt); // Elements have not moved. expect(list, expected); }); test('$name: Reverse-sorted #$n', () { var list = List.generate(n, (i) => OC(i, -i)); - sort(list, ocOrder, compareInt); - expectSorted(list, ocOrder, compareInt); + sort(list, _ocOrder, _compareInt); + expectSorted(list, _ocOrder, _compareInt); }); test('$name: Random #$n', () { var random = Random(); var list = List.generate(n, (i) => OC(i, random.nextInt(n))); - sort(list, ocOrder, compareInt); - expectSorted(list, ocOrder, compareInt); + sort(list, _ocOrder, _compareInt); + expectSorted(list, _ocOrder, _compareInt); }); test('$name: Sublist #$n', () { var random = Random(); @@ -296,8 +298,8 @@ void main() { var original = list.toList(); var start = n ~/ 4; var end = start * 3; - sort(list, ocOrder, compareInt, start, end); - expectSorted(list, ocOrder, compareInt, start, end); + sort(list, _ocOrder, _compareInt, start, end); + expectSorted(list, _ocOrder, _compareInt, start, end); expect(list.sublist(0, start), original.sublist(0, start)); expect(list.sublist(end), original.sublist(end)); }); @@ -374,7 +376,6 @@ class C { } int compareC(C one, C other) => one.id - other.id; -int cId(C c) => c.id; /// Class naturally ordered by its first constructor argument. class OC implements Comparable { @@ -389,10 +390,9 @@ class OC implements Comparable { String toString() => 'OC[$id,$order]'; } -int ocId(OC oc) => oc.id; -int ocOrder(OC oc) => oc.order; +int _ocOrder(OC oc) => oc.order; -int compareInt(int a, int b) => a - b; +int _compareInt(int a, int b) => a - b; /// Check that a list is sorted according to [compare] of [keyOf] of elements. void expectSorted( diff --git a/test/analysis_options.yaml b/test/analysis_options.yaml index 3d47f949..899b0f33 100644 --- a/test/analysis_options.yaml +++ b/test/analysis_options.yaml @@ -4,3 +4,5 @@ include: ../analysis_options.yaml analyzer: errors: avoid_dynamic_calls: ignore + inference_failure_on_collection_literal: ignore + inference_failure_on_instance_creation: ignore diff --git a/test/boollist_test.dart b/test/boollist_test.dart index aa9e3982..da7b7364 100644 --- a/test/boollist_test.dart +++ b/test/boollist_test.dart @@ -44,10 +44,12 @@ void main() { var b = BoolList(1024, fill: false); expect(() { + // ignore: unnecessary_statements b[-1]; }, throwsRangeError); expect(() { + // ignore: unnecessary_statements b[1024]; }, throwsRangeError); }); diff --git a/test/canonicalized_map_test.dart b/test/canonicalized_map_test.dart index 34e4e8d9..9ae46579 100644 --- a/test/canonicalized_map_test.dart +++ b/test/canonicalized_map_test.dart @@ -147,9 +147,9 @@ void main() { test('addEntries adds key-value pairs to the map', () { map.addEntries([ - MapEntry('1', 'value 1'), - MapEntry('01', 'value 01'), - MapEntry('2', 'value 2'), + const MapEntry('1', 'value 1'), + const MapEntry('01', 'value 01'), + const MapEntry('2', 'value 2'), ]); expect(map, {'01': 'value 01', '2': 'value 2'}); }); diff --git a/test/combined_wrapper/iterable_test.dart b/test/combined_wrapper/iterable_test.dart index 9fb9e390..d5c90bfe 100644 --- a/test/combined_wrapper/iterable_test.dart +++ b/test/combined_wrapper/iterable_test.dart @@ -22,12 +22,12 @@ void main() { }); test('should function as an empty iterable when no iterables are passed', () { - var empty = CombinedIterableView([]); + var empty = const CombinedIterableView([]); expect(empty, isEmpty); }); test('should function as an empty iterable with all empty iterables', () { - var empty = CombinedIterableView([[], [], []]); + var empty = const CombinedIterableView([[], [], []]); expect(empty, isEmpty); }); diff --git a/test/combined_wrapper/map_test.dart b/test/combined_wrapper/map_test.dart index ad6ccc20..9b9a1a83 100644 --- a/test/combined_wrapper/map_test.dart +++ b/test/combined_wrapper/map_test.dart @@ -7,8 +7,6 @@ import 'dart:collection'; import 'package:collection/collection.dart'; import 'package:test/test.dart'; -import '../unmodifiable_collection_test.dart' as common; - void main() { var map1 = const {1: 1, 2: 2, 3: 3}; var map2 = const {4: 4, 5: 5, 6: 6}; @@ -24,10 +22,10 @@ void main() { ..addAll(map3); // In every way possible this should test the same as an UnmodifiableMapView. - common.testReadMap( + _testReadMap( concat, CombinedMapView([map1, map2, map3, map4]), 'CombinedMapView'); - common.testReadMap( + _testReadMap( concat, CombinedMapView([map1, {}, map2, {}, map3, {}, map4, {}]), 'CombinedMapView (some empty)'); @@ -69,3 +67,52 @@ void main() { expect(keys.toList(), keys.toList()); }); } + +void _testReadMap(Map original, Map wrapped, String name) { + test('$name length', () { + expect(wrapped.length, equals(original.length)); + }); + + test('$name isEmpty', () { + expect(wrapped.isEmpty, equals(original.isEmpty)); + }); + + test('$name isNotEmpty', () { + expect(wrapped.isNotEmpty, equals(original.isNotEmpty)); + }); + + test('$name operator[]', () { + expect(wrapped[0], equals(original[0])); + expect(wrapped[999], equals(original[999])); + }); + + test('$name containsKey', () { + expect(wrapped.containsKey(0), equals(original.containsKey(0))); + expect(wrapped.containsKey(999), equals(original.containsKey(999))); + }); + + test('$name containsValue', () { + expect(wrapped.containsValue(0), equals(original.containsValue(0))); + expect(wrapped.containsValue(999), equals(original.containsValue(999))); + }); + + test('$name forEach', () { + var origCnt = 0; + var wrapCnt = 0; + wrapped.forEach((k, v) { + wrapCnt += 1 << k + 3 * v; + }); + original.forEach((k, v) { + origCnt += 1 << k + 3 * v; + }); + expect(wrapCnt, equals(origCnt)); + }); + + test('$name keys', () { + expect(wrapped.keys, orderedEquals(original.keys)); + }); + + test('$name values', () { + expect(wrapped.values, orderedEquals(original.values)); + }); +} diff --git a/test/equality_test.dart b/test/equality_test.dart index 4786b407..ce58df64 100644 --- a/test/equality_test.dart +++ b/test/equality_test.dart @@ -240,10 +240,10 @@ void main() { }); test('Equality accepts null', () { - var ie = IterableEquality(); - var le = ListEquality(); - var se = SetEquality(); - var me = MapEquality(); + var ie = const IterableEquality(); + var le = const ListEquality(); + var se = const SetEquality(); + var me = const MapEquality(); expect(ie.equals(null, null), true); expect(ie.equals([], null), false); expect(ie.equals(null, []), false); diff --git a/test/extensions_test.dart b/test/extensions_test.dart index 229d6e2d..3b1401a5 100644 --- a/test/extensions_test.dart +++ b/test/extensions_test.dart @@ -2,7 +2,7 @@ // 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' show pow, Random; +import 'dart:math' show Random, pow; import 'package:collection/collection.dart'; import 'package:test/test.dart'; @@ -48,7 +48,8 @@ void main() { var input = iterable([1, 2, 3, 4, 5]); var copy = [...input]; var shuffled = input.shuffled(); - expect(UnorderedIterableEquality().equals(input, shuffled), isTrue); + expect(const UnorderedIterableEquality().equals(input, shuffled), + isTrue); // Check that the original list isn't touched expect(input, copy); }); @@ -342,7 +343,7 @@ void main() { }); group('.expandIndexed', () { test('empty', () { - expect(iterable([]).expandIndexed(unreachable), isEmpty); + expect(iterable([]).expandIndexed(unreachable), isEmpty); }); test('empty result', () { expect(iterable(['a', 'b']).expandIndexed((i, v) => []), isEmpty); @@ -616,7 +617,7 @@ void main() { }); test('no split', () { var trace = []; - bool log(x) { + bool log(int x) { trace.add(x); return false; } @@ -651,7 +652,7 @@ void main() { }); test('no split', () { var trace = []; - bool log(i, x) { + bool log(int i, int x) { trace ..add('$i') ..add(x); @@ -695,7 +696,7 @@ void main() { }); test('no split', () { var trace = []; - bool log(x) { + bool log(int x) { trace.add(x); return false; } @@ -733,7 +734,7 @@ void main() { }); test('no split', () { var trace = []; - bool log(i, x) { + bool log(int i, int x) { trace ..add('$i') ..add(x); @@ -774,7 +775,7 @@ void main() { }); test('no split', () { var trace = []; - bool log(x, y) { + bool log(int x, int y) { trace.add([x, y]); return false; } @@ -812,7 +813,7 @@ void main() { }); test('no split', () { var trace = []; - bool log(i, x, y) { + bool log(int i, int x, int y) { trace.add([i, x, y]); return false; } @@ -1191,13 +1192,15 @@ void main() { var result = input.sample(10, random); expect(result.length, 10); expect(result.isSorted(cmpInt), isFalse); - expect(UnorderedIterableEquality().equals(input, result), isTrue); + expect( + const UnorderedIterableEquality().equals(input, result), isTrue); }); test('for overlengthed samples of input', () { var result = input.sample(20, random); expect(result.length, 10); expect(result.isSorted(cmpInt), isFalse); - expect(UnorderedIterableEquality().equals(input, result), isTrue); + expect( + const UnorderedIterableEquality().equals(input, result), isTrue); }); }); }); @@ -1523,7 +1526,7 @@ void main() { list.shuffleRange(0, 3); expect(list.getRange(3, 5), [4, 5]); expect(list.getRange(0, 3), unorderedEquals([1, 2, 3])); - } while (ListEquality().equals(list.sublist(0, 3), [1, 2, 3])); + } while (const ListEquality().equals(list.sublist(0, 3), [1, 2, 3])); // Won't terminate if shuffle *never* moves a value. }); }); @@ -1803,7 +1806,7 @@ void main() { }); group('.expandIndexed', () { test('empty', () { - expect([].expandIndexed(unreachable), isEmpty); + expect([].expandIndexed(unreachable), isEmpty); }); test('empty result', () { expect(['a', 'b'].expandIndexed((i, v) => []), isEmpty); @@ -1971,9 +1974,6 @@ int Function(int, int) cmpMod(int mod) => (a, b) => a ~/ mod - b ~/ mod; /// Compares strings lexically. int cmpString(String a, String b) => a.compareTo(b); -/// Compares strings inverse lexically. -int cmpStringInverse(String a, String b) => b.compareTo(a); - /// Compares strings by length. int cmpStringLength(String a, String b) => a.length - b.length; diff --git a/test/functions_test.dart b/test/functions_test.dart index 359265c1..cc973271 100644 --- a/test/functions_test.dart +++ b/test/functions_test.dart @@ -19,7 +19,7 @@ void main() { test('with no callbacks, returns a copy of the map', () { var map = {'foo': 1, 'bar': 2}; // ignore: deprecated_member_use_from_same_package - var result = mapMap(map); + var result = mapMap(map); expect(result, equals({'foo': 1, 'bar': 2})); // The resulting map should be a copy. @@ -30,7 +30,7 @@ void main() { test("maps the map's keys", () { expect( // ignore: deprecated_member_use_from_same_package - mapMap({'foo': 1, 'bar': 2}, + mapMap({'foo': 1, 'bar': 2}, key: (dynamic key, dynamic value) => key[value]), equals({'o': 1, 'r': 2})); }); @@ -38,7 +38,7 @@ void main() { test("maps the map's values", () { expect( // ignore: deprecated_member_use_from_same_package - mapMap({'foo': 1, 'bar': 2}, + mapMap({'foo': 1, 'bar': 2}, value: (dynamic key, dynamic value) => key[value]), equals({'foo': 'o', 'bar': 'r'})); }); diff --git a/test/ignore_ascii_case_test.dart b/test/ignore_ascii_case_test.dart index 20ad70f5..78f54a2a 100644 --- a/test/ignore_ascii_case_test.dart +++ b/test/ignore_ascii_case_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// Tests case-ignoring compare and equality. +library; import 'package:collection/collection.dart'; import 'package:test/test.dart'; diff --git a/test/priority_queue_test.dart b/test/priority_queue_test.dart index 96e2c154..f07a1a39 100644 --- a/test/priority_queue_test.dart +++ b/test/priority_queue_test.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. /// Tests priority queue implementations utilities. +library; + import 'package:collection/src/priority_queue.dart'; import 'package:test/test.dart'; @@ -17,7 +19,7 @@ void main() { void testDefault() { test('PriorityQueue() returns a HeapPriorityQueue', () { - expect(PriorityQueue(), TypeMatcher>()); + expect(PriorityQueue(), const TypeMatcher>()); }); testInt(PriorityQueue.new); testCustom(PriorityQueue.new); @@ -37,7 +39,7 @@ void testCustom( testQueue('Custom:$count/compare', () => create(compare), List.generate(count, C.new), C(count)); testQueue('Custom:$count/compareNeg', () => create(compareNeg), - List.generate(count, (x) => C(count - x)), C(0)); + List.generate(count, (x) => C(count - x)), const C(0)); } } @@ -171,7 +173,8 @@ void testDuplicates() { // Check how the heap handles duplicate, or equal-but-not-identical, values. test('duplicates', () { var q = HeapPriorityQueue(compare); - var c1 = C(0); + var c1 = const C(0); + // ignore: prefer_const_constructors var c2 = C(0); // Can contain the same element more than once. @@ -218,9 +221,9 @@ void testNullable() { ? -1 : compare(a, b); - var c1 = C(1); - var c2 = C(2); - var c3 = C(3); + var c1 = const C(1); + var c2 = const C(2); + var c3 = const C(3); test('nulls first', () { var q = HeapPriorityQueue(nullCompareFirst); diff --git a/test/queue_list_test.dart b/test/queue_list_test.dart index a8cda88f..1550f927 100644 --- a/test/queue_list_test.dart +++ b/test/queue_list_test.dart @@ -304,4 +304,4 @@ QueueList withInternalGap() { /// Returns a matcher that expects that a closure throws a /// [ConcurrentModificationError]. final throwsConcurrentModificationError = - throwsA(TypeMatcher()); + throwsA(const TypeMatcher()); diff --git a/test/union_set_test.dart b/test/union_set_test.dart index d8897a4e..d06faf3d 100644 --- a/test/union_set_test.dart +++ b/test/union_set_test.dart @@ -39,7 +39,7 @@ void main() { }); group('with multiple disjoint sets', () { - dynamic set; + late Set set; setUp(() { set = UnionSet.from([ {1, 2}, @@ -78,7 +78,7 @@ void main() { }); group('with multiple overlapping sets', () { - dynamic set; + late Set set; setUp(() { set = UnionSet.from([ {1, 2, 3}, @@ -107,7 +107,8 @@ void main() { }); test('lookup() returns the first element in an ordered context', () { - var duration1 = Duration(seconds: 0); + var duration1 = const Duration(seconds: 0); + // ignore: prefer_const_constructors var duration2 = Duration(seconds: 0); expect(duration1, equals(duration2)); expect(duration1, isNot(same(duration2))); @@ -117,7 +118,7 @@ void main() { {duration2} ]); - expect(set.lookup(Duration(seconds: 0)), same(duration1)); + expect(set.lookup(const Duration(seconds: 0)), same(duration1)); }); test('toSet() returns the union of all the sets', () { @@ -131,7 +132,7 @@ void main() { }); group('after an inner set was modified', () { - dynamic set; + late Set set; setUp(() { var innerSet = {3, 7}; set = UnionSet.from([ @@ -175,7 +176,7 @@ void main() { }); group('after the outer set was modified', () { - dynamic set; + late Set set; setUp(() { var innerSet = {6}; var outerSet = { diff --git a/test/unmodifiable_collection_test.dart b/test/unmodifiable_collection_test.dart index a0cb89cd..12a9a0a7 100644 --- a/test/unmodifiable_collection_test.dart +++ b/test/unmodifiable_collection_test.dart @@ -276,6 +276,7 @@ void testReadList(List original, List wrapped, String name) { test('$name - []', () { if (original.isEmpty) { expect(() { + // ignore: unnecessary_statements wrapped[0]; }, throwsRangeError); } else { @@ -315,7 +316,7 @@ void testReadList(List original, List wrapped, String name) { void testNoWriteList(List original, List wrapped, String name) { var copy = List.of(original); - void testThrows(name, thunk) { + void testThrows(String name, void Function() thunk) { test(name, () { expect(thunk, throwsUnsupportedError); // No modifications happened. @@ -396,7 +397,7 @@ void testNoChangeLengthList( List original, List wrapped, String name) { var copy = List.of(original); - void testThrows(String name, thunk) { + void testThrows(String name, void Function() thunk) { test(name, () { expect(thunk, throwsUnsupportedError); // No modifications happened. @@ -490,7 +491,7 @@ void testReadSet(Set original, Set wrapped, String name) { void testNoChangeSet(Set original, Set wrapped, String name) { var originalElements = original.toList(); - void testThrows(name, thunk) { + void testThrows(String name, void Function() thunk) { test(name, () { expect(thunk, throwsUnsupportedError); // No modifications happened. @@ -538,89 +539,3 @@ void testNoChangeSet(Set original, Set wrapped, String name) { wrapped.clear(); }); } - -void testReadMap(Map original, Map wrapped, String name) { - test('$name length', () { - expect(wrapped.length, equals(original.length)); - }); - - test('$name isEmpty', () { - expect(wrapped.isEmpty, equals(original.isEmpty)); - }); - - test('$name isNotEmpty', () { - expect(wrapped.isNotEmpty, equals(original.isNotEmpty)); - }); - - test('$name operator[]', () { - expect(wrapped[0], equals(original[0])); - expect(wrapped[999], equals(original[999])); - }); - - test('$name containsKey', () { - expect(wrapped.containsKey(0), equals(original.containsKey(0))); - expect(wrapped.containsKey(999), equals(original.containsKey(999))); - }); - - test('$name containsValue', () { - expect(wrapped.containsValue(0), equals(original.containsValue(0))); - expect(wrapped.containsValue(999), equals(original.containsValue(999))); - }); - - test('$name forEach', () { - var origCnt = 0; - var wrapCnt = 0; - wrapped.forEach((k, v) { - wrapCnt += 1 << k + 3 * v; - }); - original.forEach((k, v) { - origCnt += 1 << k + 3 * v; - }); - expect(wrapCnt, equals(origCnt)); - }); - - test('$name keys', () { - expect(wrapped.keys, orderedEquals(original.keys)); - }); - - test('$name values', () { - expect(wrapped.values, orderedEquals(original.values)); - }); -} - -void testNoChangeMap( - Map original, Map wrapped, String name) { - var copy = Map.of(original); - - void testThrows(name, thunk) { - test(name, () { - expect(thunk, throwsUnsupportedError); - // No modifications happened. - expect(original, equals(copy)); - }); - } - - testThrows('$name operator[]= throws', () { - wrapped[0] = 42; - }); - - testThrows('$name putIfAbsent throws', () { - wrapped.putIfAbsent(0, () => 42); - }); - - testThrows('$name addAll throws', () { - wrapped.addAll({42: 42}); - }); - - testThrows('$name addAll empty throws', () { - wrapped.addAll({}); - }); - - testThrows('$name remove throws', () { - wrapped.remove(0); - }); - - testThrows('$name clear throws', () { - wrapped.clear(); - }); -} diff --git a/test/wrapper_test.dart b/test/wrapper_test.dart index c9785e8e..65a693f7 100644 --- a/test/wrapper_test.dart +++ b/test/wrapper_test.dart @@ -2,9 +2,12 @@ // 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. -/// Tests wrapper utilities. +// ignore_for_file: unnecessary_statements +/// Tests wrapper utilities. @TestOn('vm') +library; + import 'dart:collection'; import 'dart:mirrors';