Skip to content

Commit

Permalink
When an #if directive has a comma added with it, then the syntax node… (
Browse files Browse the repository at this point in the history
#1317)

… validation fails because it is not comparing the syntax nodes.

closes #1312
  • Loading branch information
belav authored Aug 16, 2024
1 parent 28c9bc4 commit cb64721
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 115 deletions.
136 changes: 79 additions & 57 deletions Src/CSharpier.Tests/DisabledTextComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public void IsCodeBasicallyEqual_Should_Return_True_For_Basic_Case()
{
var before = "public string Tester;";

var after =
@"public
string Tester;
";
var after = """
public
string Tester;
""";

DisabledTextComparer.IsCodeBasicallyEqual(before, after).Should().BeTrue();
}
Expand All @@ -30,74 +31,95 @@ public void Squash_Should_Work_For_Trailing_Space_And_New_Line()
Squash(before).Should().Be(Squash(after));
}

[Test]
public void Squash_Should_Work_For_Trailing_Comma()
{
var before = """
public enum Enum
{
Foo = 1,
}
""";

var after = "public enum Enum {Foo=1}\n";

Squash(before).Should().Be(Squash(after));
}

[Test]
public void Squash_Should_Work_With_Pointer_Stuff()
{
var before =
@" [MethodImpl (MethodImplOptions.InternalCall)]
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);";

var after =
@"[MethodImpl(MethodImplOptions.InternalCall)]
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
);
";
var before = """
[MethodImpl (MethodImplOptions.InternalCall)]
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);
""";

var after = """
[MethodImpl(MethodImplOptions.InternalCall)]
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
);
""";
Squash(before).Should().Be(Squash(after));
}

[Test]
public void Squash_Should_Work_With_Commas()
{
var before =
@"
TypeBuilder typeBuilder = moduleBuilder.DefineType(assemblyName.FullName
, TypeAttributes.Public |
TypeAttributes.Class |
TypeAttributes.AutoClass |
TypeAttributes.AnsiClass |
TypeAttributes.BeforeFieldInit |
TypeAttributes.AutoLayout
, null);
";

var after =
@"
TypeBuilder typeBuilder = moduleBuilder.DefineType(
assemblyName.FullName,
TypeAttributes.Public
| TypeAttributes.Class
| TypeAttributes.AutoClass
| TypeAttributes.AnsiClass
| TypeAttributes.BeforeFieldInit
| TypeAttributes.AutoLayout,
null
);
";
var before = """
TypeBuilder typeBuilder = moduleBuilder.DefineType(assemblyName.FullName
, TypeAttributes.Public |
TypeAttributes.Class |
TypeAttributes.AutoClass |
TypeAttributes.AnsiClass |
TypeAttributes.BeforeFieldInit |
TypeAttributes.AutoLayout
, null);
""";

var after = """
TypeBuilder typeBuilder = moduleBuilder.DefineType(
assemblyName.FullName,
TypeAttributes.Public
| TypeAttributes.Class
| TypeAttributes.AutoClass
| TypeAttributes.AnsiClass
| TypeAttributes.BeforeFieldInit
| TypeAttributes.AutoLayout,
null
);
""";
Squash(before).Should().Be(Squash(after));
}

[Test]
public void Squash_Should_Work_With_Period()
{
var before =
@"
var options2 = (ProxyGenerationOptions)proxy.GetType().
GetField(""proxyGenerationOptions"", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
";

var after =
@"
var options2 = (ProxyGenerationOptions)proxy.GetType()
.GetField(""proxyGenerationOptions"", BindingFlags.Static | BindingFlags.NonPublic)
.GetValue(null);
";
var before = """
var options2 = (ProxyGenerationOptions)proxy.GetType().
GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
""";

var after = """
var options2 = (ProxyGenerationOptions)proxy.GetType()
.GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic)
.GetValue(null);
""";
Squash(before).Should().Be(Squash(after));
}

Expand Down
Loading

0 comments on commit cb64721

Please sign in to comment.