[Repo Assist] Test: add UniqueNameGenerator unit tests#319
Conversation
UniqueNameGenerator is used in all v2/v3 DefinitionCompilers and OperationCompilers to de-duplicate property and method names within each generated type scope — but had no dedicated tests. Add 10 tests covering: - first/second/nth use of the same name - case-insensitive collision detection - casing preservation in returned names - sequential numeric suffixes (X, X1, X2, ...) - name-suffix chaining edge case (Op → Op1 → Op1 collision → Op11) - empty-string input Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds unit test coverage for UniqueNameGenerator to lock in its de-duplication behavior (used across v2/v3 definition & operation compilers) and prevent regressions that could lead to generated duplicate member names.
Changes:
- Added 10 new xUnit tests covering suffixing, case-insensitive collisions, and edge cases (including empty string).
- Included the new test file in the test project compilation list.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/SwaggerProvider.Tests/UtilsTests.fs | Adds a dedicated UniqueNameGenerator test module with 10 facts covering expected uniqueness behavior. |
| tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj | Adds UtilsTests.fs to the compile items so the new tests run in CI/local. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| // Suffix is appended to the original input, preserving its casing | ||
| gen.MakeUnique "myMethod" |> shouldEqual "myMethod1" |
There was a problem hiding this comment.
The test suffix casing follows the input not the stored key doesn’t currently exercise the scenario described by its name/comment: both calls use the same casing ("myMethod"), and the suffix is numeric so casing can’t differ. Consider changing the second call to a different-cased input (e.g., first "myMethod" then "MYMETHOD" expecting "MYMETHOD1"), or renaming the test to match what it actually asserts.
| // Suffix is appended to the original input, preserving its casing | |
| gen.MakeUnique "myMethod" |> shouldEqual "myMethod1" | |
| // Suffix is appended to the current input ("MYMETHOD"), preserving its casing | |
| gen.MakeUnique "MYMETHOD" |> shouldEqual "MYMETHOD1" |
🤖 This is a pull request from Repo Assist, an automated AI assistant.
Summary
Task 9 — Testing Improvement:
UniqueNameGenerator(insrc/SwaggerProvider.DesignTime/Utils.fs) is used by all four compilers (v2/v3 DefinitionCompiler and OperationCompiler) to de-duplicate property and method names within each generated type scope — but it had no unit tests at all.What's tested
10 new
[(Fact)]tests intests/SwaggerProvider.Tests/UtilsTests.fs:"Foo"→"Foo""Bar","Bar"→"Bar","Bar1""Bar2""Foo"then"foo"→"foo1""myMethod"→"myMethod1"X, X1, X2, X3, X4OpandOp1are taken,Op1→Op11""→"", then""→"1"Why this matters
A regression in
UniqueNameGenerator(e.g., if the case-insensitivity logic broke) would silently produce duplicate property names in generated types, causing compile errors in user code. These tests pin down the documented behaviour.Test Status
dotnet build SwaggerProvider.sln -c Release— 0 errorsdotnet tests/SwaggerProvider.Tests/bin/Release/net10.0/SwaggerProvider.Tests.dll— 190 passed (180 → 190, +10 new tests), 0 failed, 2 skippeddotnet fantomas tests/SwaggerProvider.Tests/UtilsTests.fs --check— format clean