tdlight/tdutils/test/emoji.cpp

140 lines
6.2 KiB
C++
Raw Normal View History

2022-05-12 17:45:25 +02:00
//
2022-12-31 22:28:08 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
2022-05-12 17:45:25 +02:00
//
// 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"
2022-05-12 18:04:37 +02:00
TEST(Emoji, is_emoji) {
2022-05-12 18:11:17 +02:00
ASSERT_TRUE(!td::is_emoji(""));
2022-05-12 17:45:25 +02:00
ASSERT_TRUE(td::is_emoji("👩🏼‍❤‍💋‍👩🏻"));
2023-01-18 16:22:41 +01:00
ASSERT_TRUE(!td::is_emoji("👩🏼‍❤‍💋‍👩🏻️"));
2022-05-12 17:45:25 +02:00
ASSERT_TRUE(td::is_emoji("👩🏼‍❤️‍💋‍👩🏻"));
2023-01-18 16:22:41 +01:00
ASSERT_TRUE(td::is_emoji("👩🏼‍❤️‍💋‍👩🏻️"));
2022-05-12 17:45:25 +02:00
ASSERT_TRUE(!td::is_emoji("👩🏼‍❤️️‍💋‍👩🏻"));
ASSERT_TRUE(td::is_emoji("⌚"));
2023-01-18 16:22:41 +01:00
ASSERT_TRUE(td::is_emoji("⌚️"));
2022-05-12 17:45:25 +02:00
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("🧑‍🎄"));
2023-01-18 16:22:41 +01:00
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("🕵‍♂"));
2022-05-12 17:45:25 +02:00
}
2022-05-12 18:04:37 +02:00
2022-05-12 18:11:17 +02:00
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);
2022-05-12 18:04:37 +02:00
ASSERT_STREQ(result, emoji);
ASSERT_STREQ(emoji, td::remove_emoji_modifiers(emoji, remove_selectors));
2022-05-12 18:04:37 +02:00
}
TEST(Emoji, remove_emoji_modifiers) {
test_remove_emoji_modifiers("", "");
test_remove_emoji_modifiers("👩🏼‍❤‍💋‍👩🏻", "👩‍❤‍💋‍👩");
test_remove_emoji_modifiers("👩🏼‍❤️‍💋‍👩🏻", "👩‍❤‍💋‍👩");
test_remove_emoji_modifiers("👩🏼‍❤️‍💋‍👩🏻", "👩‍❤️‍💋‍👩", false);
2022-05-12 18:11:17 +02:00
test_remove_emoji_modifiers("👋🏻", "👋");
test_remove_emoji_modifiers("👋🏼", "👋");
test_remove_emoji_modifiers("👋🏽", "👋");
test_remove_emoji_modifiers("👋🏾", "👋");
test_remove_emoji_modifiers("👋🏿", "👋");
2022-11-11 20:20:38 +01:00
test_remove_emoji_modifiers("🏻", "🏻");
test_remove_emoji_modifiers("🏼", "🏼");
test_remove_emoji_modifiers("🏽", "🏽");
test_remove_emoji_modifiers("🏾", "🏾");
test_remove_emoji_modifiers("🏿", "🏿");
2022-05-12 18:04:37 +02:00
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("⌚", "⌚");
2022-11-11 20:20:38 +01:00
test_remove_emoji_modifiers("️", "️");
test_remove_emoji_modifiers("️️️🏻", "️️️🏻");
test_remove_emoji_modifiers("️️️🏻a", "a");
2022-05-12 18:04:37 +02:00
test_remove_emoji_modifiers("🎄", "🎄");
test_remove_emoji_modifiers("🧑‍🎄", "🧑‍🎄");
}
2022-05-12 18:18:14 +02:00
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("🧑‍🎄", "🧑‍🎄");
}