public void EncodingEncodesThrowExceptionIfInvalidHexNumber() { Encoding encoding = new EscapeOutRangeEncoding("utf-8"); string input = "あ[@!!Q3]あ"; Assert.Throws <FormatException>(() => encoding.GetBytes(input)); }
public void EncodingEncodesThrowExceptionIfMissingEndToken() { Encoding encoding = new EscapeOutRangeEncoding("utf-8"); string input = "あ[@!!E3"; Assert.Throws <EncoderFallbackException>(() => encoding.GetBytes(input)); }
public void EncodingEncodesInvalidUtf8Symbols() { Encoding encoding = new EscapeOutRangeEncoding("utf-8"); string input = "あ[@!!E3]あ"; byte[] output = encoding.GetBytes(input); Assert.AreEqual(output.Length, encoding.GetByteCount(input)); Assert.Less(output.Length, encoding.GetMaxByteCount(3)); Assert.IsTrue(output.SequenceEqual(new byte[] { 0xE3, 0x81, 0x82, 0xE3, 0xE3, 0x81, 0x82 })); }
public void EncodingThrowsWithInvalidArguments() { Encoding encoding = new EscapeOutRangeEncoding("utf-8"); char[] input = "test".ToCharArray(); byte[] output = new byte[10]; Assert.Throws <ArgumentNullException>( () => encoding.GetBytes((char[])null, 0, 0, output, 0)); Assert.Throws <ArgumentOutOfRangeException>( () => encoding.GetBytes(input, -1, 1, output, 0)); Assert.Throws <ArgumentOutOfRangeException>( () => encoding.GetBytes(input, 10, 0, output, 0)); Assert.Throws <ArgumentOutOfRangeException>( () => encoding.GetBytes(input, 0, -1, output, 0)); Assert.Throws <ArgumentOutOfRangeException>( () => encoding.GetBytes(input, 2, 4, output, 0)); Assert.Throws <ArgumentNullException>( () => encoding.GetBytes(input, 0, 4, null, 0)); Assert.Throws <ArgumentOutOfRangeException>( () => encoding.GetBytes(input, 0, 4, output, -1)); Assert.Throws <ArgumentOutOfRangeException>( () => encoding.GetBytes(input, 0, 4, output, 15)); }