static String GetMessage(Utf8ExceptionType type) { switch (type) { case Utf8ExceptionType.StartedInsideCodePoint: return(StartedInsideCodePointMessage); case Utf8ExceptionType.MissingBytes: return(MissingBytesMessage); case Utf8ExceptionType.OutOfRange: return(OutOfRangeMessage); } return(GenericMessage); }
void TestInvalidUtf8(Utf8ExceptionType expectedError, params Byte[] s) { UInt32 start = 0; UInt32 limit = (UInt32)s.Length; try { var decoded = Utf8.Decode(s, ref start, limit); Assert.Fail("expected error '%s' but no error was thrown", expectedError); } catch (Utf8Exception e) { Assert.AreEqual(expectedError, e.type, String.Format("expected error '{0}' but got '{1}'", expectedError, e.type)); } Console.WriteLine("got expected error '{0}'", expectedError); }
public Utf8Exception(Utf8ExceptionType type) : base(GetMessage(type)) { this.type = type; }