tdlight/tdutils/test/emoji.cpp

140 lines
6.2 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/utils/emoji.h"
#include "td/utils/tests.h"
TEST(Emoji, is_emoji) {
ASSERT_TRUE(!td::is_emoji(""));
ASSERT_TRUE(td::is_emoji("👩đŸŧ‍❤‍💋‍👩đŸģ"));
ASSERT_TRUE(!td::is_emoji("👩đŸŧ‍❤‍💋‍👩đŸģī¸"));
ASSERT_TRUE(td::is_emoji("👩đŸŧ‍❤ī¸â€đŸ’‹â€đŸ‘ŠđŸģ"));
ASSERT_TRUE(td::is_emoji("👩đŸŧ‍❤ī¸â€đŸ’‹â€đŸ‘ŠđŸģī¸"));
ASSERT_TRUE(!td::is_emoji("👩đŸŧ‍❤ī¸ī¸â€đŸ’‹â€đŸ‘ŠđŸģ"));
ASSERT_TRUE(td::is_emoji("⌚"));
ASSERT_TRUE(td::is_emoji("⌚ī¸"));
ASSERT_TRUE(td::is_emoji("↔"));
ASSERT_TRUE(td::is_emoji("đŸĒ—"));
ASSERT_TRUE(td::is_emoji("2ī¸âƒŖ"));
ASSERT_TRUE(td::is_emoji("2âƒŖ"));
ASSERT_TRUE(!td::is_emoji(" 2âƒŖ"));
ASSERT_TRUE(!td::is_emoji("2âƒŖ "));
ASSERT_TRUE(!td::is_emoji(" "));
ASSERT_TRUE(!td::is_emoji(""));
ASSERT_TRUE(!td::is_emoji("1234567890123456789012345678901234567890123456789012345678901234567890"));
ASSERT_TRUE(td::is_emoji("❤ī¸"));
ASSERT_TRUE(td::is_emoji("❤"));
ASSERT_TRUE(td::is_emoji("⌚"));
ASSERT_TRUE(td::is_emoji("🎄"));
ASSERT_TRUE(td::is_emoji("🧑‍🎄"));
ASSERT_TRUE(td::is_emoji("Šī¸"));
ASSERT_TRUE(td::is_emoji("Š"));
ASSERT_TRUE(!td::is_emoji("Šī¸ī¸"));
ASSERT_TRUE(td::is_emoji("đŸ•ĩī¸â€â™‚ī¸"));
ASSERT_TRUE(!td::is_emoji("đŸ•ĩ‍♂ī¸"));
ASSERT_TRUE(!td::is_emoji("đŸ•ĩī¸â€â™‚"));
ASSERT_TRUE(td::is_emoji("đŸ•ĩ‍♂"));
}
static void test_get_fitzpatrick_modifier(td::string emoji, int result) {
ASSERT_EQ(result, td::get_fitzpatrick_modifier(emoji));
}
TEST(Emoji, get_fitzpatrick_modifier) {
test_get_fitzpatrick_modifier("", 0);
test_get_fitzpatrick_modifier("👩đŸŧ‍❤‍💋‍👩đŸģ", 2);
test_get_fitzpatrick_modifier("👩đŸŧ‍❤ī¸â€đŸ’‹â€đŸ‘ŠđŸģ", 2);
test_get_fitzpatrick_modifier("👋", 0);
test_get_fitzpatrick_modifier("👋đŸģ", 2);
test_get_fitzpatrick_modifier("👋đŸŧ", 3);
test_get_fitzpatrick_modifier("👋đŸŊ", 4);
test_get_fitzpatrick_modifier("👋🏾", 5);
test_get_fitzpatrick_modifier("👋đŸŋ", 6);
test_get_fitzpatrick_modifier("đŸģ", 2);
test_get_fitzpatrick_modifier("đŸŧ", 3);
test_get_fitzpatrick_modifier("đŸŊ", 4);
test_get_fitzpatrick_modifier("🏾", 5);
test_get_fitzpatrick_modifier("đŸŋ", 6);
test_get_fitzpatrick_modifier("⌚", 0);
test_get_fitzpatrick_modifier("↔", 0);
test_get_fitzpatrick_modifier("đŸĒ—", 0);
test_get_fitzpatrick_modifier("2ī¸âƒŖ", 0);
test_get_fitzpatrick_modifier("2âƒŖ", 0);
test_get_fitzpatrick_modifier("❤ī¸", 0);
test_get_fitzpatrick_modifier("❤", 0);
test_get_fitzpatrick_modifier("⌚", 0);
test_get_fitzpatrick_modifier("🎄", 0);
test_get_fitzpatrick_modifier("🧑‍🎄", 0);
}
static void test_remove_emoji_modifiers(td::string emoji, const td::string &result, bool remove_selectors = true) {
ASSERT_STREQ(result, td::remove_emoji_modifiers(emoji, remove_selectors));
td::remove_emoji_modifiers_in_place(emoji, remove_selectors);
ASSERT_STREQ(result, emoji);
ASSERT_STREQ(emoji, td::remove_emoji_modifiers(emoji, remove_selectors));
}
TEST(Emoji, remove_emoji_modifiers) {
test_remove_emoji_modifiers("", "");
test_remove_emoji_modifiers("👩đŸŧ‍❤‍💋‍👩đŸģ", "👩‍❤‍💋‍👩");
test_remove_emoji_modifiers("👩đŸŧ‍❤ī¸â€đŸ’‹â€đŸ‘ŠđŸģ", "👩‍❤‍💋‍👩");
test_remove_emoji_modifiers("👩đŸŧ‍❤ī¸â€đŸ’‹â€đŸ‘ŠđŸģ", "👩‍❤ī¸â€đŸ’‹â€đŸ‘Š", false);
test_remove_emoji_modifiers("👋đŸģ", "👋");
test_remove_emoji_modifiers("👋đŸŧ", "👋");
test_remove_emoji_modifiers("👋đŸŊ", "👋");
test_remove_emoji_modifiers("👋🏾", "👋");
test_remove_emoji_modifiers("👋đŸŋ", "👋");
test_remove_emoji_modifiers("đŸģ", "đŸģ");
test_remove_emoji_modifiers("đŸŧ", "đŸŧ");
test_remove_emoji_modifiers("đŸŊ", "đŸŊ");
test_remove_emoji_modifiers("🏾", "🏾");
test_remove_emoji_modifiers("đŸŋ", "đŸŋ");
test_remove_emoji_modifiers("⌚", "⌚");
test_remove_emoji_modifiers("↔", "↔");
test_remove_emoji_modifiers("đŸĒ—", "đŸĒ—");
test_remove_emoji_modifiers("2ī¸âƒŖ", "2âƒŖ");
test_remove_emoji_modifiers("2âƒŖ", "2âƒŖ");
test_remove_emoji_modifiers("❤ī¸", "❤");
test_remove_emoji_modifiers("❤", "❤");
test_remove_emoji_modifiers("⌚", "⌚");
test_remove_emoji_modifiers("ī¸", "ī¸");
test_remove_emoji_modifiers("ī¸ī¸ī¸đŸģ", "ī¸ī¸ī¸đŸģ");
test_remove_emoji_modifiers("ī¸ī¸ī¸đŸģa", "a");
test_remove_emoji_modifiers("🎄", "🎄");
test_remove_emoji_modifiers("🧑‍🎄", "🧑‍🎄");
}
static void test_remove_emoji_selectors(td::string emoji, const td::string &result) {
ASSERT_STREQ(result, td::remove_emoji_selectors(result));
ASSERT_STREQ(result, td::remove_emoji_selectors(emoji));
}
TEST(Emoji, remove_emoji_selectors) {
test_remove_emoji_selectors("", "");
test_remove_emoji_selectors("👩đŸŧ‍❤‍💋‍👩đŸģ", "👩đŸŧ‍❤‍💋‍👩đŸģ");
test_remove_emoji_selectors("👩đŸŧ‍❤ī¸â€đŸ’‹â€đŸ‘ŠđŸģ", "👩đŸŧ‍❤‍💋‍👩đŸģ");
test_remove_emoji_selectors("👋đŸģ", "👋đŸģ");
test_remove_emoji_selectors("👋đŸŧ", "👋đŸŧ");
test_remove_emoji_selectors("👋đŸŊ", "👋đŸŊ");
test_remove_emoji_selectors("👋🏾", "👋🏾");
test_remove_emoji_selectors("👋đŸŋ", "👋đŸŋ");
test_remove_emoji_selectors("đŸģ", "đŸģ");
test_remove_emoji_selectors("đŸŧ", "đŸŧ");
test_remove_emoji_selectors("đŸŊ", "đŸŊ");
test_remove_emoji_selectors("🏾", "🏾");
test_remove_emoji_selectors("đŸŋ", "đŸŋ");
test_remove_emoji_selectors("⌚", "⌚");
test_remove_emoji_selectors("↔", "↔");
test_remove_emoji_selectors("đŸĒ—", "đŸĒ—");
test_remove_emoji_selectors("2ī¸âƒŖ", "2âƒŖ");
test_remove_emoji_selectors("2âƒŖ", "2âƒŖ");
test_remove_emoji_selectors("❤ī¸", "❤");
test_remove_emoji_selectors("❤", "❤");
test_remove_emoji_selectors("⌚", "⌚");
test_remove_emoji_selectors("🎄", "🎄");
test_remove_emoji_selectors("🧑‍🎄", "🧑‍🎄");
}