Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a type error that occurs comparing two large maps with deepEquals. #2442

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/checks/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Add `containsMatchingInOrder` and `containsEqualInOrder` to replace the
combined functionality in `containsInOrder`.
- Replace `pairwiseComparesTo` with `pairwiseMatches`.
- Fix a bug where printing the result of a failed deep quality check would
fail with a `TypeError` when comparing large `Map` instances
- Increase SDK constraint to ^3.5.0.

## 0.3.0
Expand Down
5 changes: 3 additions & 2 deletions pkgs/checks/lib/src/describe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ 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, [
const ellipsisElement = [
['...']
]);
];
elements.replaceRange(_maxItems - 1, elements.length, ellipsisElement);
}
if (elements.every((e) => e.length == 1)) {
final singleLine = '$open${elements.map((e) => e.single).join(', ')}$close';
Expand Down
30 changes: 30 additions & 0 deletions pkgs/checks/test/pretty_print_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2025, 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:checks/checks.dart';
import 'package:checks/context.dart';
import 'package:test/scaffolding.dart';

void main() {
group('literal', () {
group('truncates large collections', () {
const maxUntruncatedCollection = 25;
final largeList =
List<int>.generate(maxUntruncatedCollection + 1, (i) => i);
test('in lists', () {
check(literal(largeList)).last.equals('...]');
});
test('in sets', () {
check(literal(largeList.toSet())).last.equals('...}');
});
test('in iterables', () {
check(literal(largeList.followedBy([]))).last.equals('...)');
});
test('in maps', () {
final map = Map<int, int>.fromIterables(largeList, largeList);
check(literal(map)).last.equals('...}');
});
});
});
}
Loading