125 lines
4.8 KiB
C#
125 lines
4.8 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc.
|
|
// All Rights Reserved
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR
|
|
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
|
// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF
|
|
// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
|
|
// NON-INFRINGEMENT.
|
|
// See the Apache 2 License for the specific language governing
|
|
// permissions and limitations under the License.
|
|
|
|
using System;
|
|
using Microsoft.AspNet.Razor.Editor;
|
|
using Microsoft.AspNet.Razor.Generator;
|
|
using Microsoft.AspNet.Razor.Parser;
|
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
|
using Microsoft.AspNet.Razor.Test.Framework;
|
|
using Microsoft.TestCommon;
|
|
|
|
namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
|
{
|
|
public class CSharpLayoutDirectiveTest : CsHtmlCodeParserTestBase
|
|
{
|
|
[Theory]
|
|
[InlineData("Layout")]
|
|
[InlineData("LAYOUT")]
|
|
[InlineData("layOut")]
|
|
[InlineData("LayOut")]
|
|
private void LayoutKeywordIsCaseSensitive(string word)
|
|
{
|
|
ParseBlockTest(word,
|
|
new ExpressionBlock(
|
|
Factory.Code(word)
|
|
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
|
|
.Accepts(AcceptedCharacters.NonWhiteSpace)
|
|
));
|
|
}
|
|
|
|
[Fact]
|
|
public void LayoutDirectiveAcceptsAllTextToEndOfLine()
|
|
{
|
|
ParseBlockTest("@layout Foo Bar Baz",
|
|
new DirectiveBlock(
|
|
Factory.CodeTransition(),
|
|
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
|
Factory.MetaCode("Foo Bar Baz")
|
|
.With(new SetLayoutCodeGenerator("Foo Bar Baz"))
|
|
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
|
)
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void LayoutDirectiveAcceptsAnyIfNoWhitespaceFollowingLayoutKeyword()
|
|
{
|
|
ParseBlockTest("@layout",
|
|
new DirectiveBlock(
|
|
Factory.CodeTransition(),
|
|
Factory.MetaCode("layout")
|
|
)
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void LayoutDirectiveOutputsMarkerSpanIfAnyWhitespaceAfterLayoutKeyword()
|
|
{
|
|
ParseBlockTest("@layout ",
|
|
new DirectiveBlock(
|
|
Factory.CodeTransition(),
|
|
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
|
Factory.EmptyCSharp()
|
|
.AsMetaCode()
|
|
.With(new SetLayoutCodeGenerator(String.Empty))
|
|
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
|
)
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void LayoutDirectiveAcceptsTrailingNewlineButDoesNotIncludeItInLayoutPath()
|
|
{
|
|
ParseBlockTest("@layout Foo" + Environment.NewLine,
|
|
new DirectiveBlock(
|
|
Factory.CodeTransition(),
|
|
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
|
Factory.MetaCode("Foo\r\n")
|
|
.With(new SetLayoutCodeGenerator("Foo"))
|
|
.Accepts(AcceptedCharacters.None)
|
|
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
|
)
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public void LayoutDirectiveCorrectlyRestoresContextAfterCompleting()
|
|
{
|
|
ParseDocumentTest("@layout Foo" + Environment.NewLine
|
|
+ "@foo",
|
|
new MarkupBlock(
|
|
Factory.EmptyHtml(),
|
|
new DirectiveBlock(
|
|
Factory.CodeTransition(),
|
|
Factory.MetaCode("layout ").Accepts(AcceptedCharacters.None),
|
|
Factory.MetaCode("Foo\r\n")
|
|
.With(new SetLayoutCodeGenerator("Foo"))
|
|
.Accepts(AcceptedCharacters.None)
|
|
.WithEditorHints(EditorHints.VirtualPath | EditorHints.LayoutPage)
|
|
),
|
|
Factory.EmptyHtml(),
|
|
new ExpressionBlock(
|
|
Factory.CodeTransition(),
|
|
Factory.Code("foo")
|
|
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)
|
|
.Accepts(AcceptedCharacters.NonWhiteSpace)),
|
|
Factory.EmptyHtml()));
|
|
}
|
|
}
|
|
}
|