emoji-mixer 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ dist
2
+ .idea
3
+ qodana.yaml
4
+ node_modules
5
+ target
6
+ Cargo.lock
7
+ __pycache__
8
+
9
+ # PHP, Ruby, .NET
10
+ /vendor/
11
+ *.gem
12
+ bin/
13
+ obj/
14
+ /nupkg/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MattFor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.5
2
+ Name: emoji-mixer
3
+ Version: 2.2.0
4
+ Summary: Get a Google Emoji Kitchen mixed emoji .png link from 2 other emojis. (and some more)
5
+ Project-URL: Homepage, https://github.com/MattFor/emoji-mixer
6
+ Project-URL: Issues, https://github.com/MattFor/emoji-mixer/issues
7
+ Author-email: MattFor <mattfor@relaxy.xyz>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: combination,emoji,google,kitchen,mix,mixing
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Emoji Mixer
15
+
16
+ [![CI](https://github.com/MattFor/emoji-mixer/actions/workflows/ci.yml/badge.svg)](https://github.com/MattFor/emoji-mixer/actions/workflows/ci.yml)
17
+ [![npm](https://img.shields.io/npm/v/emoji-mixer)](https://www.npmjs.com/package/emoji-mixer)
18
+ [![PyPI](https://img.shields.io/pypi/v/emoji-mixer)](https://pypi.org/project/emoji-mixer/)
19
+ [![crates.io](https://img.shields.io/crates/v/emoji-mixer)](https://crates.io/crates/emoji-mixer)
20
+ [![Go Reference](https://pkg.go.dev/badge/github.com/MattFor/emoji-mixer/v2.svg)](https://pkg.go.dev/github.com/MattFor/emoji-mixer/v2)
21
+ [![JSR](https://jsr.io/badges/@mattfor/emoji-mixer)](https://jsr.io/@mattfor/emoji-mixer)
22
+ [![Packagist](https://img.shields.io/packagist/v/mattfor/emoji-mixer)](https://packagist.org/packages/mattfor/emoji-mixer)
23
+ [![Gem](https://img.shields.io/gem/v/emoji_mixer)](https://rubygems.org/gems/emoji_mixer)
24
+ [![NuGet](https://img.shields.io/nuget/v/EmojiMixer)](https://www.nuget.org/packages/EmojiMixer)
25
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
26
+
27
+ Get the URL of a Google Emoji Kitchen image for two emojis.
28
+
29
+ ## Install
30
+
31
+ ```sh
32
+ npm install emoji-mixer # JavaScript / TypeScript, Node.js 20.19+
33
+ pip install emoji-mixer # Python 3.10+
34
+ cargo add emoji-mixer # Rust
35
+ go get github.com/MattFor/emoji-mixer/v2 # Go 1.21+
36
+ deno add jsr:@mattfor/emoji-mixer # Deno, or npx jsr add @mattfor/emoji-mixer
37
+ composer require mattfor/emoji-mixer # PHP 8.2+
38
+ gem install emoji_mixer # Ruby 3.3+
39
+ dotnet add package EmojiMixer # .NET 10+
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ```js
45
+ import getEmojiMixUrl from 'emoji-mixer';
46
+ // or: const { default: getEmojiMixUrl } = require("emoji-mixer");
47
+
48
+ getEmojiMixUrl('🔥', '😃');
49
+ // https://www.gstatic.com/android/keyboard/emojikitchen/20201001/u1f603/u1f603_u1f525.png
50
+ ```
51
+
52
+ ```python
53
+ from emoji_mixer import get_emoji_mix_url
54
+
55
+ get_emoji_mix_url("🔥", "😃")
56
+ ```
57
+
58
+ ```rust
59
+ emoji_mixer::get_emoji_mix_url("🔥", "😃"); // Some(url)
60
+ ```
61
+
62
+ ```go
63
+ import emojimixer "github.com/MattFor/emoji-mixer/v2"
64
+
65
+ url, err := emojimixer.EmojiMixURL("🔥", "😃")
66
+ ```
67
+
68
+ ```php
69
+ use MattFor\EmojiMixer\EmojiMixer;
70
+
71
+ EmojiMixer::getEmojiMixUrl('🔥', '😃');
72
+ ```
73
+
74
+ ```ruby
75
+ require "emoji_mixer"
76
+
77
+ EmojiMixer.emoji_mix_url("🔥", "😃")
78
+ ```
79
+
80
+ ```csharp
81
+ using EmojiMixer;
82
+
83
+ EmojiKitchen.GetEmojiMixUrl("🔥", "😃");
84
+ ```
85
+
86
+ Emojis can be passed as characters (`"☕"`) or codepoint strings (`"2615"`, `"1F600"`, `"2764-fe0f"`). The FE0F variation selector is optional.
87
+
88
+ ## Functions
89
+
90
+ - `getEmojiMixUrl(leftEmoji, rightEmoji, detailedErrors = false)` (default export)
91
+ Returns the image URL, or `undefined` if an emoji is unsupported or the pair has no mix. With `detailedErrors`, throws an error explaining why instead.
92
+
93
+ - `toUnicode(input)`
94
+ Returns the codepoint key of one supported emoji, e.g. `"☕"` → `"2615"`, or `undefined`.
95
+
96
+ - `getEmojiCombo(leftEmoji, rightEmoji)`
97
+ Takes two codepoint keys and returns the newest `{ leftEmoji, rightEmoji, date }` combination, or `undefined`. `leftEmoji` and `rightEmoji` are in the order Google hosts the image under, which may differ from the argument order.
98
+
99
+ - `checkSupported(emoji)`
100
+ Returns every combination containing the emoji (on either side), or `null` if it is unsupported.
101
+
102
+ - `googleRequestUrl(combo)` / `googleRequestUrlEmojiPart(emoji)`
103
+ Build the image URL from a combination / format one emoji for the URL.
104
+
105
+ - `getExpandedEmojiCompatibilityData(useCache = false)`
106
+ Returns `{ [emoji]: combination[] }` for every supported emoji.
107
+
108
+ - `supportedEmojis`, `emojiCompatibilityData`, `baseUrl`
109
+ The supported codepoint keys, the compressed database and the image base URL.
110
+
111
+ **Python** has the same API in snake_case (`get_emoji_mix_url`, `to_unicode`, …, `BASE_URL`). It returns `None` instead of `undefined`/`null`, `detailed_errors` raises `ValueError`, and combinations are `EmojiCombo(left_emoji, right_emoji, date)` named tuples.
112
+
113
+ **Rust** has `get_emoji_mix_url`, `to_unicode`, `get_emoji_combo`, `check_supported`, `google_request_url`, `google_request_url_emoji_part`, `supported_emojis()` and `BASE_URL`, returning `Option`s.
114
+
115
+ **Go** has `EmojiMixURL` (an `error` says why there is no URL), `ToUnicode`, `EmojiCombo`, `CheckSupported`,
116
+ `ExpandedEmojiCompatibilityData`, `GoogleRequestURL`, `GoogleRequestURLEmojiPart`, `SupportedEmojis()` and `BaseURL`;
117
+ lookups return `(value, ok)` and combinations are `Combo{LeftEmoji, RightEmoji, Date}`.
118
+
119
+ **JSR** is the same TypeScript as the npm package.
120
+
121
+ **PHP** has the same API as static methods of `MattFor\EmojiMixer\EmojiMixer` (`getEmojiMixUrl`, `toUnicode`, …,
122
+ `BASE_URL`), returning `null`; `$detailedErrors` throws `InvalidArgumentException`, and combinations are `EmojiCombo`
123
+ objects with `leftEmoji`, `rightEmoji` and `date`.
124
+
125
+ **Ruby** has `EmojiMixer.emoji_mix_url(left, right, detailed_errors: false)`, `to_unicode`, `emoji_combo`,
126
+ `check_supported`, `expanded_emoji_compatibility_data`, `google_request_url`, `google_request_url_emoji_part`,
127
+ `supported_emojis` and `BASE_URL`, returning `nil`; `detailed_errors` raises `ArgumentError`, and combinations are
128
+ `EmojiMixer::EmojiCombo` values.
129
+
130
+ **C#** has the same API as static members of `EmojiMixer.EmojiKitchen` (`GetEmojiMixUrl`, `ToUnicode`, …,
131
+ `SupportedEmojis`, `BaseUrl`), returning `null`; `detailedErrors` throws `ArgumentException`, and combinations are
132
+ `EmojiCombo(LeftEmoji, RightEmoji, Date)` records.
133
+
134
+ ## Data format
135
+
136
+ `emojiCompatibilityData` is generated from [emojikitchen.dev](https://emojikitchen.dev/metadata.json) by `converter.ts`:
137
+
138
+ ```js
139
+ {
140
+ "$d": [20201001, 20260128], // unique dates
141
+ "$e": [9749, 9800], // unique emojis: codepoints as integers, sequences as strings
142
+ "2615": [[0, 0], [1, 1]], // [emojiIndex, dateIndex]
143
+ "2648": [[-1, 1]]
144
+ }
145
+ ```
146
+
147
+ A negative `emojiIndex` (`~i`) means the key emoji is the right-hand emoji in Google's URL. Above, both entries `[1, 1]` and `[-1, 1]` describe ☕ (left) + ♈ (right).
148
+
149
+ ## Attributions
150
+
151
+ - Created by MattFor | Discord tag: mattfor | [Github](https://github.com/MattFor)
152
+ - Inspired by [emoji-kitchen](https://github.com/xsalazar/emoji-kitchen) [made by Xavier Salazar a.k.a [xsalazar](https://github.com/xsalazar)]
153
+
154
+ ## License
155
+
156
+ MIT, see [LICENSE](LICENSE). By [MattFor](https://github.com/MattFor).
@@ -0,0 +1,143 @@
1
+ # Emoji Mixer
2
+
3
+ [![CI](https://github.com/MattFor/emoji-mixer/actions/workflows/ci.yml/badge.svg)](https://github.com/MattFor/emoji-mixer/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/emoji-mixer)](https://www.npmjs.com/package/emoji-mixer)
5
+ [![PyPI](https://img.shields.io/pypi/v/emoji-mixer)](https://pypi.org/project/emoji-mixer/)
6
+ [![crates.io](https://img.shields.io/crates/v/emoji-mixer)](https://crates.io/crates/emoji-mixer)
7
+ [![Go Reference](https://pkg.go.dev/badge/github.com/MattFor/emoji-mixer/v2.svg)](https://pkg.go.dev/github.com/MattFor/emoji-mixer/v2)
8
+ [![JSR](https://jsr.io/badges/@mattfor/emoji-mixer)](https://jsr.io/@mattfor/emoji-mixer)
9
+ [![Packagist](https://img.shields.io/packagist/v/mattfor/emoji-mixer)](https://packagist.org/packages/mattfor/emoji-mixer)
10
+ [![Gem](https://img.shields.io/gem/v/emoji_mixer)](https://rubygems.org/gems/emoji_mixer)
11
+ [![NuGet](https://img.shields.io/nuget/v/EmojiMixer)](https://www.nuget.org/packages/EmojiMixer)
12
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
13
+
14
+ Get the URL of a Google Emoji Kitchen image for two emojis.
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ npm install emoji-mixer # JavaScript / TypeScript, Node.js 20.19+
20
+ pip install emoji-mixer # Python 3.10+
21
+ cargo add emoji-mixer # Rust
22
+ go get github.com/MattFor/emoji-mixer/v2 # Go 1.21+
23
+ deno add jsr:@mattfor/emoji-mixer # Deno, or npx jsr add @mattfor/emoji-mixer
24
+ composer require mattfor/emoji-mixer # PHP 8.2+
25
+ gem install emoji_mixer # Ruby 3.3+
26
+ dotnet add package EmojiMixer # .NET 10+
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```js
32
+ import getEmojiMixUrl from 'emoji-mixer';
33
+ // or: const { default: getEmojiMixUrl } = require("emoji-mixer");
34
+
35
+ getEmojiMixUrl('🔥', '😃');
36
+ // https://www.gstatic.com/android/keyboard/emojikitchen/20201001/u1f603/u1f603_u1f525.png
37
+ ```
38
+
39
+ ```python
40
+ from emoji_mixer import get_emoji_mix_url
41
+
42
+ get_emoji_mix_url("🔥", "😃")
43
+ ```
44
+
45
+ ```rust
46
+ emoji_mixer::get_emoji_mix_url("🔥", "😃"); // Some(url)
47
+ ```
48
+
49
+ ```go
50
+ import emojimixer "github.com/MattFor/emoji-mixer/v2"
51
+
52
+ url, err := emojimixer.EmojiMixURL("🔥", "😃")
53
+ ```
54
+
55
+ ```php
56
+ use MattFor\EmojiMixer\EmojiMixer;
57
+
58
+ EmojiMixer::getEmojiMixUrl('🔥', '😃');
59
+ ```
60
+
61
+ ```ruby
62
+ require "emoji_mixer"
63
+
64
+ EmojiMixer.emoji_mix_url("🔥", "😃")
65
+ ```
66
+
67
+ ```csharp
68
+ using EmojiMixer;
69
+
70
+ EmojiKitchen.GetEmojiMixUrl("🔥", "😃");
71
+ ```
72
+
73
+ Emojis can be passed as characters (`"☕"`) or codepoint strings (`"2615"`, `"1F600"`, `"2764-fe0f"`). The FE0F variation selector is optional.
74
+
75
+ ## Functions
76
+
77
+ - `getEmojiMixUrl(leftEmoji, rightEmoji, detailedErrors = false)` (default export)
78
+ Returns the image URL, or `undefined` if an emoji is unsupported or the pair has no mix. With `detailedErrors`, throws an error explaining why instead.
79
+
80
+ - `toUnicode(input)`
81
+ Returns the codepoint key of one supported emoji, e.g. `"☕"` → `"2615"`, or `undefined`.
82
+
83
+ - `getEmojiCombo(leftEmoji, rightEmoji)`
84
+ Takes two codepoint keys and returns the newest `{ leftEmoji, rightEmoji, date }` combination, or `undefined`. `leftEmoji` and `rightEmoji` are in the order Google hosts the image under, which may differ from the argument order.
85
+
86
+ - `checkSupported(emoji)`
87
+ Returns every combination containing the emoji (on either side), or `null` if it is unsupported.
88
+
89
+ - `googleRequestUrl(combo)` / `googleRequestUrlEmojiPart(emoji)`
90
+ Build the image URL from a combination / format one emoji for the URL.
91
+
92
+ - `getExpandedEmojiCompatibilityData(useCache = false)`
93
+ Returns `{ [emoji]: combination[] }` for every supported emoji.
94
+
95
+ - `supportedEmojis`, `emojiCompatibilityData`, `baseUrl`
96
+ The supported codepoint keys, the compressed database and the image base URL.
97
+
98
+ **Python** has the same API in snake_case (`get_emoji_mix_url`, `to_unicode`, …, `BASE_URL`). It returns `None` instead of `undefined`/`null`, `detailed_errors` raises `ValueError`, and combinations are `EmojiCombo(left_emoji, right_emoji, date)` named tuples.
99
+
100
+ **Rust** has `get_emoji_mix_url`, `to_unicode`, `get_emoji_combo`, `check_supported`, `google_request_url`, `google_request_url_emoji_part`, `supported_emojis()` and `BASE_URL`, returning `Option`s.
101
+
102
+ **Go** has `EmojiMixURL` (an `error` says why there is no URL), `ToUnicode`, `EmojiCombo`, `CheckSupported`,
103
+ `ExpandedEmojiCompatibilityData`, `GoogleRequestURL`, `GoogleRequestURLEmojiPart`, `SupportedEmojis()` and `BaseURL`;
104
+ lookups return `(value, ok)` and combinations are `Combo{LeftEmoji, RightEmoji, Date}`.
105
+
106
+ **JSR** is the same TypeScript as the npm package.
107
+
108
+ **PHP** has the same API as static methods of `MattFor\EmojiMixer\EmojiMixer` (`getEmojiMixUrl`, `toUnicode`, …,
109
+ `BASE_URL`), returning `null`; `$detailedErrors` throws `InvalidArgumentException`, and combinations are `EmojiCombo`
110
+ objects with `leftEmoji`, `rightEmoji` and `date`.
111
+
112
+ **Ruby** has `EmojiMixer.emoji_mix_url(left, right, detailed_errors: false)`, `to_unicode`, `emoji_combo`,
113
+ `check_supported`, `expanded_emoji_compatibility_data`, `google_request_url`, `google_request_url_emoji_part`,
114
+ `supported_emojis` and `BASE_URL`, returning `nil`; `detailed_errors` raises `ArgumentError`, and combinations are
115
+ `EmojiMixer::EmojiCombo` values.
116
+
117
+ **C#** has the same API as static members of `EmojiMixer.EmojiKitchen` (`GetEmojiMixUrl`, `ToUnicode`, …,
118
+ `SupportedEmojis`, `BaseUrl`), returning `null`; `detailedErrors` throws `ArgumentException`, and combinations are
119
+ `EmojiCombo(LeftEmoji, RightEmoji, Date)` records.
120
+
121
+ ## Data format
122
+
123
+ `emojiCompatibilityData` is generated from [emojikitchen.dev](https://emojikitchen.dev/metadata.json) by `converter.ts`:
124
+
125
+ ```js
126
+ {
127
+ "$d": [20201001, 20260128], // unique dates
128
+ "$e": [9749, 9800], // unique emojis: codepoints as integers, sequences as strings
129
+ "2615": [[0, 0], [1, 1]], // [emojiIndex, dateIndex]
130
+ "2648": [[-1, 1]]
131
+ }
132
+ ```
133
+
134
+ A negative `emojiIndex` (`~i`) means the key emoji is the right-hand emoji in Google's URL. Above, both entries `[1, 1]` and `[-1, 1]` describe ☕ (left) + ♈ (right).
135
+
136
+ ## Attributions
137
+
138
+ - Created by MattFor | Discord tag: mattfor | [Github](https://github.com/MattFor)
139
+ - Inspired by [emoji-kitchen](https://github.com/xsalazar/emoji-kitchen) [made by Xavier Salazar a.k.a [xsalazar](https://github.com/xsalazar)]
140
+
141
+ ## License
142
+
143
+ MIT, see [LICENSE](LICENSE). By [MattFor](https://github.com/MattFor).
@@ -0,0 +1,100 @@
1
+ import json
2
+ import re
3
+ from importlib.resources import files
4
+ from typing import NamedTuple
5
+
6
+ BASE_URL = "https://www.gstatic.com/android/keyboard/emojikitchen"
7
+
8
+ emoji_compatibility_data = json.loads(files(__name__).joinpath("compatibility.json").read_text("utf-8"))
9
+ supported_emojis = sorted(key for key in emoji_compatibility_data if not key.startswith("$"))
10
+
11
+
12
+ class EmojiCombo(NamedTuple):
13
+ left_emoji: str
14
+ right_emoji: str
15
+ date: str
16
+
17
+
18
+ def _strip_fe0f(codepoints: str) -> str:
19
+ return "-".join(part for part in codepoints.split("-") if part != "fe0f")
20
+
21
+
22
+ _supported = set(supported_emojis)
23
+ _by_stripped_key = {_strip_fe0f(key): key for key in supported_emojis}
24
+
25
+
26
+ def _combos_of(emoji: str) -> list[list[int]]:
27
+ return emoji_compatibility_data[emoji] if emoji in _supported else []
28
+
29
+
30
+ def _emoji_at(index: int) -> str:
31
+ emoji = emoji_compatibility_data["$e"][~index if index < 0 else index]
32
+ return format(emoji, "x") if isinstance(emoji, int) else emoji
33
+
34
+
35
+ def _expand(anchor: str, entry: list[int]) -> EmojiCombo:
36
+ index, date_index = entry
37
+ other, date = _emoji_at(index), str(emoji_compatibility_data["$d"][date_index])
38
+ return EmojiCombo(other, anchor, date) if index < 0 else EmojiCombo(anchor, other, date)
39
+
40
+
41
+ def to_unicode(value: str) -> str | None:
42
+ if not isinstance(value, str):
43
+ return None
44
+
45
+ if re.fullmatch(r"[0-9a-f]+(-[0-9a-f]+)*", value, re.IGNORECASE):
46
+ codepoints = value.lower()
47
+ else:
48
+ codepoints = "-".join(format(ord(char), "x") for char in value)
49
+
50
+ return _by_stripped_key.get(_strip_fe0f(codepoints))
51
+
52
+
53
+ def check_supported(emoji: str) -> list[EmojiCombo] | None:
54
+ key = to_unicode(emoji)
55
+ return [_expand(key, entry) for entry in _combos_of(key)] if key else None
56
+
57
+
58
+ def get_expanded_emoji_compatibility_data() -> dict[str, list[EmojiCombo]]:
59
+ return {emoji: check_supported(emoji) for emoji in supported_emojis}
60
+
61
+
62
+ def google_request_url_emoji_part(emoji: str) -> str:
63
+ return "-".join(f"u{part.lower()}" for part in emoji.split("-"))
64
+
65
+
66
+ def google_request_url(combo: EmojiCombo) -> str:
67
+ left = google_request_url_emoji_part(combo.left_emoji)
68
+ return f"{BASE_URL}/{combo.date}/{left}/{left}_{google_request_url_emoji_part(combo.right_emoji)}.png"
69
+
70
+
71
+ def get_emoji_combo(left_emoji: str, right_emoji: str) -> EmojiCombo | None:
72
+ matches = [
73
+ _expand(anchor, entry)
74
+ for anchor, other in ((left_emoji, right_emoji), (right_emoji, left_emoji))
75
+ for entry in _combos_of(anchor)
76
+ if _emoji_at(entry[0]) == other
77
+ ]
78
+ return max(matches, key=lambda combo: combo.date, default=None)
79
+
80
+
81
+ def get_emoji_mix_url(left_emoji: str, right_emoji: str, detailed_errors: bool = False) -> str | None:
82
+ left, right = to_unicode(left_emoji), to_unicode(right_emoji)
83
+ combo = get_emoji_combo(left, right) if left and right else None
84
+
85
+ if combo:
86
+ return google_request_url(combo)
87
+
88
+ if not detailed_errors:
89
+ return None
90
+
91
+ if not left:
92
+ raise ValueError(f"'{left_emoji}' [left_emoji] is not a supported emoji.")
93
+
94
+ if not right:
95
+ raise ValueError(f"'{right_emoji}' [right_emoji] is not a supported emoji.")
96
+
97
+ compatible = ", ".join(_emoji_at(index) for index, _ in _combos_of(right))
98
+ raise ValueError(
99
+ f"'{left}' is not compatible with '{right}'. Here are all emojis compatible with '{right}':\n[{compatible}]"
100
+ )
File without changes
@@ -0,0 +1,90 @@
1
+ import unittest
2
+
3
+ from emoji_mixer import (
4
+ BASE_URL,
5
+ EmojiCombo,
6
+ check_supported,
7
+ get_emoji_combo,
8
+ get_emoji_mix_url,
9
+ get_expanded_emoji_compatibility_data,
10
+ google_request_url_emoji_part,
11
+ supported_emojis,
12
+ to_unicode,
13
+ )
14
+
15
+
16
+ def url(date, left, right):
17
+ return f"{BASE_URL}/{date}/{left}/{left}_{right}.png"
18
+
19
+
20
+ class EmojiMixerTest(unittest.TestCase):
21
+ def test_mix_url_uses_googles_order_whichever_way_it_is_called(self):
22
+ self.assertEqual(get_emoji_mix_url("☕", "♈"), url(20260128, "u2615", "u2648"))
23
+ self.assertEqual(get_emoji_mix_url("♈", "☕"), url(20260128, "u2615", "u2648"))
24
+ self.assertEqual(get_emoji_mix_url("🔥", "😃"), url(20201001, "u1f603", "u1f525"))
25
+ self.assertEqual(get_emoji_mix_url("2615", "2615"), url(20201001, "u2615", "u2615"))
26
+
27
+ def test_mix_url_returns_none_for_unsupported_input_and_pairs(self):
28
+ for value in ["not an emoji", "abc", "deadbeef", "", "😀😀", None]:
29
+ self.assertIsNone(get_emoji_mix_url(value, "☕"))
30
+
31
+ self.assertIsNone(get_emoji_mix_url("☕", "🌳"))
32
+
33
+ def test_detailed_errors_name_the_problem(self):
34
+ with self.assertRaisesRegex(ValueError, r"'abc' \[left_emoji\]"):
35
+ get_emoji_mix_url("abc", "☕", True)
36
+
37
+ with self.assertRaisesRegex(ValueError, r"'abc' \[right_emoji\]"):
38
+ get_emoji_mix_url("☕", "abc", True)
39
+
40
+ with self.assertRaisesRegex(ValueError, "'2615' is not compatible with '1f333'"):
41
+ get_emoji_mix_url("☕", "🌳", True)
42
+
43
+ def test_to_unicode_accepts_exactly_one_supported_emoji(self):
44
+ self.assertEqual(to_unicode("☕"), "2615")
45
+ self.assertEqual(to_unicode("☕️"), "2615")
46
+ self.assertEqual(to_unicode("❤"), "2764-fe0f")
47
+ self.assertEqual(to_unicode("1F600"), "1f600")
48
+ self.assertEqual(to_unicode("😮‍💨"), "1f62e-200d-1f4a8")
49
+ self.assertEqual(to_unicode("❤️‍🩹"), "2764-fe0f-200d-1fa79")
50
+
51
+ for value in ["1f6", "2", "a", "☕ hello", "😀😀", "", None, 2615]:
52
+ self.assertIsNone(to_unicode(value))
53
+
54
+ def test_every_supported_emoji_resolves_to_itself(self):
55
+ for key in supported_emojis:
56
+ self.assertEqual(to_unicode("".join(chr(int(part, 16)) for part in key.split("-"))), key)
57
+ self.assertEqual(to_unicode(key.upper()), key)
58
+ self.assertTrue(check_supported(key))
59
+
60
+ def test_get_emoji_combo_returns_the_newest_combo_in_googles_order(self):
61
+ combo = EmojiCombo("2615", "2648", "20260128")
62
+
63
+ self.assertEqual(get_emoji_combo("2615", "2648"), combo)
64
+ self.assertEqual(get_emoji_combo("2648", "2615"), combo)
65
+ self.assertEqual(get_emoji_combo("2615", "2615"), EmojiCombo("2615", "2615", "20201001"))
66
+ self.assertIsNone(get_emoji_combo("2615", "deadbeef"))
67
+ self.assertIsNone(get_emoji_combo("$e", "2615"))
68
+
69
+ def test_check_supported_lists_combos_containing_the_emoji(self):
70
+ combos = check_supported("♈")
71
+
72
+ self.assertIn(EmojiCombo("2615", "2648", "20260128"), combos)
73
+ self.assertTrue(all("2648" in (combo.left_emoji, combo.right_emoji) for combo in combos))
74
+ self.assertIsNone(check_supported("abc"))
75
+
76
+ def test_expanded_data_covers_every_emoji(self):
77
+ expanded = get_expanded_emoji_compatibility_data()
78
+
79
+ self.assertEqual(list(expanded), supported_emojis)
80
+ self.assertEqual(expanded["2615"], check_supported("2615"))
81
+
82
+ def test_url_part_formats_codepoints(self):
83
+ self.assertEqual(
84
+ google_request_url_emoji_part("1f642-200d-2194-FE0F"),
85
+ "u1f642-u200d-u2194-ufe0f",
86
+ )
87
+
88
+
89
+ if __name__ == "__main__":
90
+ unittest.main()