From d3b7fcf8b564e46d95469da91ed0140771250ae2 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sat, 7 Dec 2024 21:43:45 -0800 Subject: [PATCH] emoji: Add toString on EmojiCandidate and EmojiAutocompleteResult Very useful when these objects appear in test failures. --- lib/model/autocomplete.dart | 5 +++++ lib/model/emoji.dart | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/model/autocomplete.dart b/lib/model/autocomplete.dart index 77bfb9e537..b9eb33f25c 100644 --- a/lib/model/autocomplete.dart +++ b/lib/model/autocomplete.dart @@ -766,6 +766,11 @@ class EmojiAutocompleteResult extends ComposeAutocompleteResult { final int rank; final EmojiCandidate candidate; + + @override + String toString() { + return 'EmojiAutocompleteResult(${candidate.description()})'; + } } /// A result from an @-mention autocomplete interaction, diff --git a/lib/model/emoji.dart b/lib/model/emoji.dart index a456836889..753b034c52 100644 --- a/lib/model/emoji.dart +++ b/lib/model/emoji.dart @@ -87,6 +87,18 @@ final class EmojiCandidate { required List? aliases, required this.emojiDisplay, }) : _aliases = aliases; + + /// Used for implementing [toString] and [EmojiAutocompleteResult.toString]. + String description() { + final typeLabel = emojiType.name.replaceFirst(RegExp(r'Emoji$'), ''); + return '$typeLabel $emojiCode $emojiName' + '${aliases.isNotEmpty ? ' $aliases' : ''}'; + } + + @override + String toString() { + return 'EmojiCandidate(${description()})'; + } } // Zulip's hand selected "popular" emojis, currently used as list of