Skip to content

Commit

Permalink
#292 #293 made some changes around handler field usage
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonBock committed Jan 14, 2024
1 parent e350e8b commit beca06d
Show file tree
Hide file tree
Showing 45 changed files with 1,556 additions and 1,163 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [8.0.0-alpha.2] - 2024-01-14

### Changed

- Updated handler list generation to reduce allocations (issue [#292](https://github.com/JasonBock/Rocks/issues/292)) and (issue [#293](https://github.com/JasonBock/Rocks/issues/293))

## [8.0.0-alpha.1] - 2024-01-13

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<Version>8.0.0-alpha.1</Version>
<Version>8.0.0-alpha.2</Version>
</PropertyGroup>
</Project>
49 changes: 28 additions & 21 deletions src/Rocks.Tests/Generators/AllowNullGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ internal sealed class Handler1
#pragma warning restore CS8618
private readonly global::System.Collections.Generic.List<global::MockTests.IAllowCreateExpectations.Handler0> @handlers0 = new();
private readonly global::System.Collections.Generic.List<global::MockTests.IAllowCreateExpectations.Handler1> @handlers1 = new();
private global::System.Collections.Generic.List<global::MockTests.IAllowCreateExpectations.Handler0>? @handlers0;
private global::System.Collections.Generic.List<global::MockTests.IAllowCreateExpectations.Handler1>? @handlers1;
public override void Verify()
{
if (this.WasInstanceInvoked)
{
var failures = new global::System.Collections.Generic.List<string>();
failures.AddRange(this.Verify(handlers0));
failures.AddRange(this.Verify(handlers1));
if (this.handlers0?.Count > 0) { failures.AddRange(this.Verify(this.handlers0)); }
if (this.handlers1?.Count > 0) { failures.AddRange(this.Verify(this.handlers1)); }
if (failures.Count > 0)
{
Expand All @@ -84,7 +84,7 @@ public string NewLine
{
get
{
if (this.Expectations.handlers0.Count > 0)
if (this.Expectations.handlers0?.Count > 0)
{
var @handler = this.Expectations.handlers0[0];
@handler.CallCount++;
Expand All @@ -97,7 +97,7 @@ public string NewLine
}
set
{
if (this.Expectations.handlers1.Count > 0)
if (this.Expectations.handlers1?.Count > 0)
{
var @foundMatch = false;
foreach (var @handler in this.Expectations.handlers1)
Expand Down Expand Up @@ -135,6 +135,7 @@ internal PropertyGetterExpectations(global::MockTests.IAllowCreateExpectations e
internal global::Rocks.Adornments<global::MockTests.IAllowCreateExpectations.Handler0, global::System.Func<string>, string> NewLine()
{
if (this.Expectations.handlers0 is null ) { this.Expectations.handlers0 = new(); }
var handler = new global::MockTests.IAllowCreateExpectations.Handler0();
this.Expectations.handlers0.Add(handler);
return new(handler);
Expand All @@ -154,6 +155,7 @@ internal PropertySetterExpectations(global::MockTests.IAllowCreateExpectations e
value = @value,
};
if (this.Expectations.handlers1 is null ) { this.Expectations.handlers1 = new(); }
this.Expectations.handlers1.Add(handler);
return new(handler);
}
Expand Down Expand Up @@ -316,23 +318,23 @@ internal sealed class Handler4
#pragma warning restore CS8618
private readonly global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler0> @handlers0 = new();
private readonly global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler1> @handlers1 = new();
private readonly global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler2> @handlers2 = new();
private readonly global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler3> @handlers3 = new();
private readonly global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler4> @handlers4 = new();
private global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler0>? @handlers0;
private global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler1>? @handlers1;
private global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler2>? @handlers2;
private global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler3>? @handlers3;
private global::System.Collections.Generic.List<global::MockTests.AllowCreateExpectations.Handler4>? @handlers4;
public override void Verify()
{
if (this.WasInstanceInvoked)
{
var failures = new global::System.Collections.Generic.List<string>();
failures.AddRange(this.Verify(handlers0));
failures.AddRange(this.Verify(handlers1));
failures.AddRange(this.Verify(handlers2));
failures.AddRange(this.Verify(handlers3));
failures.AddRange(this.Verify(handlers4));
if (this.handlers0?.Count > 0) { failures.AddRange(this.Verify(this.handlers0)); }
if (this.handlers1?.Count > 0) { failures.AddRange(this.Verify(this.handlers1)); }
if (this.handlers2?.Count > 0) { failures.AddRange(this.Verify(this.handlers2)); }
if (this.handlers3?.Count > 0) { failures.AddRange(this.Verify(this.handlers3)); }
if (this.handlers4?.Count > 0) { failures.AddRange(this.Verify(this.handlers4)); }
if (failures.Count > 0)
{
Expand All @@ -352,7 +354,7 @@ public Mock(global::MockTests.AllowCreateExpectations @expectations)
[global::Rocks.MemberIdentifier(0, "bool Equals(object? @obj)")]
public override bool Equals(object? @obj)
{
if (this.Expectations.handlers0.Count > 0)
if (this.Expectations.handlers0?.Count > 0)
{
foreach (var @handler in this.Expectations.handlers0)
{
Expand All @@ -376,7 +378,7 @@ public override bool Equals(object? @obj)
[global::Rocks.MemberIdentifier(1, "int GetHashCode()")]
public override int GetHashCode()
{
if (this.Expectations.handlers1.Count > 0)
if (this.Expectations.handlers1?.Count > 0)
{
var @handler = this.Expectations.handlers1[0];
@handler.CallCount++;
Expand All @@ -393,7 +395,7 @@ public override int GetHashCode()
[global::Rocks.MemberIdentifier(2, "string? ToString()")]
public override string? ToString()
{
if (this.Expectations.handlers2.Count > 0)
if (this.Expectations.handlers2?.Count > 0)
{
var @handler = this.Expectations.handlers2[0];
@handler.CallCount++;
Expand All @@ -414,7 +416,7 @@ public override string NewLine
{
get
{
if (this.Expectations.handlers3.Count > 0)
if (this.Expectations.handlers3?.Count > 0)
{
var @handler = this.Expectations.handlers3[0];
@handler.CallCount++;
Expand All @@ -429,7 +431,7 @@ public override string NewLine
}
set
{
if (this.Expectations.handlers4.Count > 0)
if (this.Expectations.handlers4?.Count > 0)
{
var @foundMatch = false;
foreach (var @handler in this.Expectations.handlers4)
Expand Down Expand Up @@ -473,19 +475,22 @@ internal MethodExpectations(global::MockTests.AllowCreateExpectations expectatio
@obj = @obj,
};
if (this.Expectations.handlers0 is null ) { this.Expectations.handlers0 = new(); }
this.Expectations.handlers0.Add(handler);
return new(handler);
}
internal new global::Rocks.Adornments<global::MockTests.AllowCreateExpectations.Handler1, global::System.Func<int>, int> GetHashCode()
{
if (this.Expectations.handlers1 is null ) { this.Expectations.handlers1 = new(); }
var handler = new global::MockTests.AllowCreateExpectations.Handler1();
this.Expectations.handlers1.Add(handler);
return new(handler);
}
internal new global::Rocks.Adornments<global::MockTests.AllowCreateExpectations.Handler2, global::System.Func<string?>, string?> ToString()
{
if (this.Expectations.handlers2 is null ) { this.Expectations.handlers2 = new(); }
var handler = new global::MockTests.AllowCreateExpectations.Handler2();
this.Expectations.handlers2.Add(handler);
return new(handler);
Expand All @@ -503,6 +508,7 @@ internal PropertyGetterExpectations(global::MockTests.AllowCreateExpectations ex
internal global::Rocks.Adornments<global::MockTests.AllowCreateExpectations.Handler3, global::System.Func<string>, string> NewLine()
{
if (this.Expectations.handlers3 is null ) { this.Expectations.handlers3 = new(); }
var handler = new global::MockTests.AllowCreateExpectations.Handler3();
this.Expectations.handlers3.Add(handler);
return new(handler);
Expand All @@ -522,6 +528,7 @@ internal PropertySetterExpectations(global::MockTests.AllowCreateExpectations ex
value = @value,
};
if (this.Expectations.handlers4 is null ) { this.Expectations.handlers4 = new(); }
this.Expectations.handlers4.Add(handler);
return new(handler);
}
Expand Down
28 changes: 16 additions & 12 deletions src/Rocks.Tests/Generators/AsyncIteratorGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ internal sealed class Handler3
#pragma warning restore CS8618
private readonly global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler0> @handlers0 = new();
private readonly global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler1> @handlers1 = new();
private readonly global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler2> @handlers2 = new();
private readonly global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler3> @handlers3 = new();
private global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler0>? @handlers0;
private global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler1>? @handlers1;
private global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler2>? @handlers2;
private global::System.Collections.Generic.List<global::AsyncEnumerationCreateExpectations.Handler3>? @handlers3;
public override void Verify()
{
if (this.WasInstanceInvoked)
{
var failures = new global::System.Collections.Generic.List<string>();
failures.AddRange(this.Verify(handlers0));
failures.AddRange(this.Verify(handlers1));
failures.AddRange(this.Verify(handlers2));
failures.AddRange(this.Verify(handlers3));
if (this.handlers0?.Count > 0) { failures.AddRange(this.Verify(this.handlers0)); }
if (this.handlers1?.Count > 0) { failures.AddRange(this.Verify(this.handlers1)); }
if (this.handlers2?.Count > 0) { failures.AddRange(this.Verify(this.handlers2)); }
if (this.handlers3?.Count > 0) { failures.AddRange(this.Verify(this.handlers3)); }
if (failures.Count > 0)
{
Expand All @@ -95,7 +95,7 @@ public Mock(global::AsyncEnumerationCreateExpectations @expectations)
[global::Rocks.MemberIdentifier(0, "bool Equals(object? @obj)")]
public override bool Equals(object? @obj)
{
if (this.Expectations.handlers0.Count > 0)
if (this.Expectations.handlers0?.Count > 0)
{
foreach (var @handler in this.Expectations.handlers0)
{
Expand All @@ -119,7 +119,7 @@ public override bool Equals(object? @obj)
[global::Rocks.MemberIdentifier(1, "int GetHashCode()")]
public override int GetHashCode()
{
if (this.Expectations.handlers1.Count > 0)
if (this.Expectations.handlers1?.Count > 0)
{
var @handler = this.Expectations.handlers1[0];
@handler.CallCount++;
Expand All @@ -136,7 +136,7 @@ public override int GetHashCode()
[global::Rocks.MemberIdentifier(2, "string? ToString()")]
public override string? ToString()
{
if (this.Expectations.handlers2.Count > 0)
if (this.Expectations.handlers2?.Count > 0)
{
var @handler = this.Expectations.handlers2[0];
@handler.CallCount++;
Expand All @@ -153,7 +153,7 @@ public override int GetHashCode()
[global::Rocks.MemberIdentifier(3, "global::System.Collections.Generic.IAsyncEnumerable<string> GetRecordsAsync(global::System.Threading.CancellationToken @cancellationToken)")]
public override global::System.Collections.Generic.IAsyncEnumerable<string> GetRecordsAsync(global::System.Threading.CancellationToken @cancellationToken = default)
{
if (this.Expectations.handlers3.Count > 0)
if (this.Expectations.handlers3?.Count > 0)
{
foreach (var @handler in this.Expectations.handlers3)
{
Expand Down Expand Up @@ -191,19 +191,22 @@ internal MethodExpectations(global::AsyncEnumerationCreateExpectations expectati
@obj = @obj,
};
if (this.Expectations.handlers0 is null ) { this.Expectations.handlers0 = new(); }
this.Expectations.handlers0.Add(handler);
return new(handler);
}
internal new global::Rocks.Adornments<global::AsyncEnumerationCreateExpectations.Handler1, global::System.Func<int>, int> GetHashCode()
{
if (this.Expectations.handlers1 is null ) { this.Expectations.handlers1 = new(); }
var handler = new global::AsyncEnumerationCreateExpectations.Handler1();
this.Expectations.handlers1.Add(handler);
return new(handler);
}
internal new global::Rocks.Adornments<global::AsyncEnumerationCreateExpectations.Handler2, global::System.Func<string?>, string?> ToString()
{
if (this.Expectations.handlers2 is null ) { this.Expectations.handlers2 = new(); }
var handler = new global::AsyncEnumerationCreateExpectations.Handler2();
this.Expectations.handlers2.Add(handler);
return new(handler);
Expand All @@ -218,6 +221,7 @@ internal MethodExpectations(global::AsyncEnumerationCreateExpectations expectati
@cancellationToken = @cancellationToken.Transform(default),
};
if (this.Expectations.handlers3 is null ) { this.Expectations.handlers3 = new(); }
this.Expectations.handlers3.Add(handler);
return new(handler);
}
Expand Down
Loading

0 comments on commit beca06d

Please sign in to comment.