mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:12:44 +00:00 
			
		
		
		
	LibUnicode: Add a method to check if a code point could start an emoji
This commit is contained in:
		
							parent
							
								
									8c38d46c1a
								
							
						
					
					
						commit
						1484d3d9f5
					
				
					 4 changed files with 163 additions and 2 deletions
				
			
		
							
								
								
									
										54
									
								
								Tests/LibUnicode/TestEmoji.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								Tests/LibUnicode/TestEmoji.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,54 @@ | |||
| /*
 | ||||
|  * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> | ||||
|  * | ||||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <AK/Array.h> | ||||
| #include <AK/CharacterTypes.h> | ||||
| #include <AK/String.h> | ||||
| #include <AK/Utf8View.h> | ||||
| #include <LibTest/TestCase.h> | ||||
| #include <LibUnicode/Emoji.h> | ||||
| 
 | ||||
| // These emojis are the first subgroup in each Unicode-defined group of emojis, plus some interesting
 | ||||
| // hand-picked test cases (such as keycap emoji, which begin with ASCII symbols, and country flags).
 | ||||
| static constexpr auto s_smileys_emotion = Array { "😀"sv, "😃"sv, "😄"sv, "😁"sv, "😆"sv, "😅"sv, "🤣"sv, "😂"sv, "🙂"sv, "🙃"sv, "🫠"sv, "😉"sv, "😊"sv, "😇"sv }; | ||||
| static constexpr auto s_people_body = Array { "👋"sv, "🤚"sv, "🖐️"sv, "🖐"sv, "✋"sv, "🫱"sv, "🫲"sv, "🫳"sv, "🫴"sv, "🫷"sv, "🫸"sv }; | ||||
| 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 }; | ||||
| 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 }; | ||||
| static constexpr auto s_travel_places = Array { "🌍"sv, "🌎"sv, "🌏"sv, "🌐"sv, "🗺️"sv, "🗺"sv, "🗾"sv, "🧭"sv }; | ||||
| 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 }; | ||||
| 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 }; | ||||
| 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 }; | ||||
| 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 }; | ||||
| 
 | ||||
| TEST_CASE(emoji) | ||||
| { | ||||
|     auto test_emojis = [](auto const& emojis) { | ||||
|         for (auto emoji : emojis) { | ||||
|             Utf8View view { emoji }; | ||||
|             EXPECT(Unicode::could_be_start_of_emoji_sequence(view.begin())); | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     test_emojis(s_smileys_emotion); | ||||
|     test_emojis(s_people_body); | ||||
|     test_emojis(s_animals_nature); | ||||
|     test_emojis(s_food_drink); | ||||
|     test_emojis(s_travel_places); | ||||
|     test_emojis(s_activities); | ||||
|     test_emojis(s_objects); | ||||
|     test_emojis(s_symbols); | ||||
|     test_emojis(s_flags); | ||||
| } | ||||
| 
 | ||||
| TEST_CASE(ascii_is_not_emoji) | ||||
| { | ||||
|     for (u32 code_point = 0u; is_ascii(code_point); ++code_point) { | ||||
|         auto string = String::from_code_point(code_point); | ||||
|         Utf8View view { string }; | ||||
| 
 | ||||
|         EXPECT(!Unicode::could_be_start_of_emoji_sequence(view.begin())); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn