|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: BSD-2-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <AK/Array.h> |
| 8 | +#include <AK/CharacterTypes.h> |
| 9 | +#include <AK/String.h> |
| 10 | +#include <AK/Utf8View.h> |
| 11 | +#include <LibTest/TestCase.h> |
| 12 | +#include <LibUnicode/Emoji.h> |
| 13 | + |
| 14 | +// These emojis are the first subgroup in each Unicode-defined group of emojis, plus some interesting |
| 15 | +// hand-picked test cases (such as keycap emoji, which begin with ASCII symbols, and country flags). |
| 16 | +static constexpr auto s_smileys_emotion = Array { "😀"sv, "😃"sv, "😄"sv, "😁"sv, "😆"sv, "😅"sv, "🤣"sv, "😂"sv, "🙂"sv, "🙃"sv, "🫠"sv, "😉"sv, "😊"sv, "😇"sv }; |
| 17 | +static constexpr auto s_people_body = Array { "👋"sv, "🤚"sv, "🖐️"sv, "🖐"sv, "✋"sv, "🫱"sv, "🫲"sv, "🫳"sv, "🫴"sv, "🫷"sv, "🫸"sv }; |
| 18 | +static constexpr auto s_animals_nature = Array { "🐶"sv, "🐕"sv, "🐕🦺"sv, "🐩"sv, "🦊"sv, "🦝"sv, "🐱"sv, "🐈"sv, "🐈⬛"sv, "🦁"sv, "🐯"sv, "🐴"sv, "🫎"sv, "🫏"sv, "🐎"sv, "🦄"sv, "🦓"sv, "🦌"sv, "🦬"sv, "🐮"sv, "🐷"sv, "🐖"sv, "🐗"sv, "🐽"sv, "🐑"sv, "🦙"sv, "🦒"sv, "🐘"sv, "🐭"sv, "🐁"sv, "🐀"sv, "🐰"sv, "🐇"sv, "🐿️"sv, "🐿"sv, "🦔"sv, "🦇"sv, "🐻"sv, "🐻❄️"sv, "🐻❄"sv, "🐨"sv, "🐼"sv, "🦥"sv, "🦘"sv, "🦡"sv, "🐾"sv }; |
| 19 | +static constexpr auto s_food_drink = Array { "🍇"sv, "🍈"sv, "🍉"sv, "🍊"sv, "🍋"sv, "🍌"sv, "🍍"sv, "🥭"sv, "🍎"sv, "🍏"sv, "🍐"sv, "🍑"sv, "🍒"sv, "🍓"sv, "🫐"sv, "🥝"sv, "🍅"sv, "🫒"sv, "🥥"sv }; |
| 20 | +static constexpr auto s_travel_places = Array { "🌍"sv, "🌎"sv, "🌏"sv, "🌐"sv, "🗺️"sv, "🗺"sv, "🗾"sv, "🧭"sv }; |
| 21 | +static constexpr auto s_activities = Array { "🎃"sv, "🎄"sv, "🎆"sv, "🎇"sv, "🧨"sv, "✨"sv, "🎈"sv, "🎉"sv, "🎊"sv, "🎋"sv, "🎍"sv, "🎏"sv, "🎑"sv, "🎀"sv, "🎁"sv, "🎗️"sv, "🎗"sv, "🎟️"sv, "🎟"sv, "🎫"sv }; |
| 22 | +static constexpr auto s_objects = Array { "👓"sv, "🕶️"sv, "🕶"sv, "🦺"sv, "👔"sv, "👖"sv, "🧦"sv, "👗"sv, "🥻"sv, "🩱"sv, "🩲"sv, "🩳"sv, "👙"sv, "🪭"sv, "👛"sv, "👜"sv, "🛍️"sv, "🛍"sv, "🩴"sv, "👡"sv, "👢"sv, "🪮"sv, "👑"sv, "🎩"sv, "🎓"sv, "🪖"sv, "⛑️"sv, "⛑"sv, "💄"sv, "💍"sv, "💎"sv }; |
| 23 | +static constexpr auto s_symbols = Array { "🚮"sv, "🚰"sv, "♿"sv, "🚹"sv, "🚺"sv, "🚾"sv, "🛂"sv, "🛃"sv, "🛄"sv, "🛅"sv, "#️⃣"sv, "#⃣"sv, "*️⃣"sv, "*⃣"sv, "0️⃣"sv, "0⃣"sv, "1️⃣"sv, "1⃣"sv, "2️⃣"sv, "2⃣"sv, "3️⃣"sv, "3⃣"sv, "4️⃣"sv, "4⃣"sv, "5️⃣"sv, "5⃣"sv, "6️⃣"sv, "6⃣"sv, "7️⃣"sv, "7⃣"sv, "8️⃣"sv, "8⃣"sv, "9️⃣"sv, "9⃣"sv, "🔟"sv }; |
| 24 | +static constexpr auto s_flags = Array { "🏁"sv, "🚩"sv, "🎌"sv, "🏴"sv, "🏳️"sv, "🏳"sv, "🏳️🌈"sv, "🏳🌈"sv, "🏳️⚧️"sv, "🏳⚧️"sv, "🏳️⚧"sv, "🏳⚧"sv, "🏴☠️"sv, "🏴☠"sv, "🇦🇨"sv, "🇦🇩"sv, "🇦🇪"sv, "🇦🇫"sv, "🇦🇬"sv, "🇦🇮"sv, "🇦🇱"sv, "🇦🇲"sv, "🇦🇴"sv, "🇦🇶"sv, "🇦🇷"sv, "🇦🇸"sv, "🇦🇹"sv, "🇦🇺"sv, "🇦🇼"sv, "🇦🇽"sv, "🇦🇿"sv, "🇧🇦"sv, "🇧🇧"sv, "🇧🇩"sv, "🇧🇪"sv, "🇧🇫"sv, "🇧🇬"sv, "🇧🇭"sv, "🇧🇮"sv, "🇧🇯"sv, "🇧🇱"sv, "🇧🇲"sv, "🇧🇳"sv, "🇧🇴"sv, "🇧🇶"sv, "🇧🇷"sv, "🇧🇸"sv }; |
| 25 | + |
| 26 | +TEST_CASE(emoji) |
| 27 | +{ |
| 28 | + auto test_emojis = [](auto const& emojis) { |
| 29 | + for (auto emoji : emojis) { |
| 30 | + Utf8View view { emoji }; |
| 31 | + EXPECT(Unicode::could_be_start_of_emoji_sequence(view.begin())); |
| 32 | + } |
| 33 | + }; |
| 34 | + |
| 35 | + test_emojis(s_smileys_emotion); |
| 36 | + test_emojis(s_people_body); |
| 37 | + test_emojis(s_animals_nature); |
| 38 | + test_emojis(s_food_drink); |
| 39 | + test_emojis(s_travel_places); |
| 40 | + test_emojis(s_activities); |
| 41 | + test_emojis(s_objects); |
| 42 | + test_emojis(s_symbols); |
| 43 | + test_emojis(s_flags); |
| 44 | +} |
| 45 | + |
| 46 | +TEST_CASE(ascii_is_not_emoji) |
| 47 | +{ |
| 48 | + for (u32 code_point = 0u; is_ascii(code_point); ++code_point) { |
| 49 | + auto string = String::from_code_point(code_point); |
| 50 | + Utf8View view { string }; |
| 51 | + |
| 52 | + EXPECT(!Unicode::could_be_start_of_emoji_sequence(view.begin())); |
| 53 | + } |
| 54 | +} |
0 commit comments