public void UnicodeToCodepoint() { string unicode = "๐"; // :grinning: string expected = "1f600"; string actual = EmojiOne.ToCodePoint(unicode); Assert.AreEqual(expected, actual); expected = "D83D-DE00"; actual = ShowX4(unicode); Assert.AreEqual(expected, actual); string codepoint = "1f600"; expected = "๐"; actual = EmojiOne.ToUnicode(codepoint); Assert.AreEqual(expected, actual); expected = "D83D-DE00"; actual = ShowX4(actual); Assert.AreEqual(expected, actual); expected = "\uD83D\uDE00"; actual = "๐"; Assert.AreEqual(expected, actual); expected = "\\uD83D\\uDE00"; actual = ToSurrogateString("1f600"); Assert.AreEqual(expected, actual); }
/// <summary> /// Converts a unicode character to surrogate pairs /// </summary> /// <param name="unicode"></param> /// <returns></returns> private static string ToSurrogateString(string codepoint) { string unicode = EmojiOne.ToUnicode(codepoint); string s2 = ""; for (int x = 0; x < unicode.Length; x++) { s2 += string.Format("\\u{0:X4}", (int)unicode[x]); } return(s2); }
public void FamilyEmoji() { string unicode = "๐จโ๐ฉโ๐งโ๐ฆ"; string codepoint = EmojiOne.ToCodePoint(unicode); string expected = "1f468-200d-1f469-200d-1f467-200d-1f466"; Assert.AreEqual(expected, codepoint); unicode = EmojiOne.ToUnicode(codepoint); string shortname = EmojiOne.ToShort(unicode); expected = ":family_mwgb:"; Assert.AreEqual(expected, shortname); unicode = "๐จโ๐ฉโ๐งโ๐ฆ"; shortname = EmojiOne.ToShort(unicode); expected = ":family_mwgb:"; Assert.AreEqual(expected, shortname, "Going from unicode > codepoint > unicode > shortname works, but going directly from unicode > shortname fails"); }