|
| 1 | +// BotKit by Fedify: A framework for creating ActivityPub bots |
| 2 | +// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/> |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as |
| 6 | +// published by the Free Software Foundation, either version 3 of the |
| 7 | +// License, or (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +import { assert } from "@std/assert/assert"; |
| 17 | +import { assertFalse } from "@std/assert/false"; |
| 18 | +import { isEmoji } from "./emoji.ts"; |
| 19 | + |
| 20 | +Deno.test("isEmoji() with valid emojis", () => { |
| 21 | + const validEmojis = [ |
| 22 | + "😀", // simple emoji |
| 23 | + "👍", // thumbs up |
| 24 | + "🚀", // rocket |
| 25 | + "🏳️🌈", // pride flag (complex emoji with ZWJ sequence) |
| 26 | + "👨👩👧👦", // family (complex emoji with multiple ZWJ sequences) |
| 27 | + "👩🏽🔬", // woman scientist with medium skin tone |
| 28 | + "🧘🏻♀️", // woman in lotus position with light skin tone |
| 29 | + "🤦♂️", // man facepalming |
| 30 | + "🇯🇵", // flag |
| 31 | + ]; |
| 32 | + |
| 33 | + for (const emoji of validEmojis) { |
| 34 | + assert( |
| 35 | + isEmoji(emoji), |
| 36 | + `Expected '${emoji}' to be recognized as an emoji`, |
| 37 | + ); |
| 38 | + } |
| 39 | +}); |
| 40 | + |
| 41 | +Deno.test("isEmoji() with invalid inputs", () => { |
| 42 | + const invalidInputs = [ |
| 43 | + // Multiple emojis |
| 44 | + "😀😀", |
| 45 | + "👍🏻👎🏻", |
| 46 | + // Regular text |
| 47 | + "hello", |
| 48 | + "a", |
| 49 | + // Mixed content |
| 50 | + "hi😀", |
| 51 | + "👍awesome", |
| 52 | + // Empty string |
| 53 | + "", |
| 54 | + // Non-string values |
| 55 | + 42, |
| 56 | + null, |
| 57 | + undefined, |
| 58 | + true, |
| 59 | + false, |
| 60 | + {}, |
| 61 | + [], |
| 62 | + new Date(), |
| 63 | + ]; |
| 64 | + |
| 65 | + for (const input of invalidInputs) { |
| 66 | + assertFalse( |
| 67 | + isEmoji(input), |
| 68 | + `Expected '${input}' not to be recognized as an emoji`, |
| 69 | + ); |
| 70 | + } |
| 71 | +}); |
| 72 | + |
| 73 | +Deno.test("isEmoji() with additional edge cases", () => { |
| 74 | + const edgeCaseEmojis = [ |
| 75 | + "5️⃣", // key cap sequence |
| 76 | + "❤️", // emoji with presentation variation selector |
| 77 | + "☺️", // older emoji with variation selector |
| 78 | + "👩🦰", // woman with red hair (hair modifier) |
| 79 | + "🏊♀️", // woman swimming (gender modifier) |
| 80 | + "🧙♂️", // man mage (gender modifier) |
| 81 | + "🔢", // input numbers symbol (legacy input emoji) |
| 82 | + "↔️", // arrow with variation selector |
| 83 | + "📧", // e-mail symbol |
| 84 | + "📱", // mobile phone |
| 85 | + ]; |
| 86 | + |
| 87 | + for (const emoji of edgeCaseEmojis) { |
| 88 | + assert( |
| 89 | + isEmoji(emoji), |
| 90 | + `Expected '${emoji}' to be recognized as an emoji`, |
| 91 | + ); |
| 92 | + } |
| 93 | +}); |
| 94 | + |
| 95 | +Deno.test("isEmoji() with tricky invalid inputs", () => { |
| 96 | + const trickyInvalidInputs = [ |
| 97 | + " 😀", // emoji with leading space |
| 98 | + "😀 ", // emoji with trailing space |
| 99 | + "\u200B😀", // emoji with zero-width space |
| 100 | + // Note: Single regional indicators like "🇺" are technically valid emojis |
| 101 | + // even though they're usually paired to form flags |
| 102 | + "\u{1F3F4}\uE0067\uE0062", // incomplete tag sequence |
| 103 | + "\uFE0F", // variation selector alone |
| 104 | + "\u200D", // zero width joiner alone |
| 105 | + "♀️♂️", // gender symbols together (should be two separate graphemes) |
| 106 | + ]; |
| 107 | + |
| 108 | + for (const input of trickyInvalidInputs) { |
| 109 | + assertFalse( |
| 110 | + isEmoji(input), |
| 111 | + `Expected '${input}' not to be recognized as an emoji`, |
| 112 | + ); |
| 113 | + } |
| 114 | +}); |
0 commit comments