public void UnrecognizedEscapeSequenceError(string escapeSequence, int position) { var error = JsonParseErrors.UnrecognizedEscapeSequence(escapeSequence, position, escapeSequence.Length); Assert.Equal(JsonErrorCode.UnrecognizedEscapeSequence, error.ErrorCode); AssertErrorInfoParameters(error, new JsonErrorInfoParameter <string>(escapeSequence)); Assert.Equal(position, error.Start); Assert.Equal(escapeSequence.Length, error.Length); }
public void IllegalControlCharacterInStringError(char illegalControlCharacter, int position) { var error = JsonParseErrors.IllegalControlCharacterInString(illegalControlCharacter, position); Assert.Equal(JsonErrorCode.IllegalControlCharacterInString, error.ErrorCode); AssertErrorInfoParameters(error, new JsonErrorInfoParameter <char>(illegalControlCharacter)); Assert.Equal(position, error.Start); Assert.Equal(1, error.Length); }
public void UnexpectedSymbolError(char unexpectedCharacter, int position) { var error = JsonParseErrors.UnexpectedSymbol(unexpectedCharacter, position); Assert.NotNull(error); Assert.Equal(JsonErrorCode.UnexpectedSymbol, error.ErrorCode); AssertErrorInfoParameters(error, new JsonErrorInfoParameter <char>(unexpectedCharacter)); Assert.Equal(position, error.Start); Assert.Equal(1, error.Length); }
public void UnterminatedStringError(int start, int length) { var error = JsonParseErrors.UnterminatedString(start, length); Assert.NotNull(error); Assert.Equal(JsonErrorCode.UnterminatedString, error.ErrorCode); AssertErrorInfoParameters(error); Assert.Equal(start, error.Start); Assert.Equal(length, error.Length); }
public static IEnumerable <object[]> GetErrorStrings() { yield return(new object[] { "*", new[] { JsonParseErrors.UnexpectedSymbol('*', 0) } }); yield return(new object[] { " *", new[] { JsonParseErrors.UnexpectedSymbol('*', 1) } }); yield return(new object[] { " ° ", new[] { JsonParseErrors.UnexpectedSymbol('°', 2) } }); // Unterminated comments. yield return(new object[] { "/*", new[] { JsonParseErrors.UnterminatedMultiLineComment(0, 2) } }); yield return(new object[] { "/*\n\n", new[] { JsonParseErrors.UnterminatedMultiLineComment(0, 4) } }); yield return(new object[] { " /*\n\n*", new[] { JsonParseErrors.UnterminatedMultiLineComment(2, 5) } }); yield return(new object[] { " /*\n\n* /", new[] { JsonParseErrors.UnterminatedMultiLineComment(2, 7) } }); // Invalid strings. yield return(new object[] { "\"", new[] { JsonParseErrors.UnterminatedString(0, 1) } }); yield return(new object[] { "\"\\", new[] { JsonParseErrors.UnterminatedString(0, 2) } }); // Unterminated because the closing " is escaped. yield return(new object[] { "\"\\\"", new[] { JsonParseErrors.UnterminatedString(0, 3) } }); yield return(new object[] { "\"\\ \"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\ ", 1, 2) } }); yield return(new object[] { "\"\\e\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\e", 1, 2) } }); // Unicode escape sequences. yield return(new object[] { "\"\\u\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u", 1, 2) } }); yield return(new object[] { "\"\\ux\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u", 1, 2) } }); yield return(new object[] { "\"\\uxxxx\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u", 1, 2) } }); yield return(new object[] { "\"\\u0\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u0", 1, 3) } }); yield return(new object[] { "\"\\u00\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u00", 1, 4) } }); yield return(new object[] { "\"\\u000\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u000", 1, 5) } }); yield return(new object[] { "\"\\u000g\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u000", 1, 5) } }); // Prevent int.TryParse hacks. yield return(new object[] { "\"\\u-1000\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u", 1, 2) } }); // Disallow control characters. yield return(new object[] { "\"\n\"", new[] { JsonParseErrors.IllegalControlCharacterInString('\n', 1) } }); yield return(new object[] { "\"\t\"", new[] { JsonParseErrors.IllegalControlCharacterInString('\t', 1) } }); yield return(new object[] { "\"\0\"", new[] { JsonParseErrors.IllegalControlCharacterInString('\u0000', 1) } }); yield return(new object[] { "\"\u0001\"", new[] { JsonParseErrors.IllegalControlCharacterInString('\u0001', 1) } }); yield return(new object[] { "\"\u007f\"", new[] { JsonParseErrors.IllegalControlCharacterInString('\u007f', 1) } }); // Multiple errors. yield return(new object[] { " ∙\"∙\"\"", new JsonErrorInfo[] { JsonParseErrors.UnexpectedSymbol('∙', 1), JsonParseErrors.UnterminatedString(5, 1) } }); yield return(new object[] { "\"\r\n\"", new[] { JsonParseErrors.IllegalControlCharacterInString('\r', 1), JsonParseErrors.IllegalControlCharacterInString('\n', 2) } }); yield return(new object[] { "\"\\ ", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\ ", 1, 2), JsonParseErrors.UnterminatedString(0, 3) } }); yield return(new object[] { "\"\r\n∙\"∙", new[] { JsonParseErrors.IllegalControlCharacterInString('\r', 1), JsonParseErrors.IllegalControlCharacterInString('\n', 2), JsonParseErrors.UnexpectedSymbol('∙', 5) } }); yield return(new object[] { "\"\t\n", new[] { JsonParseErrors.IllegalControlCharacterInString('\t', 1), JsonParseErrors.IllegalControlCharacterInString('\n', 2), JsonParseErrors.UnterminatedString(0, 3) } }); yield return(new object[] { "\" \\ \n\"", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\ ", 2, 2), JsonParseErrors.IllegalControlCharacterInString('\n', 4) } }); yield return(new object[] { "\"\n\\ \n\"", new[] { JsonParseErrors.IllegalControlCharacterInString('\n', 1), JsonParseErrors.UnrecognizedEscapeSequence("\\ ", 2, 2), JsonParseErrors.IllegalControlCharacterInString('\n', 4) } }); yield return(new object[] { "\"\\u", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u", 1, 2), JsonParseErrors.UnterminatedString(0, 3) } }); yield return(new object[] { "\"\\uA", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\uA", 1, 3), JsonParseErrors.UnterminatedString(0, 4) } }); yield return(new object[] { "\"\\u\n", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\u", 1, 2), JsonParseErrors.IllegalControlCharacterInString('\n', 3), JsonParseErrors.UnterminatedString(0, 4) } }); yield return(new object[] { "\"\\ufff\n", new[] { JsonParseErrors.UnrecognizedEscapeSequence("\\ufff", 1, 5), JsonParseErrors.IllegalControlCharacterInString('\n', 6), JsonParseErrors.UnterminatedString(0, 7) } }); yield return(new object[] { "\"\n\\ ∙\"∙", new[] { JsonParseErrors.IllegalControlCharacterInString('\n', 1), JsonParseErrors.UnrecognizedEscapeSequence("\\ ", 2, 2), JsonParseErrors.UnexpectedSymbol('∙', 6) } }); yield return(new object[] { "∙\"\n\\ ∙\"", new[] { JsonParseErrors.UnexpectedSymbol('∙', 0), JsonParseErrors.IllegalControlCharacterInString('\n', 2), JsonParseErrors.UnrecognizedEscapeSequence("\\ ", 3, 2) } }); // Know what's unterminated. yield return(new object[] { "\"/*", new[] { JsonParseErrors.UnterminatedString(0, 3) } }); yield return(new object[] { "/*\"", new[] { JsonParseErrors.UnterminatedMultiLineComment(0, 3) } }); yield return(new object[] { "///*\n\"", new[] { JsonParseErrors.UnterminatedString(5, 1) } }); yield return(new object[] { "///*\"\n/*", new[] { JsonParseErrors.UnterminatedMultiLineComment(6, 2) } }); }