Beispiel #1
0
        public void TestTextUtilsEncoding()
        {
            var value = $"\n \r \t 0 a A Ñ Ç £ ¢";

            Assert.IsFalse(TextUtils.CanEncode(Encoding.ASCII, value));
            Assert.IsTrue(TextUtils.CanEncode(Encoding.UTF8, value));

            var escapedValue = TextUtils.UnicodeToEscapedAscii(value);

            Assert.AreEqual(@"\u000a \u000d \u0009 0 a A \u00d1 \u00c7 \u00a3 \u00a2", escapedValue);

            Assert.IsTrue(TextUtils.CanEncode(Encoding.ASCII, escapedValue));
            Assert.IsTrue(TextUtils.CanEncode(Encoding.UTF8, escapedValue));

            Assert.AreEqual(value, TextUtils.EscapedAsciiToUnicode(escapedValue));
        }