Repository navigation
Make Select and MultiSelect item and limit handling consistent - #430
Merged
Merged
Conversation
- Equal items are listed once, at the position of the first. In
MultiSelect, checking one of several equal items checked all of them
and returned each, so the result could exceed Maximum and disagree with
the Minimum check.
- Options that leave the prompt unanswerable now throw before it is
shown: an empty Select (ArgumentException) and a MultiSelect whose
Minimum exceeds the number of items (ArgumentOutOfRangeException).
Before, the user could only cancel, which exits the process when
ThrowExceptionOnCancel is false.
- Options are validated and Items are snapshotted before the base
constructor creates the console driver, so invalid options no longer
leave it undisposed.
- The Japanese invalid-minimum message referenced {1} with a single
argument and threw FormatException instead of the intended
ArgumentOutOfRangeException.
- Docs (en/ja) describe the item rules and how Minimum and Maximum apply
to each MultiSelect operation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Static review found no blocking issues; the remaining documentation clarification is nonblocking.
1 open issue
1 file not reviewed
src/Sharprompt/Strings/Resource.Designer.cs: Generated file
What changed in this PR
Makes Select and MultiSelect boundary behavior consistent and documents compatibility changes.
Changes:
- Deduplicates items and rejects unanswerable options before creating the console driver.
- Adds localized validation messages and fixes Japanese error formatting.
- Adds regression tests and English/Japanese selection rules.
| File | Description |
|---|---|
| tests/Sharprompt.Tests/Forms/FormInteractionTests.cs | Tests duplicates, validation timing, and localized errors. |
| src/Sharprompt/Strings/Resource.zh-Hans.resx | Adds Chinese validation messages. |
| src/Sharprompt/Strings/Resource.resx | Adds default validation messages. |
| src/Sharprompt/Strings/Resource.ja.resx | Adds Japanese messages and fixes a placeholder. |
| src/Sharprompt/Strings/Resource.Designer.cs | Exposes new resource strings. |
| src/Sharprompt/Strings/Resource.de-DE.resx | Adds German validation messages. |
| src/Sharprompt/Forms/SelectForm.cs | Deduplicates items and validates before driver creation. |
| src/Sharprompt/Forms/MultiSelectForm.cs | Deduplicates items and rejects impossible minimums early. |
| docs/ja/prompt-types/select.md | Documents Select rules in Japanese. |
| docs/ja/prompt-types/multi-select.md | Documents MultiSelect rules in Japanese. |
| docs/en/prompt-types/select.md | Documents Select rules in English. |
| docs/en/prompt-types/multi-select.md | Documents MultiSelect rules in English. |
Review effort: Balanced
An unmatched DefaultValue does not select anything, but when only one item is listed, with or without a filter, that item is selected, so Enter returns it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved issues were identified, and the implementation, regression coverage, and documentation consistently address the intended boundary conditions.
No open issues 🎉
1 resolved since last review
1 file not reviewed
src/Sharprompt/Strings/Resource.Designer.cs: Generated file
Review effort: Balanced
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
Closes #410.
#403 and #417 already covered part of this issue:
Itemsfor rendering and the resultDefaultValuesoutsideItemsare ignoredMaximumare rejected as a wholeThis PR covers the remaining boundary conditions and documents the rules.
Changes
Duplicate items (Select and MultiSelect): equal items (
EqualityComparer<T>.Default) are listed once, at the position of the first.Items = ["a", "a"]andMaximum = 1, Enter returned two items, andMinimumcounted distinct items while the result did not.Options that make the prompt unanswerable now throw before it is shown:
ArgumentException(Items)Minimum> item count (after duplicates are removed)ArgumentOutOfRangeException(Minimum)With these options, the only way out was to cancel. When
ThrowExceptionOnCancelisfalse, canceling callsEnvironment.Exit(1). An empty MultiSelect withMinimum = 0still works.Validation before the driver is created: options are validated and
Itemsis snapshotted in a staticPreparethat runs before the base constructor creates the console driver. Before, invalid options (for example, a negativeMinimum) threw after the driver was created, and the driver was never disposed.Japanese message fix:
Validation_Minimum_OutOfRangereferenced{1}with a single argument. In thejaculture, a negativeMinimumthrewFormatExceptioninstead ofArgumentOutOfRangeException.New messages: for the two new exceptions, in en, ja, de-DE, and zh-Hans.
Docs (en/ja):
DefaultValue, Enter and filter selection, empty items).MinimumandMaximumapply to Space, Ctrl+A / Ctrl+I,DefaultValues, and Enter.Compatibility
ArgumentException. The test that pinned the old behavior is replaced.DefaultValuesthanMaximumstill start checked, and Enter is rejected until enough are unchecked. The prompt can still be answered, so the rule is to throw only when it cannot be answered.Testing
FormInteractionTests:Minimum> items, including duplicates and emptyItems, throw without creating the console driverMaximum = 1dotnet build,dotnet test(1246 passed), anddotnet format --verify-no-changes🤖 Generated with Claude Code