-
Notifications
You must be signed in to change notification settings - Fork 60
[Repo Assist] Test: add UniqueNameGenerator unit tests #319
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
Merged
sergey-tihon
merged 2 commits into
master
from
repo-assist/test-unique-name-generator-2026-03-11-90443b2c3b139800
Mar 11, 2026
+74
β0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| namespace SwaggerProvider.Tests.UtilsTests | ||
|
|
||
| open Xunit | ||
| open FsUnitTyped | ||
| open SwaggerProvider.Internal | ||
|
|
||
| /// Unit tests for UniqueNameGenerator β used by all DefinitionCompilers and OperationCompilers | ||
| /// to de-duplicate property and method names within a given type scope. | ||
| module UniqueNameGeneratorTests = | ||
|
|
||
| [<Fact>] | ||
| let ``first use of a name is returned unchanged``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "Foo" |> shouldEqual "Foo" | ||
|
|
||
| [<Fact>] | ||
| let ``second use of same name gets numeric suffix 1``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "Bar" |> ignore | ||
| gen.MakeUnique "Bar" |> shouldEqual "Bar1" | ||
|
|
||
| [<Fact>] | ||
| let ``third use of same name gets numeric suffix 2``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "Bar" |> ignore | ||
| gen.MakeUnique "Bar" |> ignore | ||
| gen.MakeUnique "Bar" |> shouldEqual "Bar2" | ||
|
|
||
| [<Fact>] | ||
| let ``collision detection is case-insensitive``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "Foo" |> ignore | ||
| // "foo" collides with "Foo" because comparison is case-insensitive | ||
| gen.MakeUnique "foo" |> shouldEqual "foo1" | ||
|
|
||
| [<Fact>] | ||
| let ``original casing of the returned name is preserved``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "MyProperty" |> shouldEqual "MyProperty" | ||
|
|
||
| [<Fact>] | ||
| let ``suffix casing follows the input not the stored key``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "myMethod" |> ignore | ||
| // Suffix is appended to the original input, preserving its casing | ||
| gen.MakeUnique "myMethod" |> shouldEqual "myMethod1" | ||
|
|
||
| [<Fact>] | ||
| let ``different names do not collide``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "Alpha" |> shouldEqual "Alpha" | ||
| gen.MakeUnique "Beta" |> shouldEqual "Beta" | ||
| gen.MakeUnique "Gamma" |> shouldEqual "Gamma" | ||
|
|
||
| [<Fact>] | ||
| let ``numeric suffixes increment sequentially``() = | ||
| let gen = UniqueNameGenerator() | ||
| let names = [ for _ in 0..4 -> gen.MakeUnique "X" ] | ||
| names |> shouldEqual [ "X"; "X1"; "X2"; "X3"; "X4" ] | ||
|
|
||
| [<Fact>] | ||
| let ``name equal to a previously suffixed name is also de-duplicated``() = | ||
| // After generating "Op" and "Op1", adding "Op1" should produce "Op11" | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "Op" |> ignore // reserves "op" | ||
| gen.MakeUnique "Op" |> ignore // reserves "op1" | ||
| gen.MakeUnique "Op1" |> shouldEqual "Op11" // "op1" is taken β try "op11" | ||
|
|
||
| [<Fact>] | ||
| let ``empty string is accepted as input``() = | ||
| let gen = UniqueNameGenerator() | ||
| gen.MakeUnique "" |> shouldEqual "" | ||
| gen.MakeUnique "" |> shouldEqual "1" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test
suffix casing follows the input not the stored keydoesnβ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.