Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[net8] Use new collection initializers #521

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ dotnet_analyzer_diagnostic.category-Style.severity = warning

dotnet_diagnostic.IDE0011.severity = silent # IDE0011: Add braces
dotnet_diagnostic.IDE0046.severity = silent # IDE0046: Convert to conditional expression
dotnet_diagnostic.IDE0290.severity = none # IDE0290: Use primary constructor
dotnet_diagnostic.IDE0028.severity = none # IDE0028: Simplify collection initialization
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Simplify collection initialization

# For ScanEx()
dotnet_code_quality.ca1711.allowed_suffixes = Ex
Expand Down
62 changes: 31 additions & 31 deletions Generators/SuperLinq.Generator/ArgumentNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@ public record ArgumentNames(string[] Arity, string[] Ordinals, string[] Cardinal
/// int->string translations of different types.
/// </summary>
public static ArgumentNames Instance { get; } = new(
Arity: new[]
{
"zero" ,
"one" ,
"two" ,
Arity:
[
"zero",
"one",
"two",
"three",
"four" ,
"five" ,
"six" ,
"four",
"five",
"six",
"seven",
"eight",
},
Ordinals: new[]
{
"zeroth" ,
"first" ,
"second" ,
"third" ,
"fourth" ,
"fifth" ,
"sixth" ,
],
Ordinals:
[
"zeroth",
"first",
"second",
"third",
"fourth",
"fifth",
"sixth",
"seventh",
"eighth" ,
},
Cardinals: new[]
{
"Zeroth" ,
"First" ,
"Second" ,
"Third" ,
"Fourth" ,
"Fifth" ,
"Sixth" ,
"eighth",
],
Cardinals:
[
"Zeroth",
"First",
"Second",
"Third",
"Fourth",
"Fifth",
"Sixth",
"Seventh",
"Eighth" ,
});
"Eighth",
]);
}

2 changes: 1 addition & 1 deletion Source/SuperLinq/ToArrayByIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static partial class SuperEnumerable
}

if (lastIndex == -1)
return Array.Empty<TResult>();
return [];

var length = lastIndex + 1;
var array = new TResult?[length];
Expand Down
4 changes: 2 additions & 2 deletions Source/SuperLinq/ToDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static partial class SuperEnumerable
public static TTable ToDataTable<T, TTable>(this IEnumerable<T> source, TTable table)
where TTable : DataTable
{
return ToDataTable(source, table, Array.Empty<Expression<Func<T, object>>>());
return ToDataTable(source, table, []);
}

/// <summary>
Expand Down Expand Up @@ -54,7 +54,7 @@ public static DataTable ToDataTable<T>(this IEnumerable<T> source, params Expres

public static DataTable ToDataTable<T>(this IEnumerable<T> source)
{
return ToDataTable(source, new DataTable(), Array.Empty<Expression<Func<T, object>>>());
return ToDataTable(source, new DataTable(), []);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions Tests/SuperLinq.Async.Test/CountDownTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public void ExceptionOnNegativeCount(int param)
private static IEnumerable<T> GetData<T>(Func<int[], int, int?[], T> selector)
{
var xs = Enumerable.Range(0, 5).ToArray();
yield return selector(xs, 1, new int?[] { null, null, null, null, 0 });
yield return selector(xs, 2, new int?[] { null, null, null, 1, 0 });
yield return selector(xs, 3, new int?[] { null, null, 2, 1, 0 });
yield return selector(xs, 4, new int?[] { null, 3, 2, 1, 0 });
yield return selector(xs, 5, new int?[] { 4, 3, 2, 1, 0 });
yield return selector(xs, 6, new int?[] { 4, 3, 2, 1, 0 });
yield return selector(xs, 7, new int?[] { 4, 3, 2, 1, 0 });
yield return selector(xs, 1, [null, null, null, null, 0]);
yield return selector(xs, 2, [null, null, null, 1, 0]);
yield return selector(xs, 3, [null, null, 2, 1, 0]);
yield return selector(xs, 4, [null, 3, 2, 1, 0]);
yield return selector(xs, 5, [4, 3, 2, 1, 0]);
yield return selector(xs, 6, [4, 3, 2, 1, 0]);
yield return selector(xs, 7, [4, 3, 2, 1, 0]);
}

public static IEnumerable<object[]> SequenceData { get; } =
Expand Down
9 changes: 4 additions & 5 deletions Tests/SuperLinq.Async.Test/FullOuterJoinTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ public class FullOuterJoinTest
public enum Side { Left, Right, Both }

public static IEnumerable<object[]> GetJoinTypes() =>
new[]
{
new object[] { JoinType.Hash, },
new object[] { JoinType.Merge, },
};
[
[JoinType.Hash,],
[JoinType.Merge,],
];

[Theory, MemberData(nameof(GetJoinTypes))]
public void FullOuterJoinIsLazy(JoinType joinType)
Expand Down
153 changes: 80 additions & 73 deletions Tests/SuperLinq.Async.Test/GetShortestPathTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ private static void VerifySequences<T>(this List<TestingSequence<T>> list)
public class Dijkstra
{
public static IEnumerable<object?[]> GetStringIntCostData { get; } =
new[]
{
new object?[] { null, null, 15, 7, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, null, 10, 4, },
new object?[] { null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 150, 6, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 1000, 1, },
};
[
[null, null, 15, 7,],
[StringComparer.InvariantCultureIgnoreCase, null, 10, 4,],
[null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 150, 6,],
[StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 1000, 1,],
];

[Theory]
[MemberData(nameof(GetStringIntCostData))]
Expand Down Expand Up @@ -116,13 +115,12 @@ public async Task GetStringIntCostByFunction(
}

public static IEnumerable<object?[]> GetStringIntPathData { get; } =
new[]
{
new object?[] { null, null, Seq(("start", 0), ("a", 1), ("b", 3), ("c", 6), ("d", 10), ("end", 15)), 7, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, null, Seq(("start", 0), ("END", 10)), 4, },
new object?[] { null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("A", 10), ("B", 30), ("C", 60), ("D", 100), ("end", 150)), 6, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("END", 1000)), 1, },
};
[
[null, null, Seq(("start", 0), ("a", 1), ("b", 3), ("c", 6), ("d", 10), ("end", 15)), 7,],
[StringComparer.InvariantCultureIgnoreCase, null, Seq(("start", 0), ("END", 10)), 4,],
[null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("A", 10), ("B", 30), ("C", 60), ("D", 100), ("end", 150)), 6,],
[StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("END", 1000)), 1,],
];

[Theory]
[MemberData(nameof(GetStringIntPathData))]
Expand Down Expand Up @@ -187,51 +185,62 @@ public async Task GetStringIntPathByFunction(
}

public static IEnumerable<object?[]> GetStringIntPathsData { get; } =
new[]
{
new object?[] { null, null, Seq(
("start", (null, 0)),
("a", ("start", 1)),
("b", ("a", 3)),
("c", ("b", 6)),
("d", ("c", 10)),
("end", ("d", 15)),
("A", ("start", 10)),
("B", ("A", 30)),
("C", ("B", 60)),
("D", ("C", 100)),
("END", ("start", 10))),
},
new object?[] { StringComparer.InvariantCultureIgnoreCase, null, Seq(
("start", (null, 0)),
("a", ("start", 1)),
("b", ("a", 3)),
("c", ("b", 6)),
("d", ("c", 10)),
("end", ("start", 10))),
},
new object?[] { null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(
("start", (null, 0)),
("a", ("start", 1)),
("b", ("a", 3)),
("c", ("b", 6)),
("d", ("c", 10)),
("A", ("start", 10)),
("B", ("A", 30)),
("C", ("B", 60)),
("D", ("C", 100)),
("end", ("D", 150)),
("END", ("start", 1000))),
},
new object?[] { StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(
("start", (null, 0)),
("a", ("start", 10)),
("b", ("a", 30)),
("c", ("b", 60)),
("d", ("c", 100)),
("end", ("start", 1000))),
},
};
[
[
null,
null,
Seq(
("start", (null, 0)),
("a", ("start", 1)),
("b", ("a", 3)),
("c", ("b", 6)),
("d", ("c", 10)),
("end", ("d", 15)),
("A", ("start", 10)),
("B", ("A", 30)),
("C", ("B", 60)),
("D", ("C", 100)),
("END", ("start", 10))),
],
[
StringComparer.InvariantCultureIgnoreCase,
null,
Seq(
("start", (null, 0)),
("a", ("start", 1)),
("b", ("a", 3)),
("c", ("b", 6)),
("d", ("c", 10)),
("end", ("start", 10))),
],
[
null,
Comparer<int>.Create((x, y) => -x.CompareTo(y)),
Seq(
("start", (null, 0)),
("a", ("start", 1)),
("b", ("a", 3)),
("c", ("b", 6)),
("d", ("c", 10)),
("A", ("start", 10)),
("B", ("A", 30)),
("C", ("B", 60)),
("D", ("C", 100)),
("end", ("D", 150)),
("END", ("start", 1000))),
],
[
StringComparer.InvariantCultureIgnoreCase,
Comparer<int>.Create((x, y) => -x.CompareTo(y)),
Seq(
("start", (null, 0)),
("a", ("start", 10)),
("b", ("a", 30)),
("c", ("b", 60)),
("d", ("c", 100)),
("end", ("start", 1000))),
],
];

[Theory]
[MemberData(nameof(GetStringIntPathsData))]
Expand Down Expand Up @@ -341,13 +350,12 @@ public async Task InvalidMapThrowsException()
public class AStar
{
public static IEnumerable<object?[]> GetStringIntCostData { get; } =
new[]
{
new object?[] { null, null, 15, 7, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, null, 10, 4, },
new object?[] { null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 150, 6, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 1000, 1, },
};
[
[null, null, 15, 7,],
[StringComparer.InvariantCultureIgnoreCase, null, 10, 4,],
[null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 150, 6,],
[StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), 1000, 1,],
];

// No heuristic means this operates the same as Dijkstra; this is
// to prove the base algorithm still works.
Expand Down Expand Up @@ -415,13 +423,12 @@ public async Task GetStringIntCostByFunction(
}

public static IEnumerable<object?[]> GetStringIntPathData { get; } =
new[]
{
new object?[] { null, null, Seq(("start", 0), ("a", 1), ("b", 3), ("c", 6), ("d", 10), ("end", 15)), 7, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, null, Seq(("start", 0), ("END", 10)), 4, },
new object?[] { null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("A", 10), ("B", 30), ("C", 60), ("D", 100), ("end", 150)), 6, },
new object?[] { StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("END", 1000)), 1, },
};
[
[null, null, Seq(("start", 0), ("a", 1), ("b", 3), ("c", 6), ("d", 10), ("end", 15)), 7,],
[StringComparer.InvariantCultureIgnoreCase, null, Seq(("start", 0), ("END", 10)), 4,],
[null, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("A", 10), ("B", 30), ("C", 60), ("D", 100), ("end", 150)), 6,],
[StringComparer.InvariantCultureIgnoreCase, Comparer<int>.Create((x, y) => -x.CompareTo(y)), Seq(("start", 0), ("END", 1000)), 1,],
];

// No heuristic means this operates the same as Dijkstra; this is
// to prove the base algorithm still works.
Expand Down
2 changes: 1 addition & 1 deletion Tests/SuperLinq.Async.Test/GroupAdjacentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public async Task GroupAdjacentSourceSequenceWithSomeNullKeys()

var groupings = source.GroupAdjacent(SuperEnumerable.Identity);

int?[] aNull = { null };
var aNull = new int?[] { null };

await using var reader = groupings.Read();
await AssertGrouping(reader, 1, 1);
Expand Down
11 changes: 5 additions & 6 deletions Tests/SuperLinq.Async.Test/InnerJoinTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace Test.Async;
public class InnerJoinTest
{
public static IEnumerable<object[]> GetJoinTypes() =>
new[]
{
new object[] { JoinType.Loop, },
new object[] { JoinType.Hash, },
new object[] { JoinType.Merge, },
};
[
[JoinType.Loop,],
[JoinType.Hash,],
[JoinType.Merge,],
];

[Theory, MemberData(nameof(GetJoinTypes))]
public void InnerJoinIsLazy(JoinType joinType)
Expand Down
11 changes: 5 additions & 6 deletions Tests/SuperLinq.Async.Test/LeftOuterJoin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace Test.Async;
public class LeftOuterJoinTest
{
public static IEnumerable<object[]> GetJoinTypes() =>
new[]
{
new object[] { JoinType.Loop, },
new object[] { JoinType.Hash, },
new object[] { JoinType.Merge, },
};
[
[JoinType.Loop,],
[JoinType.Hash,],
[JoinType.Merge,],
];

[Theory, MemberData(nameof(GetJoinTypes))]
public void LeftOuterJoinIsLazy(JoinType joinType)
Expand Down
Loading