-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create comparer for strings (#55)
* Add string equality comparer * Separate analyzer and compilation unit definitions for enum * Updated README * Added more tests * Separate analyzer and compilation unit definitions for enum for hashcodes as well * More correct way to check enum value
- Loading branch information
Showing
21 changed files
with
366 additions
and
6 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
1 change: 1 addition & 0 deletions
1
Generator.Equals.SnapshotTests/Classes/StringEquality.Net60.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
...rator.Equals.SnapshotTests/Classes/StringEquality.NetFramework48.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
Generator.Equals.SnapshotTests/RecordStructs/StringEquality.Net60.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
...Equals.SnapshotTests/RecordStructs/StringEquality.NetFramework48.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
Generator.Equals.SnapshotTests/Records/StringEquality.Net60.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
...rator.Equals.SnapshotTests/Records/StringEquality.NetFramework48.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
Generator.Equals.SnapshotTests/Structs/StringEquality.Net60.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
...rator.Equals.SnapshotTests/Structs/StringEquality.NetFramework48.Diagnostics.verified.txt
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 @@ | ||
[] |
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,31 @@ | ||
using System; | ||
|
||
namespace Generator.Equals.Tests.Classes | ||
{ | ||
public partial class StringEquality | ||
{ | ||
[Equatable] | ||
public partial class SampleCaseInsensitive | ||
{ | ||
public SampleCaseInsensitive(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
[StringEquality(StringComparison.CurrentCultureIgnoreCase)] | ||
public string Name { get; } | ||
} | ||
|
||
[Equatable] | ||
public partial class SampleCaseSensitive | ||
{ | ||
public SampleCaseSensitive(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
[StringEquality(StringComparison.CurrentCulture)] | ||
public string Name { get; } | ||
} | ||
} | ||
} |
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,55 @@ | ||
namespace Generator.Equals.Tests.Classes | ||
{ | ||
public partial class StringEquality | ||
{ | ||
public class EqualsTestsNotCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive("BAR"); | ||
public override object Factory2() => new SampleCaseInsensitive("bar"); | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
|
||
public class NotEqualsTestsNotCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive("BAR"); | ||
public override object Factory2() => new SampleCaseInsensitive("foo"); | ||
public override bool Expected => false; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
|
||
public class EqualsTestsCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseSensitive("Foo"); | ||
public override object Factory2() => new SampleCaseSensitive("Foo"); | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 == (SampleCaseSensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 != (SampleCaseSensitive)value2; | ||
} | ||
|
||
public class NotEqualsTestsCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseSensitive("Foo"); | ||
public override object Factory2() => new SampleCaseSensitive("foo"); | ||
public override bool Expected => false; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 == (SampleCaseSensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 != (SampleCaseSensitive)value2; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Generator.Equals.Tests/RecordStructs/StringEquality.Sample.cs
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,17 @@ | ||
using System; | ||
|
||
namespace Generator.Equals.Tests.RecordStructs | ||
{ | ||
public partial class StringEquality | ||
{ | ||
[Equatable] | ||
public partial record struct SampleCaseInsensitive( | ||
[property: StringEquality(StringComparison.CurrentCultureIgnoreCase)] | ||
string Name); | ||
|
||
[Equatable] | ||
public partial record struct SampleCaseSensitive( | ||
[property: StringEquality(StringComparison.CurrentCulture)] | ||
string Name); | ||
} | ||
} |
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,30 @@ | ||
namespace Generator.Equals.Tests.RecordStructs | ||
{ | ||
public partial class StringEquality | ||
{ | ||
public class EqualsTests : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive { Name = "BAR" }; | ||
public override object Factory2() => new SampleCaseInsensitive { Name = "bar" }; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
|
||
public class NotEqualsTest : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive { Name = "BAR" }; | ||
public override object Factory2() => new SampleCaseInsensitive { Name = "foo" }; | ||
public override bool Expected => false; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
|
||
namespace Generator.Equals.Tests.Records | ||
{ | ||
public partial class StringEquality | ||
{ | ||
[Equatable] | ||
public partial record SampleCaseInsensitive | ||
{ | ||
[StringEquality(StringComparison.CurrentCultureIgnoreCase)] | ||
public string Name { get; init; } = ""; | ||
} | ||
|
||
[Equatable] | ||
public partial record SampleCaseSensitive | ||
{ | ||
[StringEquality(StringComparison.CurrentCulture)] | ||
public string Name { get; init; } = ""; | ||
} | ||
} | ||
} |
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,55 @@ | ||
namespace Generator.Equals.Tests.Records | ||
{ | ||
public partial class StringEquality | ||
{ | ||
public class EqualsTestsNotCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive { Name = "BAR" }; | ||
public override object Factory2() => new SampleCaseInsensitive { Name = "bar" }; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
|
||
public class NotEqualsTestsNotCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive { Name = "BAR" }; | ||
public override object Factory2() => new SampleCaseInsensitive { Name = "foo" }; | ||
public override bool Expected => false; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
|
||
public class EqualsTestsCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseSensitive { Name = "Foo" }; | ||
public override object Factory2() => new SampleCaseSensitive { Name = "Foo" }; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 == (SampleCaseSensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 != (SampleCaseSensitive)value2; | ||
} | ||
|
||
public class NotEqualsTestsCaseSensitive : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseSensitive { Name = "Foo" }; | ||
public override object Factory2() => new SampleCaseSensitive { Name = "foo" }; | ||
public override bool Expected => false; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 == (SampleCaseSensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseSensitive)value1 != (SampleCaseSensitive)value2; | ||
} | ||
} | ||
} |
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,31 @@ | ||
using System; | ||
|
||
namespace Generator.Equals.Tests.Structs | ||
{ | ||
public partial class StringEquality | ||
{ | ||
[Equatable] | ||
public partial struct SampleCaseInsensitive | ||
{ | ||
public SampleCaseInsensitive(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
[StringEquality(StringComparison.CurrentCultureIgnoreCase)] | ||
public string Name { get; init; } = ""; | ||
} | ||
|
||
[Equatable] | ||
public partial struct SampleCaseSensitive | ||
{ | ||
public SampleCaseSensitive(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
[StringEquality(StringComparison.CurrentCulture)] | ||
public string Name { get; init; } = ""; | ||
} | ||
} | ||
} |
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,30 @@ | ||
namespace Generator.Equals.Tests.Structs | ||
{ | ||
public partial class StringEquality | ||
{ | ||
public class EqualsTests : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive { Name = "BAR" }; | ||
public override object Factory2() => new SampleCaseInsensitive { Name = "bar" }; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
|
||
public class NotEqualsTest : EqualityTestCase | ||
{ | ||
public override object Factory1() => new SampleCaseInsensitive { Name = "BAR" }; | ||
public override object Factory2() => new SampleCaseInsensitive { Name = "foo" }; | ||
public override bool Expected => false; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 == (SampleCaseInsensitive)value2; | ||
|
||
public override bool NotEqualsOperator(object value1, object value2) => | ||
(SampleCaseInsensitive)value1 != (SampleCaseInsensitive)value2; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.