Skip to content

Add unit tests for various options and validators#329

Merged
shibayan merged 1 commit intomasterfrom
add-test-case
Feb 27, 2026
Merged

Add unit tests for various options and validators#329
shibayan merged 1 commit intomasterfrom
add-test-case

Conversation

@shibayan
Copy link
Owner

This pull request primarily adds comprehensive unit tests for several core components in the codebase, including options validation, fluent API extensions, registries, paginator logic, and exception handling. Additionally, it includes a minor code style update for collection initialization. These changes aim to improve test coverage, ensure reliability, and modernize code style.

Unit tests for core components:

  • Added extensive tests for the options classes (e.g., InputOptions, ConfirmOptions, PasswordOptions, SelectOptions, ListOptions, MultiSelectOptions) to verify correct validation logic and error handling in various scenarios.
  • Introduced tests for the paginator, covering navigation (next/previous item and page), filtering, selection, page size changes, and looping behavior.
  • Added tests for the Optional<T> struct to verify its value semantics and creation logic.
  • Added tests for the fluent API extension methods on options classes, ensuring that chaining and property setting work as intended.
  • Introduced tests for registry classes (EnumMetadataRegistry, ModelBinderRegistry) to verify registration and retrieval behavior. [1] [2]
  • Added tests for the PromptCanceledException class to ensure constructors and properties behave as expected.

Code style improvements:

  • Updated the initialization of the Validators property in PropertyMetadata to use the modern collection initializer syntax ([] instead of new()).

Test refactoring:

  • Refactored the MoveToPreviousWord test in TextInputBufferTests to use a helper method for buffer initialization, improving readability and maintainability.

@shibayan shibayan requested a review from Copilot February 27, 2026 08:24
@shibayan shibayan self-assigned this Feb 27, 2026
@shibayan shibayan added the enhancement New feature or request label Feb 27, 2026
Copy link

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

Adds a broad set of new unit tests across Sharprompt’s core validation/options and internal utilities, plus a couple of small modernization/style tweaks (collection expressions) and a minor test refactor.

Changes:

  • Added new test suites for validators, options validation, fluent extensions, registries, paginator behavior, optional/value helpers, and PromptCanceledException.
  • Refactored TextInputBufferTests to reuse a helper for cursor-position setup and added a few additional buffer behavior tests.
  • Updated a couple of collection initializations to modern C# collection expression syntax.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
Sharprompt/Internal/OffscreenBuffer.cs Uses collection expressions for initializing the output buffer.
Sharprompt.SourceGenerator/PromptBindableGenerator.cs Modernizes Validators list initialization in generator metadata.
Sharprompt.Tests/ValidatorsTests.cs Adds unit tests for Validators behaviors.
Sharprompt.Tests/ValidatorsExtensionsTests.cs Adds tests for internal validators list merge helper.
Sharprompt.Tests/TypeHelperTests.cs Adds tests for nullability detection and invariant conversions.
Sharprompt.Tests/TextInputBufferTests.cs Refactors buffer setup and adds coverage for Clear, MoveToStart, MoveToEnd.
Sharprompt.Tests/PromptCanceledExceptionTests.cs Adds constructor/property tests for PromptCanceledException.
Sharprompt.Tests/PaginatorTests.cs Adds extensive paginator navigation/filtering/page-size tests.
Sharprompt.Tests/OptionsTests.cs Adds EnsureOptions validation tests for option types.
Sharprompt.Tests/OptionalTests.cs Adds tests for Optional<T> semantics and factory methods.
Sharprompt.Tests/ModelBinderRegistryTests.cs Adds tests for registering and retrieving model binders.
Sharprompt.Tests/FluentExtensionsTests.cs Adds tests for fluent options extension methods/chaining.
Sharprompt.Tests/EnumMetadataRegistryTests.cs Adds tests for enum metadata registration and retrieval.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shibayan shibayan merged commit b9a9e4d into master Feb 27, 2026
5 checks passed
@shibayan shibayan deleted the add-test-case branch February 27, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants