|
15 | 15 | // along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | import { assert } from "@std/assert/assert"; |
17 | 17 | import { assertFalse } from "@std/assert/false"; |
18 | | -import { isEmoji } from "./emoji.ts"; |
| 18 | +import { emoji, isEmoji } from "./emoji.ts"; |
19 | 19 |
|
20 | 20 | Deno.test("isEmoji() with valid emojis", () => { |
21 | 21 | const validEmojis = [ |
@@ -112,3 +112,47 @@ Deno.test("isEmoji() with tricky invalid inputs", () => { |
112 | 112 | ); |
113 | 113 | } |
114 | 114 | }); |
| 115 | +Deno.test("emoji() tagged template function with valid emojis", () => { |
| 116 | + const validEmojis = [ |
| 117 | + emoji`😀`, // simple emoji |
| 118 | + emoji`👍`, // thumbs up |
| 119 | + emoji`🚀`, // rocket |
| 120 | + emoji`🏳️🌈`, // pride flag |
| 121 | + emoji`👨👩👧👦`, // family |
| 122 | + emoji`👩🏽🔬`, // woman scientist with medium skin tone |
| 123 | + emoji`🧘🏻♀️`, // woman in lotus position |
| 124 | + emoji`🇯🇵`, // flag |
| 125 | + ]; |
| 126 | + |
| 127 | + for (const emojiValue of validEmojis) { |
| 128 | + assert(isEmoji(emojiValue)); |
| 129 | + } |
| 130 | +}); |
| 131 | + |
| 132 | +Deno.test("emoji() tagged template function with interpolation", () => { |
| 133 | + const rocket = "🚀"; |
| 134 | + const result = emoji`${rocket}`; |
| 135 | + assert(isEmoji(result)); |
| 136 | + assert(result === "🚀"); |
| 137 | +}); |
| 138 | + |
| 139 | +Deno.test("emoji() throws with invalid inputs", () => { |
| 140 | + const invalidInputs = [ |
| 141 | + () => emoji`😀😀`, // multiple emojis |
| 142 | + () => emoji`hi😀`, // mixed content |
| 143 | + () => emoji`👍awesome`, // mixed content |
| 144 | + () => emoji` 😀`, // emoji with leading space |
| 145 | + () => emoji`😀 `, // emoji with trailing space |
| 146 | + () => emoji``, // empty string |
| 147 | + ]; |
| 148 | + |
| 149 | + for (const fn of invalidInputs) { |
| 150 | + try { |
| 151 | + fn(); |
| 152 | + assert(false, "Expected function to throw TypeError"); |
| 153 | + } catch (error) { |
| 154 | + assert(error instanceof TypeError); |
| 155 | + assert(error.message.startsWith("Invalid emoji:")); |
| 156 | + } |
| 157 | + } |
| 158 | +}); |
0 commit comments