@@ -17,10 +17,7 @@ public static class AssertionExtensions
17
17
/// </summary>
18
18
/// <param name="actual">Resulted code</param>
19
19
/// <param name="expected">Expected code</param>
20
- public static void ShouldBeSemantically ( this string actual , string expected )
21
- {
22
- ShouldBeSemantically ( CSharpSyntaxTree . ParseText ( actual ) . GetRoot ( ) , CSharpSyntaxTree . ParseText ( expected ) . GetRoot ( ) ) ;
23
- }
20
+ public static void ShouldBeSemantically ( this string actual , string expected ) => ShouldBeSemantically ( CSharpSyntaxTree . ParseText ( actual ) , CSharpSyntaxTree . ParseText ( expected ) ) ;
24
21
25
22
/// <summary>
26
23
/// Compares two syntax trees and asserts equality
@@ -29,14 +26,9 @@ public static void ShouldBeSemantically(this string actual, string expected)
29
26
/// <param name="expected">Expected code</param>
30
27
/// <remarks>Warning: this code tries to pinpoint the first different lines, but it will work on string comparison, so it may pinpoint spaces
31
28
/// or new line variations, hiding the real differences.</remarks>
32
- public static void ShouldBeSemantically ( this SyntaxNode actual , SyntaxNode expected )
29
+ public static void ShouldBeSemantically ( this SyntaxTree actual , SyntaxTree expected )
33
30
{
34
- // for some reason, nodes can be different while being textually the same
35
- if ( actual . ToFullString ( ) == expected . ToFullString ( ) )
36
- {
37
- return ;
38
- }
39
- var isSame = SyntaxFactory . AreEquivalent ( actual , expected ) ;
31
+ var isSame = actual . IsEquivalentTo ( expected ) ;
40
32
41
33
if ( ! isSame )
42
34
{
@@ -63,12 +55,12 @@ public static void ShouldBeWithNewlineReplace(this string actual, string expecte
63
55
actual . ShouldBe ( replaced ) ;
64
56
}
65
57
66
- public static void ShouldNotContainErrors ( this SyntaxNode actual )
58
+ public static void ShouldNotContainErrors ( this SyntaxTree actual )
67
59
{
68
- var errors = actual . SyntaxTree . GetDiagnostics ( ) . Count ( x => x . Severity == DiagnosticSeverity . Error ) ;
60
+ var errors = actual . GetDiagnostics ( ) . Count ( x => x . Severity == DiagnosticSeverity . Error ) ;
69
61
if ( errors > 0 )
70
62
{
71
- errors . ShouldBe ( 0 , $ "Actual code has build errors!\n { actual . ToFullString ( ) } \n errors: { string . Join ( Environment . NewLine , actual . SyntaxTree . GetDiagnostics ( ) ) } ") ;
63
+ errors . ShouldBe ( 0 , $ "Actual code has build errors!\n { actual . GetText ( ) } \n errors: { string . Join ( Environment . NewLine , actual . GetDiagnostics ( ) ) } ") ;
72
64
}
73
65
}
74
66
0 commit comments