Change missing section end brace error to work at EOF.
- Updated existing tests and added a new case to understand `@section {....` scenarios.
- Instead of trying to guess 1 character prior to EOF decided to log error on opening brace since we know its position. Updated error to account for change in location.
#625
This commit is contained in:
parent
5fecd5bd1e
commit
392871beb6
|
|
@ -114,6 +114,8 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
Accept(whitespace);
|
Accept(whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var startingBraceLocation = CurrentLocation;
|
||||||
|
|
||||||
// Set up edit handler
|
// Set up edit handler
|
||||||
var editHandler = new AutoCompleteEditHandler(Language.TokenizeString, autoCompleteAtEndOfSpan: true);
|
var editHandler = new AutoCompleteEditHandler(Language.TokenizeString, autoCompleteAtEndOfSpan: true);
|
||||||
|
|
||||||
|
|
@ -130,8 +132,11 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
{
|
{
|
||||||
editHandler.AutoCompleteString = "}";
|
editHandler.AutoCompleteString = "}";
|
||||||
Context.OnError(
|
Context.OnError(
|
||||||
CurrentLocation,
|
startingBraceLocation,
|
||||||
RazorResources.FormatParseError_Expected_X(Language.GetSample(CSharpSymbolType.RightBrace)),
|
RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF(
|
||||||
|
SyntaxConstants.CSharp.SectionKeyword,
|
||||||
|
Language.GetSample(CSharpSymbolType.RightBrace),
|
||||||
|
Language.GetSample(CSharpSymbolType.LeftBrace)),
|
||||||
length: 1 /* } */);
|
length: 1 /* } */);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
.Accepts(AcceptedCharacters.Any),
|
.Accepts(AcceptedCharacters.Any),
|
||||||
new MarkupBlock()),
|
new MarkupBlock()),
|
||||||
new RazorError(
|
new RazorError(
|
||||||
RazorResources.FormatParseError_Expected_X("}"),
|
RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("section", "}", "{"),
|
||||||
new SourceLocation(17, 0, 17),
|
new SourceLocation(16, 0, 16),
|
||||||
length: 1));
|
length: 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,8 +109,8 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
Factory.Markup("</p>")))),
|
Factory.Markup("</p>")))),
|
||||||
new RazorError(
|
new RazorError(
|
||||||
RazorResources.FormatParseError_Expected_X("}"),
|
RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("section", "}", "{"),
|
||||||
new SourceLocation(27 + Environment.NewLine.Length, 1, 10),
|
new SourceLocation(16, 0, 16),
|
||||||
length: 1));
|
length: 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -170,8 +170,30 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
.AutoCompleteWith("}", atEndOfSpan: true),
|
.AutoCompleteWith("}", atEndOfSpan: true),
|
||||||
new MarkupBlock())),
|
new MarkupBlock())),
|
||||||
new RazorError(
|
new RazorError(
|
||||||
RazorResources.FormatParseError_Expected_X("}"),
|
RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("section", "}", "{"),
|
||||||
new SourceLocation(14, 0, 14),
|
new SourceLocation(13, 0, 13),
|
||||||
|
length: 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(" ")]
|
||||||
|
[InlineData("\n")]
|
||||||
|
[InlineData(" abc")]
|
||||||
|
[InlineData(" \n abc")]
|
||||||
|
public void ParseSectionBlockHandlesEOFAfterOpenContent(string postStartBrace)
|
||||||
|
{
|
||||||
|
ParseDocumentTest("@section foo {" + postStartBrace,
|
||||||
|
new MarkupBlock(
|
||||||
|
Factory.EmptyHtml(),
|
||||||
|
new SectionBlock(new SectionChunkGenerator("foo"),
|
||||||
|
Factory.CodeTransition(),
|
||||||
|
Factory.MetaCode("section foo {")
|
||||||
|
.AutoCompleteWith("}", atEndOfSpan: true),
|
||||||
|
new MarkupBlock(
|
||||||
|
Factory.Markup(postStartBrace)))),
|
||||||
|
new RazorError(
|
||||||
|
RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("section", "}", "{"),
|
||||||
|
new SourceLocation(13, 0, 13),
|
||||||
length: 1));
|
length: 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,8 +216,43 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
Factory.Markup("</p>"))))),
|
Factory.Markup("</p>"))))),
|
||||||
new RazorError(
|
new RazorError(
|
||||||
RazorResources.FormatParseError_Expected_X("}"),
|
RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("section", "}", "{"),
|
||||||
new SourceLocation(27, 0, 27),
|
new SourceLocation(13, 0, 13),
|
||||||
|
length: 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ParseSectionBlockHandlesUnterminatedSectionWithNestedIf()
|
||||||
|
{
|
||||||
|
var newLine = Environment.NewLine;
|
||||||
|
var spaces = " ";
|
||||||
|
ParseDocumentTest(
|
||||||
|
string.Format(
|
||||||
|
"@section Test{0}{{{0}{1}@if(true){0}{1}{{{0}{1}{1}<p>Hello World</p>{0}{1}}}",
|
||||||
|
newLine,
|
||||||
|
spaces),
|
||||||
|
new MarkupBlock(
|
||||||
|
Factory.EmptyHtml(),
|
||||||
|
new SectionBlock(new SectionChunkGenerator("Test"),
|
||||||
|
Factory.CodeTransition(),
|
||||||
|
Factory.MetaCode($"section Test{newLine}{{")
|
||||||
|
.AutoCompleteWith("}", atEndOfSpan: true),
|
||||||
|
new MarkupBlock(
|
||||||
|
Factory.Markup(newLine),
|
||||||
|
new StatementBlock(
|
||||||
|
Factory.Code(spaces).AsStatement(),
|
||||||
|
Factory.CodeTransition(),
|
||||||
|
Factory.Code($"if(true){newLine}{spaces}{{{newLine}").AsStatement(),
|
||||||
|
new MarkupBlock(
|
||||||
|
Factory.Markup($"{spaces}{spaces}"),
|
||||||
|
BlockFactory.MarkupTagBlock("<p>", AcceptedCharacters.None),
|
||||||
|
Factory.Markup("Hello World"),
|
||||||
|
BlockFactory.MarkupTagBlock("</p>", AcceptedCharacters.None),
|
||||||
|
Factory.Markup(newLine).Accepts(AcceptedCharacters.None)),
|
||||||
|
Factory.Code($"{spaces}}}").AsStatement())))),
|
||||||
|
new RazorError(
|
||||||
|
RazorResources.FormatParseError_Expected_EndOfBlock_Before_EOF("section", "}", "{"),
|
||||||
|
new SourceLocation(13 + newLine.Length, 1, 0),
|
||||||
length: 1));
|
length: 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue