forked from diegofrata/Generator.Equals
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes diegofrata#60: String array + Comparer
- Loading branch information
Showing
9 changed files
with
206 additions
and
53 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Generator.Equals.DynamicGenerationTests/Issues/Issue-60-StringEquality-Enumerables.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,48 @@ | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using SourceGeneratorTestHelpers; | ||
|
||
namespace Generator.Equals.DynamicGenerationTests.Issues; | ||
|
||
public class Issue_60_StringEquality_Enumerables | ||
{ | ||
[Fact] | ||
public void Test3_Struct_UnorderedEquality() | ||
{ | ||
// StringComparer.OrdinalIgnoreCase; | ||
|
||
var input = SourceText.CSharp( | ||
""" | ||
using System; | ||
using System.Collections.Generic; | ||
using Generator.Equals; | ||
[Equatable] | ||
public partial class Resource | ||
{ | ||
[UnorderedEquality] | ||
[StringEqualityAttribute(StringComparison.OrdinalIgnoreCase)] | ||
public string[] Tags { get; set; } = Array.Empty<string>(); | ||
} | ||
""" | ||
); | ||
|
||
var result = IncrementalGenerator.Run<EqualsGenerator> | ||
( | ||
input, | ||
new CSharpParseOptions(), | ||
UnitTest1.References | ||
); | ||
|
||
var gensource = result.Results | ||
.SelectMany(x => x.GeneratedSources) | ||
.Select(x => x.SourceText) | ||
.ToList() | ||
; | ||
|
||
Assert.NotNull(gensource); | ||
|
||
Assert.Contains("new global::Generator.Equals.UnorderedEqualityComparer<string>(StringComparer.OrdinalIgnoreCase)", | ||
gensource.FirstOrDefault()?.ToString()); | ||
} | ||
} |
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,49 @@ | ||
using System; | ||
|
||
namespace Generator.Equals.Tests.Classes; | ||
|
||
public partial class StringArrayEquality | ||
{ | ||
[Equatable] | ||
public partial class Sample | ||
{ | ||
[UnorderedEquality, StringEquality(StringComparison.OrdinalIgnoreCase)] | ||
public string[] Tags { get; set; } | ||
} | ||
} | ||
|
||
public partial class StringArrayEquality | ||
{ | ||
public class EqualsTests : EqualityTestCase | ||
{ | ||
public override object Factory1() | ||
{ | ||
return new Sample | ||
{ | ||
Tags = new[] { "a", "b", "c" } | ||
}; | ||
} | ||
|
||
public override bool EqualsOperator(object value1, object value2) => (Sample)value1 == (Sample)value2; | ||
public override bool NotEqualsOperator(object value1, object value2) => (Sample)value1 != (Sample)value2; | ||
} | ||
|
||
// Order doesnt matter | ||
public class OrderDoesntMatterEqualsTest : EqualityTestCase | ||
{ | ||
public override bool Expected => true; | ||
|
||
public override object Factory1() => new Sample | ||
{ | ||
Tags = new[] { "a", "b", "c" } | ||
}; | ||
|
||
public override object Factory2() => new Sample | ||
{ | ||
Tags = new[] { "c", "b", "a" } | ||
}; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => (Sample)value1 == (Sample)value2; | ||
public override bool NotEqualsOperator(object value1, object value2) => (Sample)value1 != (Sample)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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Equals.Tests.Classes | ||
|
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
Oops, something went wrong.