///| Chandra's own copy (scripts/fetch-emoji-font.sh; `just test` fetches it). let test_font : String = @emoji.font_path ///| fn open_font() -> @emoji.EmojiFont { let data = @sys.read_file_bytes(test_font) if data.length() == 0 { abort("font_test needs Noto Color Emoji at " + test_font + ": run scripts/fetch-emoji-font.sh") } @emoji.EmojiFont::parse(data) catch { e => abort("Noto Color Emoji didn't parse: " + Show::to_string(e)) } } ///| test "Noto Color Emoji: the same emoji as HarfBuzz finds" { let f = open_font() assert_eq(f.ppem, 109) // Counted with HarfBuzz (uharfbuzz) on Noto Color Emoji 2.051: of the 1923 listed emoji the // font draws 1914 (some Emoji 17/18 additions are missing), and 1650 skin tone variants. let mut base = 0 let mut tones = 0 for e in @emoji.all() { if f.has(e.text) { base = base + 1 } for t in e.tones { if f.has(t) { tones = tones + 1 } } } assert_eq(base, 1914) assert_eq(tones, 1650) // Ligatures: a family, a keycap, a flag and a skin tone are one picture each. for s in ["๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ", "#๏ธโƒฃ", "๐Ÿ‡ฉ๐Ÿ‡ช", "๐Ÿ‘๐Ÿฝ", "๐Ÿดโ€โ˜ ๏ธ", "๐Ÿด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ"] { assert_eq(f.shape(s).length(), 1) assert_true(f.has(s)) } // Text the font can't draw as one picture. assert_false(f.has("ab")) let cracking = @emoji.all().filter(e => e.name == "cracking face")[0] assert_false(f.has(cracking.text)) // Emoji 18.0, newer than this font } ///| test "pictures are scaled to a square, centred, with transparent corners" { let f = open_font() let p = f.picture("๐Ÿ˜€", 32).unwrap() assert_eq(p.width, 32) assert_eq(p.height, 32) // The corner is transparent, the middle of the face is opaque yellow. assert_eq(p.data[3].to_int(), 0) let o = (16 * 32 + 16) * 4 assert_eq(p.data[o + 3].to_int(), 255) assert_true(p.data[o].to_int() > 200 && p.data[o + 1].to_int() > 150 && p.data[o + 2].to_int() < 100) assert_true(f.picture("ab", 32) is None) } ///| test "a file that is not a colour emoji font is an error that says why" { let msg = try { ignore(@emoji.EmojiFont::parse(b"\x00\x01\x00\x00\x00\x00")) "parsed" } catch { e => Show::to_string(e) } assert_true(msg.contains("no cmap table")) assert_true(@emoji.missing_font_message("").contains("just install")) }