diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs
index 4ea9c53bfb..db99a15e0b 100644
--- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs
+++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorFactoryTest.cs
@@ -1221,7 +1221,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
Assert.Equal(expectedErrorMessages.Length, errors.Length);
for (var i = 0; i < expectedErrorMessages.Length; i++)
{
- Assert.Equal(1, errors[i].Length);
+ Assert.Equal(0, errors[i].Length);
Assert.Equal(SourceLocation.Zero, errors[i].Location);
Assert.Equal(expectedErrorMessages[i], errors[i].Message, StringComparer.Ordinal);
}
@@ -1377,7 +1377,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
for (var i = 0; i < actualErrors.Length; i++)
{
var actualError = actualErrors[i];
- Assert.Equal(1, actualError.Length);
+ Assert.Equal(0, actualError.Length);
Assert.Equal(SourceLocation.Zero, actualError.Location);
Assert.Equal(expectedErrors[i], actualError.Message, StringComparer.Ordinal);
}
@@ -1607,7 +1607,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
for (var i = 0; i < errors.Length; i++)
{
- Assert.Equal(1, errors[i].Length);
+ Assert.Equal(0, errors[i].Length);
Assert.Equal(SourceLocation.Zero, errors[i].Location);
Assert.Equal(expectedErrorMessages[i], errors[i].Message, StringComparer.Ordinal);
}
@@ -1749,7 +1749,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
Assert.Equal(expectedErrorMessages.Length, errors.Length);
for (var i = 0; i < expectedErrorMessages.Length; i++)
{
- Assert.Equal(1, errors[i].Length);
+ Assert.Equal(0, errors[i].Length);
Assert.Equal(SourceLocation.Zero, errors[i].Location);
Assert.Equal(expectedErrorMessages[i], errors[i].Message, StringComparer.Ordinal);
}
@@ -1804,7 +1804,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
Assert.Equal(expectedErrorMessages.Length, errors.Length);
for (var i = 0; i < expectedErrorMessages.Length; i++)
{
- Assert.Equal(1, errors[i].Length);
+ Assert.Equal(0, errors[i].Length);
Assert.Equal(SourceLocation.Zero, errors[i].Location);
Assert.Equal(expectedErrorMessages[i], errors[i].Message, StringComparer.Ordinal);
}
@@ -1837,7 +1837,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
// Arrange
var errorSink = new ErrorSink();
- var expectedErrors = expectedErrorMessages.Select(message => new RazorError(message, SourceLocation.Zero));
+ var expectedErrors = expectedErrorMessages.Select(
+ message => new RazorError(message, SourceLocation.Zero, 0));
// Act
TagHelperDescriptorFactory.GetValidAllowedChildren(new[] { name }, "SomeTagHelper", errorSink);
diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorResolverTest.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorResolverTest.cs
index dd4ac0f4e5..526694b5d5 100644
--- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorResolverTest.cs
+++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperDescriptorResolverTest.cs
@@ -47,6 +47,39 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
}
}
+ [Theory]
+ [InlineData("foo,assemblyName", 4)]
+ [InlineData("foo, assemblyName", 5)]
+ [InlineData(" foo, assemblyName", 8)]
+ [InlineData(" foo , assemblyName", 11)]
+ [InlineData("foo, assemblyName", 8)]
+ [InlineData(" foo , assemblyName ", 14)]
+ public void Resolve_CalculatesAssemblyLocationInLookupText(string lookupText, int assemblyLocation)
+ {
+ // Arrange
+ var errorSink = new ErrorSink();
+ var tagHelperDescriptorResolver = new InspectableTagHelperDescriptorResolver();
+ var directiveType = TagHelperDirectiveType.AddTagHelper;
+ var resolutionContext = new TagHelperDescriptorResolutionContext(
+ new[]
+ {
+ new TagHelperDirectiveDescriptor
+ {
+ DirectiveText = lookupText,
+ Location = SourceLocation.Zero,
+ DirectiveType = directiveType
+ }
+ },
+ errorSink);
+ var expectedSourceLocation = new SourceLocation(assemblyLocation, 0, assemblyLocation);
+
+ // Act
+ tagHelperDescriptorResolver.Resolve(resolutionContext);
+
+ // Assert
+ Assert.Empty(errorSink.Errors);
+ Assert.Equal(expectedSourceLocation, tagHelperDescriptorResolver.DocumentLocation);
+ }
public static TheoryData ResolveDirectiveDescriptorsInvalidTagHelperPrefixData
{
@@ -94,7 +127,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
new RazorError(
string.Format(multipleDirectiveError, SyntaxConstants.CSharp.TagHelperPrefixKeyword),
- directiveLocation2)
+ directiveLocation2,
+ length: 9)
}
},
{
@@ -125,7 +159,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
new RazorError(
string.Format(multipleDirectiveError, SyntaxConstants.CSharp.TagHelperPrefixKeyword),
- directiveLocation2)
+ directiveLocation2,
+ length: 9)
}
},
{
@@ -162,7 +197,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
new RazorError(
string.Format(multipleDirectiveError, SyntaxConstants.CSharp.TagHelperPrefixKeyword),
- directiveLocation2)
+ directiveLocation2,
+ length: 9)
}
},
{
@@ -185,7 +221,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
' ',
"th "),
- directiveLocation1)
+ directiveLocation1,
+ length: 3)
}
},
{
@@ -208,7 +245,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
'\t',
"th\t"),
- directiveLocation1)
+ directiveLocation1,
+ length: 3)
}
},
{
@@ -231,7 +269,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
Environment.NewLine[0],
"th" + Environment.NewLine),
- directiveLocation1)
+ directiveLocation1,
+ length: 2 + Environment.NewLine.Length)
}
},
{
@@ -254,7 +293,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
' ',
" th "),
- directiveLocation1)
+ directiveLocation1,
+ length: 4)
}
},
{
@@ -277,7 +317,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
'@',
"@"),
- directiveLocation1)
+ directiveLocation1,
+ length: 1)
}
},
{
@@ -300,7 +341,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
'@',
"t@h"),
- directiveLocation1)
+ directiveLocation1,
+ length: 3)
}
},
{
@@ -323,7 +365,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
'!',
"!"),
- directiveLocation1)
+ directiveLocation1,
+ length: 1)
}
},
{
@@ -346,7 +389,8 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
'!',
"!th"),
- directiveLocation1)
+ directiveLocation1,
+ length: 3)
}
},
};
@@ -1336,20 +1380,20 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
}
[Theory]
- [InlineData("")]
- [InlineData(null)]
- [InlineData("*,")]
- [InlineData("?,")]
- [InlineData(",")]
- [InlineData(",,,")]
- [InlineData("First, ")]
- [InlineData("First , ")]
- [InlineData(" ,Second")]
- [InlineData(" , Second")]
- [InlineData("SomeType,")]
- [InlineData("SomeAssembly")]
- [InlineData("First,Second,Third")]
- public void DescriptorResolver_CreatesErrorIfInvalidLookupText_DoesNotThrow(string lookupText)
+ [InlineData("", 1)]
+ [InlineData(null, 1)]
+ [InlineData("*,", 2)]
+ [InlineData("?,", 2)]
+ [InlineData(",", 1)]
+ [InlineData(",,,", 3)]
+ [InlineData("First, ", 7)]
+ [InlineData("First , ", 8)]
+ [InlineData(" ,Second", 8)]
+ [InlineData(" , Second", 9)]
+ [InlineData("SomeType,", 9)]
+ [InlineData("SomeAssembly", 12)]
+ [InlineData("First,Second,Third", 18)]
+ public void DescriptorResolver_CreatesErrorIfInvalidLookupText_DoesNotThrow(string lookupText, int errorLength)
{
// Arrange
var errorSink = new ErrorSink();
@@ -1379,7 +1423,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
// Assert
var error = Assert.Single(errorSink.Errors);
- Assert.Equal(1, error.Length);
+ Assert.Equal(errorLength, error.Length);
Assert.Equal(documentLocation, error.Location);
Assert.Equal(expectedErrorMessage, error.Message);
}
@@ -1414,7 +1458,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
// Assert
var error = Assert.Single(errorSink.Errors);
- Assert.Equal(1, error.Length);
+ Assert.Equal(21, error.Length);
Assert.Equal(documentLocation, error.Location);
Assert.Equal(expectedErrorMessage, error.Message);
}
@@ -1475,6 +1519,26 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
};
}
+ public class InspectableTagHelperDescriptorResolver : TagHelperDescriptorResolver
+ {
+ public InspectableTagHelperDescriptorResolver()
+ : base(designTime: false)
+ {
+ }
+
+ public SourceLocation DocumentLocation { get; private set; }
+
+ protected override IEnumerable
Hello
""). If you intended to display a ""<"" character, use the ""<"" HTML entity.", new SourceLocation(1, 0, 1)), - new RazorError(@"The code block is missing a closing ""}"" character. Make sure you have a matching ""}"" character for all the ""{"" characters within this block, and that none of the ""}"" characters are being interpreted as markup.", new SourceLocation(0, 0, 0)), + new RazorError( + @"End of file or an unexpected character was reached before the ""span"" tag could be parsed. Elements inside markup blocks must be complete. They must either be self-closing (""Hello
""). If you intended to display a ""<"" character, use the ""<"" HTML entity.", + new SourceLocation(2, 0, 2), + length: 4), + new RazorError( + @"The code block is missing a closing ""}"" character. Make sure you have a matching ""}"" character for all the ""{"" characters within this block, and that none of the ""}"" characters are being interpreted as markup.", + SourceLocation.Zero, + length: 1), }; // Act & Assert @@ -1139,8 +1159,14 @@ catch(bar) { baz(); }", BlockType.Statement, SpanKind.Code); Factory.MetaCode("}").Accepts(AcceptedCharacters.None)); var expectedErrors = new RazorError[] { - new RazorError(@"A space or line break was encountered after the ""@"" character. Only valid identifiers, keywords, comments, ""("" and ""{"" are valid at the start of a code block and they must occur immediately following ""@"" with no space in between.", new SourceLocation(13, 0, 13)), - new RazorError(@"""' />}"" is not valid at the start of a code block. Only identifiers, keywords, comments, ""("" and ""{"" are valid.", new SourceLocation(15, 0, 15)), + new RazorError( + @"A space or line break was encountered after the ""@"" character. Only valid identifiers, keywords, comments, ""("" and ""{"" are valid at the start of a code block and they must occur immediately following ""@"" with no space in between.", + new SourceLocation(13, 0, 13), + length: 1), + new RazorError( + @"""' />}"" is not valid at the start of a code block. Only identifiers, keywords, comments, ""("" and ""{"" are valid.", + new SourceLocation(15, 0, 15), + length: 5), }; // Act & Assert @@ -1187,7 +1213,7 @@ catch(bar) { baz(); }", BlockType.Statement, SpanKind.Code); { errors = new RazorError[] { - new RazorError(errorMessage, location.Value) + new RazorError(errorMessage, location.Value, length: 1) }; } ParseBlockTest(content, diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs index ac25e18729..79cd217c7c 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .AsTagHelperPrefixDirective("Foo")), new RazorError( RazorResources.ParseError_Unterminated_String_Literal, - absoluteIndex: 17, lineIndex: 0, columnIndex: 17), + absoluteIndex: 17, lineIndex: 0, columnIndex: 17, length: 1), new RazorError( RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( SyntaxConstants.CSharp.TagHelperPrefixKeyword), @@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .Accepts(AcceptedCharacters.AnyExceptNewline)), new RazorError( RazorResources.ParseError_Unterminated_String_Literal, - absoluteIndex: 20, lineIndex: 0, columnIndex: 20), + absoluteIndex: 20, lineIndex: 0, columnIndex: 20, length: 1), new RazorError( RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( SyntaxConstants.CSharp.TagHelperPrefixKeyword), @@ -168,7 +168,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .AsRemoveTagHelper("Foo")), new RazorError( RazorResources.ParseError_Unterminated_String_Literal, - absoluteIndex: 17, lineIndex: 0, columnIndex: 17), + absoluteIndex: 17, lineIndex: 0, columnIndex: 17, length: 1), new RazorError( RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( SyntaxConstants.CSharp.RemoveTagHelperKeyword), @@ -188,7 +188,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .Accepts(AcceptedCharacters.AnyExceptNewline)), new RazorError( RazorResources.ParseError_Unterminated_String_Literal, - absoluteIndex: 20, lineIndex: 0, columnIndex: 20), + absoluteIndex: 20, lineIndex: 0, columnIndex: 20, length: 1), new RazorError( RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( SyntaxConstants.CSharp.RemoveTagHelperKeyword), @@ -264,7 +264,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .AsAddTagHelper("Foo")), new RazorError( RazorResources.ParseError_Unterminated_String_Literal, - absoluteIndex: 14, lineIndex: 0, columnIndex: 14), + absoluteIndex: 14, lineIndex: 0, columnIndex: 14, length: 1), new RazorError( RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( SyntaxConstants.CSharp.AddTagHelperKeyword), @@ -284,7 +284,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .Accepts(AcceptedCharacters.AnyExceptNewline)), new RazorError( RazorResources.ParseError_Unterminated_String_Literal, - absoluteIndex: 17, lineIndex: 0, columnIndex: 17), + absoluteIndex: 17, lineIndex: 0, columnIndex: 17, length: 1), new RazorError( RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( SyntaxConstants.CSharp.AddTagHelperKeyword), diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpErrorTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpErrorTest.cs index 6383fb25e3..409da532cf 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpErrorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpErrorTest.cs @@ -23,7 +23,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS('"'), - 1, 0, 1)); + new SourceLocation(1, 0, 1), + length: 1)); } [Fact] @@ -48,7 +49,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(RazorResources.BlockName_Code, "}", "{"), - SourceLocation.Zero)); + SourceLocation.Zero, + length: 1)); } [Fact] @@ -73,7 +75,10 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp Factory.EmptyCSharp() .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharacters.NonWhiteSpace)), - new RazorError(RazorResources.ParseError_Unexpected_WhiteSpace_At_Start_Of_CodeBlock_CS, new SourceLocation(1, 0, 1))); + new RazorError( + RazorResources.ParseError_Unexpected_WhiteSpace_At_Start_Of_CodeBlock_CS, + new SourceLocation(1, 0, 1), + Environment.NewLine.Length)); } [Fact] @@ -95,7 +100,10 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp Factory.Code(" {}" + Environment.NewLine).AsStatement(), Factory.MetaCode("}").Accepts(AcceptedCharacters.None) ), - new RazorError(RazorResources.ParseError_Unexpected_WhiteSpace_At_Start_Of_CodeBlock_CS, 6 + Environment.NewLine.Length, 1, 5)); + new RazorError( + RazorResources.ParseError_Unexpected_WhiteSpace_At_Start_Of_CodeBlock_CS, + new SourceLocation(6 + Environment.NewLine.Length, 1, 5), + length: 3)); } [Fact] @@ -116,10 +124,12 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp Factory.EmptyCSharp().AsStatement() ), new RazorError( - RazorResources.ParseError_Unexpected_EndOfFile_At_Start_Of_CodeBlock, 6 + Environment.NewLine.Length, 1, 5), + RazorResources.ParseError_Unexpected_EndOfFile_At_Start_Of_CodeBlock, + 6 + Environment.NewLine.Length, 1, 5, length: 1), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(RazorResources.BlockName_Code, "}", "{"), - SourceLocation.Zero)); + SourceLocation.Zero, + length: 1)); } [Fact] @@ -133,7 +143,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .Accepts(AcceptedCharacters.NonWhiteSpace)), new RazorError( RazorResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("!"), - 1, 0, 1)); + new SourceLocation(1, 0, 1), + length: 1)); } [Fact] @@ -147,7 +158,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(RazorResources.BlockName_ExplicitExpression, ')', '('), - new SourceLocation(0, 0, 0))); + SourceLocation.Zero, + length: 1)); } [Fact] @@ -163,7 +175,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(RazorResources.BlockName_ExplicitExpression, ')', '('), - new SourceLocation(0, 0, 0))); + SourceLocation.Zero, + length: 1)); } [Fact] @@ -177,7 +190,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(4, 0, 4))); + new SourceLocation(4, 0, 4), + length: 1)); } [Fact] @@ -185,14 +199,16 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp public void ParseBlockShouldReportErrorAndTerminateAtEOFIfParenInImplicitExpressionUnclosed() { ParseBlockTest("Foo(Bar(Baz)" + Environment.NewLine - + "Biz" + Environment.NewLine - + "Boz", - new ExpressionBlock( - Factory.Code($"Foo(Bar(Baz){Environment.NewLine}Biz{Environment.NewLine}Boz") - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - ), - new RazorError(RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(3, 0, 3))); + + "Biz" + Environment.NewLine + + "Boz", + new ExpressionBlock( + Factory.Code($"Foo(Bar(Baz){Environment.NewLine}Biz{Environment.NewLine}Boz") + .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) + ), + new RazorError( + RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), + new SourceLocation(3, 0, 3), + length: 1)); } [Fact] @@ -200,16 +216,18 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp public void ParseBlockShouldReportErrorAndTerminateAtMarkupIfParenInImplicitExpressionUnclosed() { ParseBlockTest("Foo(Bar(Baz)" + Environment.NewLine - + "Biz" + Environment.NewLine - + "" + Environment.NewLine - + "Boz" + Environment.NewLine - + "", - new ExpressionBlock( - Factory.Code($"Foo(Bar(Baz){Environment.NewLine}Biz{Environment.NewLine}") - .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) - ), - new RazorError(RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(3, 0, 3))); + + "Biz" + Environment.NewLine + + "" + Environment.NewLine + + "Boz" + Environment.NewLine + + "", + new ExpressionBlock( + Factory.Code($"Foo(Bar(Baz){Environment.NewLine}Biz{Environment.NewLine}") + .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) + ), + new RazorError( + RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), + new SourceLocation(3, 0, 3), + length: 1)); } [Fact] @@ -225,7 +243,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("[", "]"), - new SourceLocation(3, 0, 3))); + new SourceLocation(3, 0, 3), + length: 1)); } [Fact] @@ -243,7 +262,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("[", "]"), - new SourceLocation(3, 0, 3))); + new SourceLocation(3, 0, 3), + length: 1)); } // Simple EOF handling errors: @@ -257,8 +277,10 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .AsStatement() .AutoCompleteWith("}")), new RazorError( - RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(RazorResources.BlockName_Code, '}', '{'), - SourceLocation.Zero)); + RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF( + RazorResources.BlockName_Code, '}', '{'), + SourceLocation.Zero, + length: 1)); } [Fact] @@ -272,7 +294,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp .AutoCompleteWith("}")), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("functions", '}', '{'), - new SourceLocation(10, 0, 10))); + new SourceLocation(10, 0, 10), + length: 1)); } [Fact] @@ -290,7 +313,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("else", '}', '{'), - new SourceLocation(19, 0, 19))); + new SourceLocation(19, 0, 19), + length: 1)); } [Fact] @@ -302,7 +326,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("else if", '}', '{'), - new SourceLocation(19, 0, 19))); + new SourceLocation(19, 0, 19), + length: 1)); } [Fact] @@ -314,7 +339,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("do", '}', '{'), - SourceLocation.Zero)); + SourceLocation.Zero, + length: 1)); } [Fact] @@ -326,7 +352,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("try", '}', '{'), - SourceLocation.Zero)); + SourceLocation.Zero, + length: 1)); } [Fact] @@ -338,7 +365,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("catch", '}', '{'), - new SourceLocation(15, 0, 15))); + new SourceLocation(15, 0, 15), + length: 1)); } [Fact] @@ -350,7 +378,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("finally", '}', '{'), - new SourceLocation(15, 0, 15))); + new SourceLocation(15, 0, 15), + length: 1)); } [Fact] @@ -414,9 +443,9 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp BlockFactory.MarkupTagBlock("", AcceptedCharacters.None)), Factory.EmptyCSharp().AsStatement() ), - new RazorError(expectedMessage, 8, 0, 8), - new RazorError(expectedMessage, 32, 0, 32), - new RazorError(expectedMessage, 48, 0, 48)); + new RazorError(expectedMessage, 8, 0, 8, 1), + new RazorError(expectedMessage, 32, 0, 32, 1), + new RazorError(expectedMessage, 48, 0, 48, 1)); } [Fact] @@ -428,7 +457,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_SingleLine_ControlFlowStatements_Not_Allowed("{", ")"), - new SourceLocation(7, 0, 7))); + new SourceLocation(7, 0, 7), + length: 1)); } [Fact] @@ -448,7 +478,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.ParseError_AtInCode_Must_Be_Followed_By_Colon_Paren_Or_Identifier_Start, - 10, 0, 10)); + new SourceLocation(10, 0, 10), + length: 1)); } [Fact] @@ -461,7 +492,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(2, 0, 2))); + new SourceLocation(2, 0, 2), + length: 1)); } [Fact] @@ -474,7 +506,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(7, 0, 7))); + new SourceLocation(7, 0, 7), + length: 1)); } [Fact] @@ -487,7 +520,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(12, 0, 12))); + new SourceLocation(12, 0, 12), + length: 1)); } [Fact] @@ -500,7 +534,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(5, 0, 5))); + new SourceLocation(5, 0, 5), + length: 1)); } [Fact] @@ -520,7 +555,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - new SourceLocation(2, 0, 2))); + new SourceLocation(2, 0, 2), + length: 1)); } [Fact] @@ -532,15 +568,23 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp + "}", BlockType.Statement, SpanKind.Code, new RazorError( - RazorResources.ParseError_Unterminated_String_Literal, 21 + Environment.NewLine.Length, 1, 12)); + RazorResources.ParseError_Unterminated_String_Literal, + new SourceLocation(21 + Environment.NewLine.Length, 1, 12), + length: 1)); } [Fact] public void ParseBlockTerminatesNormalStringAtEndOfFile() { SingleSpanBlockTest("if(foo) { var foo = \"blah blah blah blah blah", BlockType.Statement, SpanKind.Code, - new RazorError(RazorResources.ParseError_Unterminated_String_Literal, 20, 0, 20), - new RazorError(RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("if", '}', '{'), SourceLocation.Zero)); + new RazorError( + RazorResources.ParseError_Unterminated_String_Literal, + new SourceLocation(20, 0, 20), + length: 1), + new RazorError( + RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("if", '}', '{'), + SourceLocation.Zero, + length: 1)); } [Fact] @@ -552,8 +596,14 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp + "blah " + Environment.NewLine + "blah", BlockType.Statement, SpanKind.Code, - new RazorError(RazorResources.ParseError_Unterminated_String_Literal, 20, 0, 20), - new RazorError(RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("if", '}', '{'), SourceLocation.Zero)); + new RazorError( + RazorResources.ParseError_Unterminated_String_Literal, + new SourceLocation(20, 0, 20), + length: 1), + new RazorError( + RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("if", '}', '{'), + SourceLocation.Zero, + length: 1)); } [Fact] @@ -579,7 +629,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new RazorError( RazorResources.ParseError_Unterminated_String_Literal, - 23 + Environment.NewLine.Length, 1, 14)); + new SourceLocation(23 + Environment.NewLine.Length, 1, 14), + length: 1)); } [Fact] @@ -611,15 +662,22 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp { new RazorError( RazorResources.FormatParseError_Expected_CloseBracket_Before_EOF("(", ")"), - 14, 0, 14) + new SourceLocation(14, 0, 14), + length: 1) }); } private void RunUnterminatedSimpleKeywordBlock(string keyword) { - SingleSpanBlockTest(keyword + " (foo) { var foo = bar; if(foo != null) { bar(); } ", BlockType.Statement, SpanKind.Code, - new RazorError(RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(keyword, '}', '{'), SourceLocation.Zero)); + SingleSpanBlockTest( + keyword + " (foo) { var foo = bar; if(foo != null) { bar(); } ", + BlockType.Statement, + SpanKind.Code, + new RazorError( + RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(keyword, '}', '{'), + SourceLocation.Zero, + length: 1)); } } } diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpExplicitExpressionTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpExplicitExpressionTest.cs index 6a3276eff4..95ca36732d 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpExplicitExpressionTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpExplicitExpressionTest.cs @@ -32,8 +32,10 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp Factory.EmptyCSharp().AsExpression() ), new RazorError( - RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(RazorResources.BlockName_ExplicitExpression, ")", "("), - new SourceLocation(1, 0, 1))); + RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF( + RazorResources.BlockName_ExplicitExpression, ")", "("), + new SourceLocation(1, 0, 1), + length: 1)); } [Fact] diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpImplicitExpressionTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpImplicitExpressionTest.cs index 750c4d5e1b..d22864ba8e 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpImplicitExpressionTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpImplicitExpressionTest.cs @@ -26,12 +26,18 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp Func", AcceptedCharacters.None),
BlockFactory.MarkupTagBlock(">", AcceptedCharacters.None),
Factory.Markup(" ").Accepts(AcceptedCharacters.None)),
- new RazorError(RazorResources.FormatParseError_MissingEndTag("p"), 0, 0, 0));
+ new RazorError(
+ RazorResources.FormatParseError_MissingEndTag("p"),
+ new SourceLocation(1, 0, 1),
+ length: 1));
}
[Fact]
diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs
index 53c2acbc4a..4f1498f50d 100644
--- a/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs
+++ b/test/Microsoft.AspNet.Razor.Test/Parser/ParserVisitorExtensionsTest.cs
@@ -41,8 +41,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser
var errorSink = new ErrorSink();
List Hello
Hello
Title:
Something