forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpNestedStatementsTest.cs
More file actions
103 lines (96 loc) · 3.93 KB
/
Copy pathCSharpNestedStatementsTest.cs
File metadata and controls
103 lines (96 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// 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.Web.Razor.Generator;
using System.Web.Razor.Parser;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Test.Framework;
using Microsoft.TestCommon;
namespace System.Web.Razor.Test.Parser.CSharp
{
public class CSharpNestedStatementsTest : CsHtmlCodeParserTestBase
{
[Fact]
public void NestedSimpleStatement()
{
ParseBlockTest("@while(true) { foo(); }",
new StatementBlock(
Factory.CodeTransition(),
Factory.Code("while(true) { foo(); }")
.AsStatement()
.Accepts(AcceptedCharacters.None)));
}
[Fact]
public void NestedKeywordStatement()
{
ParseBlockTest("@while(true) { for(int i = 0; i < 10; i++) { foo(); } }",
new StatementBlock(
Factory.CodeTransition(),
Factory.Code("while(true) { for(int i = 0; i < 10; i++) { foo(); } }")
.AsStatement()
.Accepts(AcceptedCharacters.None)));
}
[Fact]
public void NestedCodeBlock()
{
ParseBlockTest("@while(true) { { { { foo(); } } } }",
new StatementBlock(
Factory.CodeTransition(),
Factory.Code("while(true) { { { { foo(); } } } }")
.AsStatement()
.Accepts(AcceptedCharacters.None)));
}
[Fact]
public void NestedImplicitExpression()
{
ParseBlockTest("@while(true) { @foo }",
new StatementBlock(
Factory.CodeTransition(),
Factory.Code("while(true) { ")
.AsStatement(),
new ExpressionBlock(
Factory.CodeTransition(),
Factory.Code("foo")
.AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: true)
.Accepts(AcceptedCharacters.NonWhiteSpace)),
Factory.Code(" }")
.AsStatement()
.Accepts(AcceptedCharacters.None)));
}
[Fact]
public void NestedExplicitExpression()
{
ParseBlockTest("@while(true) { @(foo) }",
new StatementBlock(
Factory.CodeTransition(),
Factory.Code("while(true) { ")
.AsStatement(),
new ExpressionBlock(
Factory.CodeTransition(),
Factory.MetaCode("(")
.Accepts(AcceptedCharacters.None),
Factory.Code("foo")
.AsExpression(),
Factory.MetaCode(")")
.Accepts(AcceptedCharacters.None)),
Factory.Code(" }")
.AsStatement()
.Accepts(AcceptedCharacters.None)));
}
[Fact]
public void NestedMarkupBlock()
{
ParseBlockTest("@while(true) { <p>Hello</p> }",
new StatementBlock(
Factory.CodeTransition(),
Factory.Code("while(true) {")
.AsStatement(),
new MarkupBlock(
Factory.Markup(" <p>Hello</p> ")
.With(new MarkupCodeGenerator())
.Accepts(AcceptedCharacters.None)),
Factory.Code("}")
.AsStatement()
.Accepts(AcceptedCharacters.None)));
}
}
}