public void TestEmojis() { var encoding = new AsmEncoding(); string smiley = "😀"; // smiley face var expectedbytes = new byte[] { 0xF0, 0x9F, 0x98, 0x80 }; // utf-8 encoding of U+1F600 var testbytes = encoding.GetBytes(smiley); Assert.AreEqual(expectedbytes, testbytes); encoding.SelectEncoding("emojis"); encoding.Map("😀", 204); expectedbytes = new byte[] { 204 }; testbytes = encoding.GetBytes(smiley); Assert.AreEqual(expectedbytes, testbytes); encoding.SelectDefaultEncoding(); var expectedchars = smiley.ToCharArray(); var testchars = encoding.GetChars(new byte[] { 0xF0, 0x9F, 0x98, 0x80 }); Assert.AreEqual(expectedchars, testchars); }
public void TestEncodingGetChar() { var encoding = new AsmEncoding(); encoding.SelectEncoding("test"); string teststring = "τϵστ"; var testbytes = encoding.GetBytes(teststring); var expectedbytes = Encoding.UTF8.GetBytes(teststring); Assert.AreEqual(expectedbytes, testbytes); var testchars = encoding.GetChars(testbytes); var expectedchars = Encoding.UTF8.GetChars(expectedbytes); Assert.AreEqual(expectedchars, testchars); var testcharcount = encoding.GetChars(testbytes, 0, testbytes.Length, testchars, 0); var expectedcharcount = Encoding.UTF8.GetChars(expectedbytes, 0, expectedbytes.Length, expectedchars, 0); Assert.AreEqual(expectedcharcount, testcharcount); encoding.Map('τ', 0xff); expectedbytes = new byte[] { 0xff, 207, 181, 207, 131, 0xff }; testbytes = encoding.GetBytes(teststring); Assert.AreEqual(expectedbytes, testbytes); testchars = encoding.GetChars(testbytes); Assert.AreEqual(expectedchars, testchars); testcharcount = encoding.GetChars(testbytes, 0, testbytes.Length, testchars, 0); Assert.AreEqual(expectedcharcount, testcharcount); encoding.Unmap("τ"); expectedbytes = Encoding.UTF8.GetBytes(teststring); testbytes = encoding.GetBytes(teststring); Assert.AreEqual(expectedbytes, testbytes); testchars = encoding.GetChars(testbytes); Assert.AreEqual(expectedchars, testchars); testcharcount = encoding.GetChars(testbytes, 0, testbytes.Length, testchars, 0); Assert.AreEqual(expectedcharcount, testcharcount); }