// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Linq; using Microsoft.AspNetCore.Razor.Language.Extensions; using Xunit; namespace Microsoft.AspNetCore.Razor.Language.Legacy { public class HtmlDocumentTest : CsHtmlMarkupParserTestBase { private static readonly TestFile Nested1000 = TestFile.Create("TestFiles/nested-1000.html", typeof(HtmlDocumentTest)); [Fact] public void NestedCodeBlockWithMarkupSetsDotAsMarkup() { ParseDocumentTest("@if (true) { @if(false) {
@something.
} }"); } [Fact] public void OutputsEmptyBlockWithEmptyMarkupSpanIfContentIsEmptyString() { ParseDocumentTest(string.Empty); } [Fact] public void OutputsWhitespaceOnlyContentAsSingleWhitespaceMarkupSpan() { ParseDocumentTest(" "); } [Fact] public void AcceptsSwapTokenAtEndOfFileAndOutputsZeroLengthCodeSpan() { ParseDocumentTest("@"); } [Fact] public void CorrectlyHandlesOddlySpacedHTMLElements() { ParseDocumentTest("

Foo

"); } [Fact] public void CorrectlyHandlesSingleLineOfMarkupWithEmbeddedStatement() { ParseDocumentTest("
Foo @if(true) {} Bar
"); } [Fact] public void WithinSectionDoesNotCreateDocumentLevelSpan() { ParseDocumentTest("@section Foo {" + Environment.NewLine + " " + Environment.NewLine + "}", new[] { SectionDirective.Directive, }); } [Fact] public void ParsesWholeContentAsOneSpanIfNoSwapCharacterEncountered() { ParseDocumentTest("foo baz"); } [Fact] public void HandsParsingOverToCodeParserWhenAtSignEncounteredAndEmitsOutput() { ParseDocumentTest("foo @bar baz"); } [Fact] public void EmitsAtSignAsMarkupIfAtEndOfFile() { ParseDocumentTest("foo @"); } [Fact] public void EmitsCodeBlockIfFirstCharacterIsSwapCharacter() { ParseDocumentTest("@bar"); } [Fact] public void ParseDocumentDoesNotSwitchToCodeOnEmailAddressInText() { ParseDocumentTest("example@microsoft.com"); } [Fact] public void DoesNotSwitchToCodeOnEmailAddressInAttribute() { ParseDocumentTest("Email me"); } [Fact] public void DoesNotReturnErrorOnMismatchedTags() { ParseDocumentTest("Foo

Baz"); } [Fact] public void ReturnsOneMarkupSegmentIfNoCodeBlocksEncountered() { ParseDocumentTest("Foo BazBar