Skip to content

Commit

Permalink
emoji test [nfc]: Tighten query-matches tests
Browse files Browse the repository at this point in the history
This makes these tests a bit easier to read already, with less
noisy repetition; and it prepares them for adding more complexity
to how this matching works.
  • Loading branch information
gnprice committed Dec 8, 2024
1 parent 5863c17 commit 5e182d4
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions test/model/emoji_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,12 @@ void main() {
emojiUnicode: tryParseEmojiCodeToUnicode(emojiCode)!));
}

bool matches(String query, EmojiCandidate candidate) {
return EmojiAutocompleteQuery(query).matches(candidate);
}

bool matchesNames(String query, List<String> names) {
return EmojiAutocompleteQuery(query).matches(unicode(names));
return matches(query, unicode(names));
}

bool matchesName(String query, String emojiName) {
Expand Down Expand Up @@ -354,8 +358,7 @@ void main() {
test('query matches literal Unicode value', () {
bool matchesLiteral(String query, String emojiCode, {required String aka}) {
assert(aka == query);
return EmojiAutocompleteQuery(query)
.matches(unicode(['asdf'], emojiCode: emojiCode));
return matches(query, unicode(['asdf'], emojiCode: emojiCode));
}

// Matching the code, in hex, doesn't count.
Expand Down Expand Up @@ -389,16 +392,11 @@ void main() {
resolvedStillUrl: eg.realmUrl.resolve('/emoji/1-still.png')));
}

check(EmojiAutocompleteQuery('eqeq')
.matches(realmCandidate('eqeq'))).isTrue();
check(EmojiAutocompleteQuery('open_')
.matches(realmCandidate('open_book'))).isTrue();
check(EmojiAutocompleteQuery('n_b')
.matches(realmCandidate('open_book'))).isFalse();
check(EmojiAutocompleteQuery('blue dia')
.matches(realmCandidate('large_blue_diamond'))).isTrue();
check(EmojiAutocompleteQuery('Smi')
.matches(realmCandidate('smile'))).isTrue();
check(matches('eqeq', realmCandidate('eqeq'))).isTrue();
check(matches('open_', realmCandidate('open_book'))).isTrue();
check(matches('n_b', realmCandidate('open_book'))).isFalse();
check(matches('blue dia', realmCandidate('large_blue_diamond'))).isTrue();
check(matches('Smi', realmCandidate('smile'))).isTrue();
});

test('can match Zulip extra emoji', () {
Expand All @@ -410,10 +408,10 @@ void main() {
emojiType: ReactionType.zulipExtraEmoji,
emojiCode: 'zulip', emojiName: 'zulip'));

check(EmojiAutocompleteQuery('z').matches(zulipCandidate)).isTrue();
check(EmojiAutocompleteQuery('Zulip').matches(zulipCandidate)).isTrue();
check(EmojiAutocompleteQuery('p').matches(zulipCandidate)).isTrue();
check(EmojiAutocompleteQuery('x').matches(zulipCandidate)).isFalse();
check(matches('z', zulipCandidate)).isTrue();
check(matches('Zulip', zulipCandidate)).isTrue();
check(matches('p', zulipCandidate)).isTrue();
check(matches('x', zulipCandidate)).isFalse();
});
});
}
Expand Down

0 comments on commit 5e182d4

Please sign in to comment.