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)
|
|
|
|
|
//
|
2023-03-06 18:36:56 +01:00
|
|
|
|
#include "td/utils/common.h"
|
2022-05-12 17:45:25 +02:00
|
|
|
|
#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-05-17 19:04:12 +02:00
|
|
|
|
ASSERT_TRUE(td::is_emoji("đŠđźââ¤âđâđŠđťď¸")); // invalid, but used in the wild
|
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("đľď¸ââď¸"));
|
2023-05-17 19:04:12 +02:00
|
|
|
|
ASSERT_TRUE(td::is_emoji("đľââď¸")); // invalid, but used in the wild
|
|
|
|
|
ASSERT_TRUE(td::is_emoji("đľď¸ââ")); // invalid, but used in the wild
|
2023-01-18 16:22:41 +01:00
|
|
|
|
ASSERT_TRUE(td::is_emoji("đľââ"));
|
2023-05-17 19:04:12 +02:00
|
|
|
|
ASSERT_TRUE(td::is_emoji("đď¸ââď¸"));
|
|
|
|
|
ASSERT_TRUE(td::is_emoji("đď¸ââď¸"));
|
|
|
|
|
ASSERT_TRUE(td::is_emoji("đââď¸")); // invalid, but used in the wild
|
|
|
|
|
ASSERT_TRUE(td::is_emoji("đââď¸")); // invalid, but used in the wild
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 20:10:23 +01:00
|
|
|
|
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);
|
2023-01-23 20:10:23 +01:00
|
|
|
|
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("đŠđźââ¤ď¸âđâđŠđť", "đŠââ¤âđâđŠ");
|
2023-01-23 20:10:23 +01:00
|
|
|
|
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("đ§âđ", "đ§âđ");
|
|
|
|
|
}
|