Skip to content

Commit

Permalink
Fix a type error that occurs comparing two large maps with deepEquals.
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey committed Dec 29, 2024
1 parent 82a1ca8 commit 1bfa2f0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkgs/checks/lib/src/describe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ Iterable<String> _prettyPrint(
Iterable<String> _prettyPrintCollection(
String open, String close, List<Iterable<String>> elements, int maxLength) {
if (elements.length > _maxItems) {
elements.replaceRange(_maxItems - 1, elements.length, [
// Force inference as List<String>, otherwise the type is
// List<Iterable<String>> which ends up as a type error in dart:collection
// when the underlying list is actually a List<List<String>>. See
// https://github.com/dart-lang/test/issues/2441 for more details.
elements.replaceRange(_maxItems - 1, elements.length, <List<String>>[
['...']
]);
}
Expand Down
59 changes: 59 additions & 0 deletions pkgs/checks/test/extensions/map_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,65 @@ void main() {
test('values', () {
check(_testMap).values.contains(1);
});
test('can be described failing compared to another large map', () {
const expected = {
1: -5,
2: -4,
3: -4,
4: -3,
5: -3,
6: -2,
7: -2,
8: -1,
9: -1,
10: 0,
11: 0,
12: 1,
13: 1,
14: 2,
15: 2,
16: 3,
17: 3,
18: 4,
19: 4,
20: 5,
21: 5,
22: 6,
23: 6,
24: 7,
25: 7,
26: 8,
};
final actual = {
1: -4,
2: -4,
3: -3,
4: -3,
5: -2,
6: -2,
7: -1,
8: -1,
9: 0,
10: 0,
11: 0,
12: 1,
13: 1,
14: 2,
15: 2,
16: 3,
17: 3,
18: 4,
19: 4,
20: 5,
21: 5,
22: 6,
23: 6,
24: 7,
25: 7,
26: 8,
};
check(actual).not((a) => a.deepEquals(expected));
});

group('operator []', () {
test('succeeds for a key that exists', () {
Expand Down

0 comments on commit 1bfa2f0

Please sign in to comment.