Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into issue665
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Jan 20, 2023
2 parents 6a59821 + c081197 commit 78c7b8a
Show file tree
Hide file tree
Showing 244 changed files with 8,103 additions and 3,542 deletions.
8 changes: 7 additions & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
"isRoot": true,
"tools": {
"dotnet-t4": {
"version": "2.0.5",
"version": "2.3.0",
"commands": [
"t4"
]
},
"dotnet-reportgenerator-globaltool": {
"version": "5.1.11",
"commands": [
"reportgenerator"
]
}
}
}
50 changes: 48 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
# http://editorconfig.org/

root = true

[*]
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.xml]
indent_style = space
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

[*.Build.{props,targets}]
indent_size = 2

[*.{sln}]
indent_style = tab

[*.{json,yml}]
indent_size = 2

[*.{cs,tt}]
charset = utf-8
indent_style = space
indent_size = 4
max_line_length = 100

[*.cs]
# Prefer "var" everywhere
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion

# Spacing
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = false

# Wrapping
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.opencover.xml
**/TestResults/

### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down
51 changes: 0 additions & 51 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<PropertyGroup>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>7.0-all</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
</Project>
28 changes: 28 additions & 0 deletions MoreLinq.Test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[*.cs]

# CA1034: Nested types should not be visible
dotnet_diagnostic.CA1034.severity = none

# CA1062: Validate arguments of public methods
dotnet_diagnostic.CA1062.severity = none

# CA1825: Avoid zero-length array allocations
dotnet_diagnostic.CA1825.severity = suggestion

# CA1032: Implement standard exception constructors
dotnet_diagnostic.CA1032.severity = none

# CA1064: Exceptions should be public
dotnet_diagnostic.CA1064.severity = none

# CA1303: Do not pass literals as localized parameters
dotnet_diagnostic.CA1303.severity = none

# CA5394: Do not use insecure randomness
dotnet_diagnostic.CA5394.severity = none

# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = none

# CA1308: Normalize strings to uppercase
dotnet_diagnostic.CA1308.severity = none
18 changes: 9 additions & 9 deletions MoreLinq.Test/AcquireTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region License and Terms
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
// Copyright (c) 2012 Atif Aziz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -26,9 +26,9 @@ public class AcquireTest
[Test]
public void AcquireAll()
{
Disposable a = null;
Disposable b = null;
Disposable c = null;
Disposable? a = null;
Disposable? b = null;
Disposable? c = null;

var allocators = MoreEnumerable.From(() => a = new Disposable(),
() => b = new Disposable(),
Expand All @@ -48,16 +48,16 @@ public void AcquireAll()
[Test]
public void AcquireSome()
{
Disposable a = null;
Disposable b = null;
Disposable c = null;
Disposable? a = null;
Disposable? b = null;
Disposable? c = null;

var allocators = MoreEnumerable.From(() => a = new Disposable(),
() => b = new Disposable(),
() => throw new TestException(),
() => c = new Disposable());

Assert.Throws<TestException>(() => allocators.Acquire());
Assert.That(allocators.Acquire, Throws.TypeOf<TestException>());

Assert.That(a, Is.Not.Null);
Assert.That(a.Disposed, Is.True);
Expand All @@ -66,7 +66,7 @@ public void AcquireSome()
Assert.That(c, Is.Null);
}

class Disposable : IDisposable
sealed class Disposable : IDisposable
{
public bool Disposed { get; private set; }
public void Dispose() { Disposed = true; }
Expand Down
17 changes: 8 additions & 9 deletions MoreLinq.Test/AggregateRightTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace MoreLinq.Test
{
using System;
using NUnit.Framework;

[TestFixture]
Expand All @@ -28,8 +27,8 @@ public class AggregateRightTest
[Test]
public void AggregateRightWithEmptySequence()
{
Assert.Throws<InvalidOperationException>(
() => new int[0].AggregateRight((a, b) => a + b));
Assert.That(() => new int[0].AggregateRight((a, b) => a + b),
Throws.InvalidOperationException);
}

[Test]
Expand All @@ -47,9 +46,9 @@ public void AggregateRightFuncIsNotInvokedOnSingleElementSequence()
[TestCase(SourceKind.Sequence)]
public void AggregateRight(SourceKind sourceKind)
{
var enumerable = Enumerable.Range(1, 5).Select(x => x.ToString()).ToSourceKind(sourceKind);
var enumerable = Enumerable.Range(1, 5).Select(x => x.ToInvariantString()).ToSourceKind(sourceKind);

var result = enumerable.AggregateRight((a, b) => string.Format("({0}+{1})", a, b));
var result = enumerable.AggregateRight((a, b) => $"({a}+{b})");

Assert.That(result, Is.EqualTo("(1+(2+(3+(4+5))))"));
}
Expand All @@ -61,7 +60,7 @@ public void AggregateRight(SourceKind sourceKind)
[TestCase(true)]
public void AggregateRightSeedWithEmptySequence(object defaultValue)
{
Assert.That(new int[0].AggregateRight(defaultValue, (a, b) => b), Is.EqualTo(defaultValue));
Assert.That(new int[0].AggregateRight(defaultValue, (_, b) => b), Is.EqualTo(defaultValue));
}

[Test]
Expand All @@ -78,7 +77,7 @@ public void AggregateRightSeedFuncIsNotInvokedOnEmptySequence()
public void AggregateRightSeed()
{
var result = Enumerable.Range(1, 4)
.AggregateRight("5", (a, b) => string.Format("({0}+{1})", a, b));
.AggregateRight("5", (a, b) => $"({a}+{b})");

Assert.That(result, Is.EqualTo("(1+(2+(3+(4+5))))"));
}
Expand All @@ -90,14 +89,14 @@ public void AggregateRightSeed()
[TestCase(true)]
public void AggregateRightResultorWithEmptySequence(object defaultValue)
{
Assert.That(new int[0].AggregateRight(defaultValue, (a, b) => b, a => a == defaultValue), Is.EqualTo(true));
Assert.That(new int[0].AggregateRight(defaultValue, (_, b) => b, a => a == defaultValue), Is.EqualTo(true));
}

[Test]
public void AggregateRightResultor()
{
var result = Enumerable.Range(1, 4)
.AggregateRight("5", (a, b) => string.Format("({0}+{1})", a, b), a => a.Length);
.AggregateRight("5", (a, b) => $"({a}+{b})", a => a.Length);

Assert.That(result, Is.EqualTo("(1+(2+(3+(4+5))))".Length));
}
Expand Down
26 changes: 14 additions & 12 deletions MoreLinq.Test/AggregateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace MoreLinq.Test
using System.Reactive.Linq;
using System.Reflection;
using NUnit.Framework.Interfaces;
using static FuncModule;

[TestFixture]
public class AggregateTest
Expand All @@ -51,8 +52,8 @@ from m in typeof(MoreEnumerable).GetMethods(BindingFlags.Public | BindingFlags.S
Source = source,
Expectation = sum,
Instantiation = m.MakeGenericMethod(Enumerable.Repeat(typeof(int), m.GetGenericArguments().Length - 1)
.Append(typeof(int[])) // TResult
.ToArray()),
.Append(typeof(int[])) // TResult
.ToArray()),
}
into m
let rst = m.Instantiation.GetParameters().Last().ParameterType
Expand All @@ -64,18 +65,19 @@ into m
AccumulatorCount = (m.Instantiation.GetParameters().Length - 2 /* source + resultSelector */) / 2 /* seed + accumulator */,
ResultSelectorType = rst,
Parameters =
rst.GetMethod("Invoke")
.GetParameters()
.Select(p => Expression.Parameter(p.ParameterType))
.ToArray(),
rst.GetMethod("Invoke") is { } invoke
? invoke.GetParameters()
.Select(p => Expression.Parameter(p.ParameterType))
.ToArray()
: throw new MissingMethodException("""Method "Invoke" not found."""),
}
into m
let resultSelector =
Expression.Lambda(m.ResultSelectorType,
Expression.NewArrayInit(typeof(int), m.Parameters),
m.Parameters)
.Compile()
let accumulator = new Func<int, int, int>((s, n) => s + n)
let accumulator = Func((int s, int n) => s + n)
select new
{
Name = $"{name}({m.AccumulatorCount})",
Expand All @@ -95,7 +97,7 @@ into t
select new TestCaseData(t.Method, t.Args).SetName(t.Name).Returns(t.Expectation);

[TestCaseSource(nameof(AccumulatorsTestSource), new object[] { nameof(Accumulators), 10 })]
public object Accumulators(MethodInfo method, object[] args) =>
public object? Accumulators(MethodInfo method, object[] args) =>
method.Invoke(null, args);

[Test]
Expand All @@ -110,8 +112,8 @@ public void SevenUniqueAccumulators()
0, (s, e) => s + e.Num,
0, (s, e) => e.Num % 2 == 0 ? s + e.Num : s,
0, (s, _) => s + 1,
(int?)null, (s, e) => s is int n ? Math.Min(n, e.Num) : e.Num,
(int?)null, (s, e) => s is int n ? Math.Max(n, e.Num) : e.Num,
(int?)null, (s, e) => s is {} n ? Math.Min(n, e.Num) : e.Num,
(int?)null, (s, e) => s is {} n ? Math.Max(n, e.Num) : e.Num,
new HashSet<int>(), (s, e) => { s.Add(e.Str.Length); return s; },
new List<(int Num, string Str)>(), (s, e) => { s.Add((e.Num, e.Str)); return s; },
(sum, esum, count, min, max, lengths, items) => new
Expand All @@ -120,8 +122,8 @@ public void SevenUniqueAccumulators()
EvenSum = esum,
Count = count,
Average = (double)sum / count,
Min = min is int mn ? mn : throw new InvalidOperationException(),
Max = max is int mx ? mx : throw new InvalidOperationException(),
Min = min ?? throw new InvalidOperationException(),
Max = max ?? throw new InvalidOperationException(),
UniqueLengths = lengths,
Items = items,
}
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/AppendTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void AppendWithEmptyHeadSequence()
public void AppendWithNullTail()
{
var head = new[] { "first", "second" };
string tail = null;
string? tail = null;
var whole = head.Append(tail);
whole.AssertSequenceEqual("first", "second", null);
}
Expand Down
Loading

0 comments on commit 78c7b8a

Please sign in to comment.