From 1bfa2f0a150b52e31cd0ab22dfff0a845619f404 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Sat, 28 Dec 2024 18:20:51 -0800 Subject: [PATCH] Fix a type error that occurs comparing two large maps with deepEquals. --- pkgs/checks/lib/src/describe.dart | 6 ++- pkgs/checks/test/extensions/map_test.dart | 59 +++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/pkgs/checks/lib/src/describe.dart b/pkgs/checks/lib/src/describe.dart index f05a1640b..ab0b2898b 100644 --- a/pkgs/checks/lib/src/describe.dart +++ b/pkgs/checks/lib/src/describe.dart @@ -72,7 +72,11 @@ Iterable _prettyPrint( Iterable _prettyPrintCollection( String open, String close, List> elements, int maxLength) { if (elements.length > _maxItems) { - elements.replaceRange(_maxItems - 1, elements.length, [ + // Force inference as List, otherwise the type is + // List> which ends up as a type error in dart:collection + // when the underlying list is actually a List>. See + // https://github.com/dart-lang/test/issues/2441 for more details. + elements.replaceRange(_maxItems - 1, elements.length, >[ ['...'] ]); } diff --git a/pkgs/checks/test/extensions/map_test.dart b/pkgs/checks/test/extensions/map_test.dart index cb3e3e493..6cc3f5064 100644 --- a/pkgs/checks/test/extensions/map_test.dart +++ b/pkgs/checks/test/extensions/map_test.dart @@ -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', () {