Skip to content

refactor!: Consolidate StartsWith/EndsWith and AsPrefix/AsSuffix for strings#763

Merged
vbreuss merged 2 commits intomainfrom
topic/consolidate-startwith-prefix-and-endwith-suffix
Sep 6, 2025
Merged

refactor!: Consolidate StartsWith/EndsWith and AsPrefix/AsSuffix for strings#763
vbreuss merged 2 commits intomainfrom
topic/consolidate-startwith-prefix-and-endwith-suffix

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Sep 6, 2025

This PR consolidates the StartsWith/EndsWith string assertion methods with the existing AsPrefix/AsSuffix functionality by refactoring them to use a unified IsEqualToConstraint approach instead of separate constraint implementations. The change is marked as breaking (refactor!:), because the return type was incorrectly set to StringEqualityTypeResult and is now fixed.

Key changes:

  • Replaces StartsWithConstraint and EndsWithConstraint with IsEqualToConstraint using prefix/suffix options
  • Updates method return types from StringEqualityTypeResult to StringEqualityResult
  • Improves error messages to show detailed diff information and actual values

@vbreuss vbreuss self-assigned this Sep 6, 2025
Copilot AI review requested due to automatic review settings September 6, 2025 21:07
@vbreuss vbreuss added breaking change The changes require a new major version refactor A change or improvement without functional impact and removed breaking change The changes require a new major version labels Sep 6, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR consolidates the StartsWith/EndsWith string assertion methods with the existing AsPrefix/AsSuffix functionality by refactoring them to use a unified IsEqualToConstraint approach instead of separate constraint implementations. The change is marked as breaking (refactor!:).

  • Replaces StartsWithConstraint and EndsWithConstraint with IsEqualToConstraint using prefix/suffix options
  • Updates method return types from StringEqualityTypeResult to StringEqualityResult
  • Improves error messages to show detailed diff information and actual values

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Source/aweXpect/That/Strings/ThatString.StartsWith.cs Refactors StartsWith/DoesNotStartWith to use IsEqualToConstraint with AsPrefix() option
Source/aweXpect/That/Strings/ThatString.EndsWith.cs Refactors EndsWith/DoesNotEndWith to use IsEqualToConstraint with AsSuffix() option
Tests/aweXpect.Api.Tests/Expected/aweXpect_netstandard2.0.txt Updates API surface to reflect StringEqualityResult return types
Tests/aweXpect.Api.Tests/Expected/aweXpect_net8.0.txt Updates API surface to reflect StringEqualityResult return types
Tests/aweXpect.Tests/Strings/*.Tests.cs Updates test expectations for improved error message formatting
Source/aweXpect.Core/Options/CollectionMatchOptions.cs Refactors private field to public property in ExpectationItem
Source/aweXpect/That/Collections/ThatEnumerable.HasItemThat.cs Updates ManualExpectationBuilder constructor calls
Source/aweXpect/That/Collections/ThatAsyncEnumerable.HasItemThat.cs Updates ManualExpectationBuilder constructor calls
Comments suppressed due to low confidence (1)

Tests/aweXpect.Tests/Strings/ThatString.IsNotEqualTo.Tests.cs:1

  • Method name contains a typo: 'Ununexpected' should be 'Unexpected'.
namespace aweXpect.Tests;

@vbreuss vbreuss added the breaking change The changes require a new major version label Sep 6, 2025
@vbreuss vbreuss enabled auto-merge (squash) September 6, 2025 21:10
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Sep 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
2 New issues

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 6, 2025

Test Results

    14 files   - 24      14 suites   - 24   5m 18s ⏱️ -24s
17 573 tests  - 24  17 571 ✅  - 24  2 💤 ±0  0 ❌ ±0 
49 380 runs   - 72  49 378 ✅  - 72  2 💤 ±0  0 ❌ ±0 

Results for commit 2f0812c. ± Comparison against base commit d94595c.

This pull request removes 1575 and adds 1551 tests. Note that renamed tests count towards both.
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message72542624-a4ee-4343-b7ee-eab4cb6fc4cf")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagee3ef69f0-3201-4e08-83ef-6b0844f15cf0")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagef96e5c9f-09e4-4a43-8aab-0ac97d1fabde")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message18bb16a8-8b15-4c77-abc3-bc212aab3842")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message3fa4d0f3-ae7e-484b-8f5b-3e37ae387e2c")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message7a7dfa7c-b0e8-40e2-b081-fcd217d09193")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason8bb3e7e4-b337-4cce-91cf-5000cc532272")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reasonbcb4a0e0-d30c-4271-b2b3-eb7836d003b7")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reasonee9042f7-60b0-4b6c-b18b-1efd3ef7734d")
aweXpect.Core.Tests.FailTests ‑ Unless_ShouldThrowException(condition: False, reason: "reason1d6e28f2-7ec5-4a75-a4ed-fbb84ae05da3")
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message1aa51d30-388a-4f3e-91c7-5ca39ce9f1fd")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message57cd89b5-19b6-4f33-86ad-0b8af361321f")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagec967a462-ad22-47de-8dfa-c6cc166327e7")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message5da30a5e-d044-4285-8eaa-60839f6e966e")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message69c18390-31c2-4506-b855-9ab1c7c09dbc")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messagefa75fe47-a0c6-4dda-86d5-c10089c1c3ed")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason02cc1e00-dbd5-4034-ac81-52857a9d30b8")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason108c2042-e78e-4ba1-8778-664473c8f39a")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason8e7ef23c-bc16-422b-bd11-8fd7ccfd6733")
aweXpect.Core.Tests.FailTests ‑ Unless_ShouldThrowException(condition: False, reason: "reason1ce60b72-ee72-4e49-b239-b1aeea22c9d4")
…

@vbreuss vbreuss merged commit 4dc12c1 into main Sep 6, 2025
13 of 14 checks passed
@vbreuss vbreuss deleted the topic/consolidate-startwith-prefix-and-endwith-suffix branch September 6, 2025 21:17
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 6, 2025

🚀 Benchmark Results

Details

BenchmarkDotNet v0.14.0, Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.413
[Host] : .NET 8.0.19 (8.0.1925.36514), X64 RyuJIT AVX2

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 228.5 ns 4.06 ns 3.80 ns 0.0300 - 504 B
Bool_FluentAssertions 260.9 ns 4.34 ns 4.06 ns 0.0567 - 952 B
Bool_TUnit 908.8 ns 10.96 ns 10.25 ns 0.1431 - 2408 B
Equivalency_aweXpect 308,764.4 ns 1,608.58 ns 1,425.96 ns 20.0195 0.9766 335556 B
Equivalency_FluentAssertions 2,307,256.1 ns 23,899.40 ns 19,957.08 ns 273.4375 46.8750 4584416 B
Equivalency_TUnit 703,699.6 ns 3,969.78 ns 3,519.11 ns 51.7578 2.9297 880545 B
Int_GreaterThan_aweXpect 266.2 ns 3.65 ns 3.24 ns 0.0486 - 816 B
Int_GreaterThan_FluentAssertions 262.7 ns 8.91 ns 8.34 ns 0.0730 - 1224 B
Int_GreaterThan_TUnit 1,286.4 ns 13.87 ns 12.98 ns 0.1774 - 2984 B
ItemsCount_AtLeast_aweXpect 538.8 ns 8.70 ns 8.14 ns 0.0868 - 1464 B
ItemsCount_AtLeast_FluentAssertions 502.7 ns 6.25 ns 5.22 ns 0.1192 - 2008 B
ItemsCount_AtLeast_TUnit 16,279.5 ns 185.03 ns 164.03 ns 1.6174 - 27480 B
String_aweXpect 462.8 ns 2.83 ns 2.50 ns 0.0734 - 1232 B
String_FluentAssertions 545.0 ns 4.85 ns 4.30 ns 0.1287 - 2168 B
String_TUnit 1,316.6 ns 10.26 ns 9.60 ns 0.1831 - 3072 B
StringArray_aweXpect 1,832.5 ns 5.05 ns 4.48 ns 0.1717 - 2888 B
StringArray_FluentAssertions 1,466.8 ns 4.54 ns 4.02 ns 0.2480 - 4152 B
StringArray_TUnit 3,426.3 ns 13.13 ns 12.28 ns 0.3128 - 5296 B
StringArrayInAnyOrder_aweXpect 2,331.4 ns 5.63 ns 5.00 ns 0.1831 - 3080 B
StringArrayInAnyOrder_FluentAssertions 152,839.9 ns 642.70 ns 536.69 ns 3.4180 - 63788 B
StringArrayInAnyOrder_TUnit 4,042.9 ns 20.29 ns 18.98 ns 0.3815 - 6488 B

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 6, 2025

👽 Mutation Results

Mutation testing badge

aweXpect

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Total Detected Total Undetected Total Mutants
That/Collections/ThatAsyncEnumerable.HasItemThat.cs 67.35% 32 2 1 14 18 16 33 16 83
That/Collections/ThatEnumerable.HasItemThat.cs 86.84% 64 7 2 3 24 30 66 10 130
That/Strings/ThatString.EndsWith.cs 4.65% 2 0 0 41 11 16 2 41 70
That/Strings/ThatString.StartsWith.cs 4.88% 2 0 0 39 11 16 2 39 68

The final mutation score is 49.28%

Coverage Thresholds: high:80 low:60 break:0

aweXpect.Core

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Total Detected Total Undetected Total Mutants
Options/CollectionMatchOptions.cs 95.24% 80 1 0 3 36 77 80 4 197

The final mutation score is 95.24%

Coverage Thresholds: high:80 low:60 break:0

github-actions Bot added a commit that referenced this pull request Sep 6, 2025
…dsWith` and `AsPrefix`/`AsSuffix` for strings (#763) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Sep 6, 2025
…dsWith` and `AsPrefix`/`AsSuffix` for strings (#763) by Valentin Breuß
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 9, 2025

This is addressed in release v2.23.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The changes require a new major version refactor A change or improvement without functional impact state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants