-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIfTests.cs
87 lines (80 loc) · 2.47 KB
/
IfTests.cs
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
using CsmlTests.Helpers;
namespace CsmlTests.Statements;
public class IfTests
{
[Fact]
public void IfTest()
{
// Arrange
string csml = """
<Call Target="System.Console" Method="WriteLine" />
<If>
<Expression>
<Equals>
<Left>
<Value Value="true" />
</Left>
<Right>
<Value Value="false" />
</Right>
</Equals>
</Expression>
<Statements>
<Variable Type="int" Name="valA">
<Expression>
<Value Value="1" />
</Expression>
</Variable>
</Statements>
</If>
<ElseIf>
<Expression>
<Equals>
<Left>
<Value Value="false" />
</Left>
<Right>
<Value Value="true" />
</Right>
</Equals>
</Expression>
<Statements>
<Variable Type="int" Name="valA">
<Expression>
<Value Value="1" />
</Expression>
</Variable>
</Statements>
</ElseIf>
<Else>
<Variable Type="int" Name="valA">
<Expression>
<Value Value="3" />
</Expression>
</Variable>
</Else>
<Call Target="System.Console" Method="WriteLine" />
""";
// Act
SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
// Assert
if (!output.FirstDescendant(out MethodDeclarationSyntax? methodDeclaration))
{
Assert.Fail();
return;
}
if (methodDeclaration.GetChildNodes() is not [.., BlockSyntax blockSyntax])
{
Assert.Fail();
return;
}
if (blockSyntax.GetChildNodes() is not [
ExpressionStatementSyntax,
IfStatementSyntax,
ExpressionStatementSyntax])
{
Assert.Fail();
return;
}
}
}