-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for basic if/elif directives (#405)
* Support for basic if/elif directives Adding some basic validation support for disabled text closes #15 * Fixing unit tests * Making some progress on edge cases * Self code review * Change format of PreprocessorSymbols * Self code review * Cleanup after rebase * Cleaning up some edge cases around new lines
- Loading branch information
Showing
20 changed files
with
790 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace CSharpier.Tests | ||
{ | ||
[TestFixture] | ||
public class DisabledTextComparerTests | ||
{ | ||
[Test] | ||
public void IsCodeBasicallyEqual_Should_Return_True_For_Basic_Case() | ||
{ | ||
var before = "public string Tester;"; | ||
|
||
var after = | ||
@"public | ||
string Tester; | ||
"; | ||
|
||
DisabledTextComparer.IsCodeBasicallyEqual(before, after).Should().BeTrue(); | ||
} | ||
|
||
[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 | ||
); | ||
"; | ||
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 | ||
); | ||
"; | ||
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); | ||
"; | ||
Squash(before).Should().Be(Squash(after)); | ||
} | ||
|
||
[Test] | ||
public void Squash_Should_Work_With_Starting_Indent() | ||
{ | ||
var before = @"array = new ulong[] { (ulong)dy.Property_ulong };"; | ||
|
||
var after = @" array = new ulong[] { (ulong)dy.Property_ulong };"; | ||
Squash(before).Should().Be(Squash(after)); | ||
} | ||
|
||
private static string Squash(string value) | ||
{ | ||
return TestableDisabledTextComparer.TestSquash(value); | ||
} | ||
|
||
private class TestableDisabledTextComparer : DisabledTextComparer | ||
{ | ||
public static string TestSquash(string value) | ||
{ | ||
return Squash(value); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Src/CSharpier.Tests/FormattingTests/TestFiles/PreprocessorSymbols.cst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
public class ClassName | ||
{ | ||
#if BASIC_IF | ||
public string ShortPropertyName; | ||
#elif BASIC_ELIF | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
|
||
#if !NOT_IF | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
|
||
#if EQUALS_TRUE == true | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
|
||
#if true == TRUE_EQUALS | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
|
||
#if NOT_EQUALS_TRUE != true | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
|
||
#if true != TRUE_NOT_EQUALS | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
|
||
#if LEFT_AND && RIGHT_AND | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
|
||
#if (LEFT_PAREN && RIGHT_PAREN) | ||
public string ShortPropertyName; | ||
#else | ||
public string ShortPropertyName; | ||
#endif | ||
} |
Oops, something went wrong.