Skip to content

Commit 073ef8b

Browse files
authored
Fix a type error that occurs comparing two large maps with deepEquals. (#2442)
Closes #2442 Avoid inference forcing a `List<Iterable<String>>` which results in a type error inserting a range into a list requiring `List<String>`. Add a test for collection truncating which would have failed with a type error before this fix.
1 parent b5bfba5 commit 073ef8b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

pkgs/checks/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Add `containsMatchingInOrder` and `containsEqualInOrder` to replace the
99
combined functionality in `containsInOrder`.
1010
- Replace `pairwiseComparesTo` with `pairwiseMatches`.
11+
- Fix a bug where printing the result of a failed deep quality check would
12+
fail with a `TypeError` when comparing large `Map` instances
1113
- Increase SDK constraint to ^3.5.0.
1214

1315
## 0.3.0

pkgs/checks/lib/src/describe.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ Iterable<String> _prettyPrint(
7272
Iterable<String> _prettyPrintCollection(
7373
String open, String close, List<Iterable<String>> elements, int maxLength) {
7474
if (elements.length > _maxItems) {
75-
elements.replaceRange(_maxItems - 1, elements.length, [
75+
const ellipsisElement = [
7676
['...']
77-
]);
77+
];
78+
elements.replaceRange(_maxItems - 1, elements.length, ellipsisElement);
7879
}
7980
if (elements.every((e) => e.length == 1)) {
8081
final singleLine = '$open${elements.map((e) => e.single).join(', ')}$close';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:checks/checks.dart';
6+
import 'package:checks/context.dart';
7+
import 'package:test/scaffolding.dart';
8+
9+
void main() {
10+
group('literal', () {
11+
group('truncates large collections', () {
12+
const maxUntruncatedCollection = 25;
13+
final largeList =
14+
List<int>.generate(maxUntruncatedCollection + 1, (i) => i);
15+
test('in lists', () {
16+
check(literal(largeList)).last.equals('...]');
17+
});
18+
test('in sets', () {
19+
check(literal(largeList.toSet())).last.equals('...}');
20+
});
21+
test('in iterables', () {
22+
check(literal(largeList.followedBy([]))).last.equals('...)');
23+
});
24+
test('in maps', () {
25+
final map = Map<int, int>.fromIterables(largeList, largeList);
26+
check(literal(map)).last.equals('...}');
27+
});
28+
});
29+
});
30+
}

0 commit comments

Comments
 (0)