Files
acceptance-tests
data
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
packages
src
test
Microsoft.TestCommon
Microsoft.Web.Helpers.Test
Microsoft.Web.Http.Data.Test
Microsoft.Web.Mvc.Test
Microsoft.Web.WebPages.OAuth.Test
SPA.Test
System.Json.Test.Integration
System.Json.Test.Unit
System.Net.Http.Formatting.Test.Integration
System.Net.Http.Formatting.Test.Unit
System.Web.Helpers.Test
System.Web.Http.Integration.Test
System.Web.Http.SelfHost.Test
System.Web.Http.Test
System.Web.Http.WebHost.Test
System.Web.Mvc.Test
System.Web.Razor.Test
Editor
Framework
Generator
Parser
CSharp
Html
Old
PartialParsing
VB
VBAutoCompleteTest.cs
VBBlockTest.cs
VBContinueStatementTest.cs
VBDirectiveTest.cs
VBErrorTest.cs
VBExitStatementTest.cs
VBExplicitExpressionTest.cs
VBExpressionTest.cs
VBExpressionsInCodeTest.cs
VBHelperTest.cs
VBHtmlDocumentTest.cs
VBImplicitExpressionTest.cs
VBLayoutDirectiveTest.cs
VBNestedStatementsTest.cs
VBRazorCommentsTest.cs
VBReservedWordsTest.cs
VBSectionTest.cs
VBSpecialKeywordsTest.cs
VBStatementTest.cs
VBTemplateTest.cs
VBToMarkupSwitchTest.cs
BlockTest.cs
CallbackParserListenerTest.cs
ParserContextTest.cs
ParserVisitorExtensionsTest.cs
RazorParserTest.cs
WhitespaceRewriterTest.cs
Properties
TestFiles
Text
Tokenizer
Utils
CSharpRazorCodeLanguageTest.cs
CodeCompileUnitExtensions.cs
RazorCodeLanguageTest.cs
RazorDirectiveAttributeTest.cs
RazorEngineHostTest.cs
RazorTemplateEngineTest.cs
StringTextBuffer.cs
System.Web.Razor.Test.csproj
VBRazorCodeLanguageTest.cs
packages.config
System.Web.WebPages.Administration.Test
System.Web.WebPages.Deployment.Test
System.Web.WebPages.Razor.Test
System.Web.WebPages.Test
WebMatrix.Data.Test
WebMatrix.WebData.Test
Settings.StyleCop
tools
.gitattributes
.gitignore
License.txt
README.md
Runtime.msbuild
Runtime.sln
Runtime.xunit
Settings.StyleCop
build.cmd
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
ikvm-native
libgc
llvm
m4
man
mcs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h

278 lines
12 KiB
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Resources;
using System.Web.Razor.Test.Framework;
using Xunit;
namespace System.Web.Razor.Test.Parser.VB
{
public class VBSectionTest : VBHtmlMarkupParserTestBase
{
[Fact]
public void ParseSectionBlockCapturesNewlineImmediatelyFollowing()
{
ParseDocumentTest(@"@Section
",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator(String.Empty),
Factory.CodeTransition(),
Factory.MetaCode("Section\r\n"),
new MarkupBlock())),
new RazorError(
String.Format(
RazorResources.ParseError_Unexpected_Character_At_Section_Name_Start,
RazorResources.ErrorComponent_EndOfFile),
10, 1, 0),
new RazorError(
String.Format(
RazorResources.ParseError_BlockNotTerminated,
"Section", "End Section"),
1, 0, 1));
}
[Fact]
public void ParseSectionRequiresNameBeOnSameLineAsSectionKeyword()
{
ParseDocumentTest(@"@Section
Foo
<p>Body</p>
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator(String.Empty),
Factory.CodeTransition(),
Factory.MetaCode("Section "),
new MarkupBlock(
Factory.Markup("\r\nFoo\r\n <p>Body</p>\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()),
new RazorError(
String.Format(
RazorResources.ParseError_Unexpected_Character_At_Section_Name_Start,
RazorResources.ErrorComponent_Newline),
9, 0, 9));
}
[Fact]
public void ParseSectionAllowsNameToBeOnDifferentLineAsSectionKeywordIfUnderscoresUsed()
{
ParseDocumentTest(@"@Section _
_
Foo
<p>Body</p>
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("Foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section _\r\n_\r\nFoo"),
new MarkupBlock(
Factory.Markup("\r\n <p>Body</p>\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()));
}
[Fact]
public void ParseSectionReportsErrorAndTerminatesSectionBlockIfKeywordNotFollowedByIdentifierStartCharacter()
{
ParseDocumentTest(@"@Section 9
<p>Foo</p>
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator(String.Empty),
Factory.CodeTransition(),
Factory.MetaCode("Section "),
new MarkupBlock(
Factory.Markup("9\r\n <p>Foo</p>\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()),
new RazorError(
String.Format(
RazorResources.ParseError_Unexpected_Character_At_Section_Name_Start,
String.Format(RazorResources.ErrorComponent_Character, "9")),
9, 0, 9));
}
[Fact]
public void ParserOutputsErrorOnNestedSections()
{
ParseDocumentTest(@"@Section foo
@Section bar
<p>Foo</p>
End Section
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section foo"),
new MarkupBlock(
Factory.Markup("\r\n"),
new SectionBlock(new SectionCodeGenerator("bar"),
Factory.Code(" ").AsStatement(),
Factory.CodeTransition(),
Factory.MetaCode("Section bar"),
new MarkupBlock(
Factory.Markup("\r\n <p>Foo</p>\r\n ")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.Markup("\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()),
new RazorError(
String.Format(
RazorResources.ParseError_Sections_Cannot_Be_Nested,
RazorResources.SectionExample_VB),
26, 1, 12));
}
[Fact]
public void ParseSectionHandlesEOFAfterIdentifier()
{
ParseDocumentTest("@Section foo",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section foo")
.AutoCompleteWith(SyntaxConstants.VB.EndSectionKeyword),
new MarkupBlock())),
new RazorError(
String.Format(
RazorResources.ParseError_BlockNotTerminated,
"Section", "End Section"),
1, 0, 1));
}
[Fact]
public void ParseSectionHandlesUnterminatedSection()
{
ParseDocumentTest(@"@Section foo
<p>Foo</p>",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section foo")
.AutoCompleteWith(SyntaxConstants.VB.EndSectionKeyword),
new MarkupBlock(
Factory.Markup("\r\n <p>Foo</p>")))),
new RazorError(
String.Format(
RazorResources.ParseError_BlockNotTerminated,
"Section", "End Section"),
1, 0, 1));
}
[Fact]
public void ParseDocumentParsesNamedSectionCorrectly()
{
ParseDocumentTest(@"@Section foo
<p>Foo</p>
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section foo"),
new MarkupBlock(
Factory.Markup("\r\n <p>Foo</p>\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()));
}
[Fact]
public void ParseSectionTerminatesOnFirstEndSection()
{
ParseDocumentTest(@"@Section foo
<p>End Section</p>",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section foo"),
new MarkupBlock(
Factory.Markup("\r\n <p>")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.Markup("</p>")));
}
[Fact]
public void ParseSectionAllowsEndSectionInVBExpression()
{
ParseDocumentTest(@"@Section foo
I really want to render the word @(""End Section""), so this is how I do it
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section foo"),
new MarkupBlock(
Factory.Markup("\r\n I really want to render the word "),
new ExpressionBlock(
Factory.CodeTransition(),
Factory.MetaCode("(").Accepts(AcceptedCharacters.None),
Factory.Code("\"End Section\"").AsExpression(),
Factory.MetaCode(")").Accepts(AcceptedCharacters.None)),
Factory.Markup(", so this is how I do it\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()));
}
// These are tests that are normally in HtmlToCodeSwitchTest, but we want to verify them for VB
// since VB has slightly different section terminating behavior which follow slightly different
// code paths
[Fact]
public void SectionBodyTreatsTwoAtSignsAsEscapeSequence()
{
ParseDocumentTest(@"@Section Foo
<foo>@@bar</foo>
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("Foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section Foo").AutoCompleteWith(null),
new MarkupBlock(
Factory.Markup("\r\n <foo>"),
Factory.Markup("@").Hidden(),
Factory.Markup("@bar</foo>\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()));
}
[Fact]
public void SectionBodyTreatsPairsOfAtSignsAsEscapeSequence()
{
ParseDocumentTest(@"@Section Foo
<foo>@@@@@bar</foo>
End Section",
new MarkupBlock(
Factory.EmptyHtml(),
new SectionBlock(new SectionCodeGenerator("Foo"),
Factory.CodeTransition(),
Factory.MetaCode("Section Foo").AutoCompleteWith(null),
new MarkupBlock(
Factory.Markup("\r\n <foo>"),
Factory.Markup("@").Hidden(),
Factory.Markup("@"),
Factory.Markup("@").Hidden(),
Factory.Markup("@"),
new ExpressionBlock(
Factory.CodeTransition(),
Factory.Code("bar")
.AsImplicitExpression(VBCodeParser.DefaultKeywords)
.Accepts(AcceptedCharacters.NonWhiteSpace)),
Factory.Markup("</foo>\r\n")),
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()));
}
}
}