-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathThrowTests.cs
55 lines (47 loc) · 1.35 KB
/
ThrowTests.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
namespace CsmlTests.Statements;
public class ThrowTests
{
[Fact]
public void Throw_NewException()
{
// Arrange
string csml = """
<Throw>
<New Type="MyException" />
</Throw>
""";
// Act
SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
// Assert
if (!output.FirstDescendant(out ThrowStatementSyntax? throwStatement))
{
Assert.Fail();
return;
}
Assert.True(throwStatement.Expression is ObjectCreationExpressionSyntax);
}
[Fact]
public void Throw_ExceptionVariable()
{
// Arrange
string csml = """
<Variable Type="MyException" Name="exception">
<Expression>
<New Type="MyException" />
</Expression>
</Variable>
<Throw>
<Value Value="exception" />
</Throw>
""";
// Act
SyntaxNode[] output = AssertCompileNoDiagnostics(CsmlSyntaxWrapper.WrapInMethod(csml));
// Assert
if (!output.FirstDescendant(out ThrowStatementSyntax? throwStatement))
{
Assert.Fail();
return;
}
Assert.True(throwStatement.Expression is IdentifierNameSyntax);
}
}