Skip to content

Commit

Permalink
emoji: Add toString on EmojiCandidate and EmojiAutocompleteResult
Browse files Browse the repository at this point in the history
Very useful when these objects appear in test failures.
  • Loading branch information
gnprice committed Dec 8, 2024
1 parent 53c49e8 commit d4a5a04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/model/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions lib/model/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ final class EmojiCandidate {
required List<String>? 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
Expand Down

0 comments on commit d4a5a04

Please sign in to comment.