Skip to content

Commit cb64721

Browse files
authored
When an #if directive has a comma added with it, then the syntax node… (#1317)
… validation fails because it is not comparing the syntax nodes. closes #1312
1 parent 28c9bc4 commit cb64721

File tree

3 files changed

+157
-115
lines changed

3 files changed

+157
-115
lines changed

Src/CSharpier.Tests/DisabledTextComparerTests.cs

Lines changed: 79 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ public void IsCodeBasicallyEqual_Should_Return_True_For_Basic_Case()
1212
{
1313
var before = "public string Tester;";
1414

15-
var after =
16-
@"public
17-
string Tester;
18-
";
15+
var after = """
16+
public
17+
string Tester;
18+
19+
""";
1920

2021
DisabledTextComparer.IsCodeBasicallyEqual(before, after).Should().BeTrue();
2122
}
@@ -30,74 +31,95 @@ public void Squash_Should_Work_For_Trailing_Space_And_New_Line()
3031
Squash(before).Should().Be(Squash(after));
3132
}
3233

34+
[Test]
35+
public void Squash_Should_Work_For_Trailing_Comma()
36+
{
37+
var before = """
38+
public enum Enum
39+
{
40+
Foo = 1,
41+
}
42+
""";
43+
44+
var after = "public enum Enum {Foo=1}\n";
45+
46+
Squash(before).Should().Be(Squash(after));
47+
}
48+
3349
[Test]
3450
public void Squash_Should_Work_With_Pointer_Stuff()
3551
{
36-
var before =
37-
@" [MethodImpl (MethodImplOptions.InternalCall)]
38-
private static unsafe extern void ApplyUpdate_internal (IntPtr base_assm, byte* dmeta_bytes, int dmeta_length, byte *dil_bytes, int dil_length, byte *dpdb_bytes, int dpdb_length);";
39-
40-
var after =
41-
@"[MethodImpl(MethodImplOptions.InternalCall)]
42-
private static unsafe extern void ApplyUpdate_internal(
43-
IntPtr base_assm,
44-
byte* dmeta_bytes,
45-
int dmeta_length,
46-
byte* dil_bytes,
47-
int dil_length,
48-
byte* dpdb_bytes,
49-
int dpdb_length
50-
);
51-
";
52+
var before = """
53+
[MethodImpl (MethodImplOptions.InternalCall)]
54+
private static unsafe extern void ApplyUpdate_internal (IntPtr base_assm, byte* dmeta_bytes, int dmeta_length, byte *dil_bytes, int dil_length, byte *dpdb_bytes, int dpdb_length);
55+
""";
56+
57+
var after = """
58+
[MethodImpl(MethodImplOptions.InternalCall)]
59+
private static unsafe extern void ApplyUpdate_internal(
60+
IntPtr base_assm,
61+
byte* dmeta_bytes,
62+
int dmeta_length,
63+
byte* dil_bytes,
64+
int dil_length,
65+
byte* dpdb_bytes,
66+
int dpdb_length
67+
);
68+
69+
""";
5270
Squash(before).Should().Be(Squash(after));
5371
}
5472

5573
[Test]
5674
public void Squash_Should_Work_With_Commas()
5775
{
58-
var before =
59-
@"
60-
TypeBuilder typeBuilder = moduleBuilder.DefineType(assemblyName.FullName
61-
, TypeAttributes.Public |
62-
TypeAttributes.Class |
63-
TypeAttributes.AutoClass |
64-
TypeAttributes.AnsiClass |
65-
TypeAttributes.BeforeFieldInit |
66-
TypeAttributes.AutoLayout
67-
, null);
68-
";
69-
70-
var after =
71-
@"
72-
TypeBuilder typeBuilder = moduleBuilder.DefineType(
73-
assemblyName.FullName,
74-
TypeAttributes.Public
75-
| TypeAttributes.Class
76-
| TypeAttributes.AutoClass
77-
| TypeAttributes.AnsiClass
78-
| TypeAttributes.BeforeFieldInit
79-
| TypeAttributes.AutoLayout,
80-
null
81-
);
82-
";
76+
var before = """
77+
78+
TypeBuilder typeBuilder = moduleBuilder.DefineType(assemblyName.FullName
79+
, TypeAttributes.Public |
80+
TypeAttributes.Class |
81+
TypeAttributes.AutoClass |
82+
TypeAttributes.AnsiClass |
83+
TypeAttributes.BeforeFieldInit |
84+
TypeAttributes.AutoLayout
85+
, null);
86+
87+
""";
88+
89+
var after = """
90+
91+
TypeBuilder typeBuilder = moduleBuilder.DefineType(
92+
assemblyName.FullName,
93+
TypeAttributes.Public
94+
| TypeAttributes.Class
95+
| TypeAttributes.AutoClass
96+
| TypeAttributes.AnsiClass
97+
| TypeAttributes.BeforeFieldInit
98+
| TypeAttributes.AutoLayout,
99+
null
100+
);
101+
102+
""";
83103
Squash(before).Should().Be(Squash(after));
84104
}
85105

86106
[Test]
87107
public void Squash_Should_Work_With_Period()
88108
{
89-
var before =
90-
@"
91-
var options2 = (ProxyGenerationOptions)proxy.GetType().
92-
GetField(""proxyGenerationOptions"", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
93-
";
94-
95-
var after =
96-
@"
97-
var options2 = (ProxyGenerationOptions)proxy.GetType()
98-
.GetField(""proxyGenerationOptions"", BindingFlags.Static | BindingFlags.NonPublic)
99-
.GetValue(null);
100-
";
109+
var before = """
110+
111+
var options2 = (ProxyGenerationOptions)proxy.GetType().
112+
GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
113+
114+
""";
115+
116+
var after = """
117+
118+
var options2 = (ProxyGenerationOptions)proxy.GetType()
119+
.GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic)
120+
.GetValue(null);
121+
122+
""";
101123
Squash(before).Should().Be(Squash(after));
102124
}
103125

0 commit comments

Comments
 (0)