-
Notifications
You must be signed in to change notification settings - Fork 735
Fixes #4389 - Add comprehensive unit tests for WindowsKeyConverter #4390
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
Fixes #4389 - Add comprehensive unit tests for WindowsKeyConverter #4390
Conversation
- Implement 118 parallelizable unit tests for WindowsKeyConverter - Cover ToKey and ToKeyInfo methods with full bidirectional testing - Test basic characters, modifiers, special keys, function keys - Test VK_PACKET Unicode/IME input - Test OEM keys, NumPad keys, and lock states - Include round-trip conversion tests - All tests passing successfully Fixes gui-cs#4389
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v2_develop #4390 +/- ##
==============================================
+ Coverage 68.64% 74.74% +6.09%
==============================================
Files 388 388
Lines 46692 46690 -2
Branches 6641 6641
==============================================
+ Hits 32052 34898 +2846
+ Misses 12708 9898 -2810
+ Partials 1932 1894 -38
... and 89 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR adds comprehensive unit tests for the WindowsKeyConverter class, which handles bidirectional conversion between Windows native InputRecord format and Terminal.Gui's Key representation. The tests provide extensive coverage with 118 parallelizable test cases covering basic character keys, modifiers, special keys, Unicode/IME input, OEM keys, NumPad keys, function keys, scan codes, round-trip conversions, and lock state handling.
Key Changes:
- Added 118 parallelizable unit tests organized into 13 test categories
- Comprehensive testing of
ToKeyandToKeyInfoconversion methods - Full bidirectional round-trip conversion validation
Tests/UnitTestsParallelizable/Drivers/WindowsKeyConverterTests.cs
Outdated
Show resolved
Hide resolved
Tests/UnitTestsParallelizable/Drivers/WindowsKeyConverterTests.cs
Outdated
Show resolved
Hide resolved
Tests/UnitTestsParallelizable/Drivers/WindowsKeyConverterTests.cs
Outdated
Show resolved
Hide resolved
Tests/UnitTestsParallelizable/Drivers/WindowsKeyConverterTests.cs
Outdated
Show resolved
Hide resolved
VK_PACKET sends surrogate pairs (e.g., emoji) as two separate events. Current WindowsKeyConverter processes each independently without combining. Test documents this limitation for future fix at InputProcessor level.
Tests now skip on non-Windows platforms using SkipException in constructor. This prevents CI failures on macOS and Linux where Windows Console API is not available.
Created custom xUnit attributes SkipOnNonWindowsFact and SkipOnNonWindowsTheory that automatically skip tests on non-Windows platforms. This prevents CI failures on macOS and Linux.
Refactored `ApplicationImpl.cs` to simplify its structure by removing the `_stopAfterFirstIteration` field. Reintroduced and modernized test files with improved structure and coverage: - `NetInputProcessorTests.cs`: Added tests for `ConsoleKeyInfo` to `Rune`/`Key` conversion and queue processing. - `WindowSizeMonitorTests.cs`: Added tests for size change event handling. - `WindowsInputProcessorTests.cs`: Added tests for keyboard and mouse input processing, including mouse flag mapping. - `WindowsKeyConverterTests.cs`: Added comprehensive tests for `InputRecord` to `Key` conversion, covering OEM keys, modifiers, Unicode, and round-trip integrity. Improved test coverage for edge cases, introduced parameterized tests, and documented known limitations for future improvements.
Added [Trait('Platform', 'Windows')] and [Collection('Global Test Setup')] attributes. Tests will run on Windows but can be filtered in CI on other platforms using --filter 'Platform!=Windows' if needed. This approach doesn't interfere with GlobalTestSetup and works correctly with xUnit.
43b0373 to
8ebf25a
Compare
Added --filter 'Platform!=Windows' for Linux and macOS runners to exclude WindowsKeyConverterTests which require Windows Console APIs. Windows runner runs all tests normally.
Corrected a typo in the log directory path from `logs/UnitTestsParallelable/` to `logs/UnitTestsParallelizable/`. Removed the "Upload Parallelizable UnitTests Coverage to Codecov" step, which was conditional on `matrix.os == 'ubuntu-latest'` and used the `codecov/codecov-action@v4` action. This change improves log handling and removes the Codecov integration.
Replaced `Application.ResetState(true)` with a more explicit reset mechanism. Introduced `ApplicationImpl.SetInstance(null)` to clear the application instance and added `CM.Disable(true)` to disable specific components. This change improves control over the reset process and ensures a more granular approach to application state management.
Enhanced null safety across the codebase by introducing the null-conditional operator (`?.`) and null-forgiving operator (`!`) where appropriate. - Updated `app` and `driver` method calls to use `?.` to prevent potential `NullReferenceException` errors. - Added `!` to assert non-nullability in cases like `e.Value!.ToString()` and `app.Driver?.Contents!`. - Modified `lv.SelectedItemChanged` event handler to ensure safe handling of nullable values. - Updated `app.Shutdown()`, `app.LayoutAndDraw()`, and mouse event handling to use `?.`. - Ensured `driver.SetScreenSize` is invoked only when `driver` is not null. - Improved string concatenation logic with null-forgiving operator for `Contents`. - General improvements to null safety to make the code more robust and resilient to null references.
Updated `WindowsKeyConverterTests` to enhance readability, improve test data, and clarify comments. Key changes include: - Reformatted `[Collection]` and `[Trait]` attributes for consistency. - Replaced placeholder Unicode characters with meaningful examples: - Chinese: `中`, Japanese: `日`, Korean: `한`, Accented: `é`, Euro: `€`, Greek: `Ω`. - Updated comments to replace placeholder emojis (`??`) with `😀` (U+1F600) for clarity. - Adjusted surrogate pair test data to accurately reflect `😀`. - Improved documentation of current limitations and future fixes for surrogate pair handling. These changes ensure more accurate and meaningful test cases while improving code clarity.
…Gui into feature/windowskeyconverter-tests
Added `System.Runtime.InteropServices` and `Xunit.Sdk` namespaces to `WindowsKeyConverterTests.cs` to support platform checks and test setup. Marked the test class with `[Collection("Global Test Setup")]` to enable shared test setup. Updated the `ToKey_NumPadKeys_ReturnsExpectedKeyCode` method to include a platform check, ensuring the test only runs on Windows platforms.
Merged TrueColors functionality into ColorPicker, enhancing the scenario with TrueColor demonstration and gradient features. Updated `ColorPicker.cs` to include driver information, TrueColor support indicators, and a toggle for `Force16Colors`. Removed `TrueColors.cs` as its functionality is now consolidated. Refined `ColorBar` to use dynamic height with `Dim.Auto` for better flexibility. Added documentation to `HueBar` to clarify its role in representing the Hue component in HSL color space.
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.
Pull Request Overview
Copilot reviewed 8 out of 11 changed files in this pull request and generated 4 comments.
Tests/UnitTestsParallelizable/Drivers/Windows/WindowsKeyConverterTests.cs
Show resolved
Hide resolved
BDisp
left a comment
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.
That sounds good to me. I might think of a solution to make unit tests pass on non-Windows operating systems as well.
Summary
This PR adds comprehensive parallelizable unit tests for
WindowsKeyConverterto ensure proper keyboard input conversion between Windows nativeInputRecordformat and Terminal.Gui'sKeyrepresentation.Changes
Tests/UnitTestsParallelizable/Drivers/WindowsKeyConverterTests.csToKeyandToKeyInfomethodsTest Coverage
Test Categories (118 tests total)
ToKey Tests - Basic Characters (7 tests)
ToKey Tests - Modifiers (5 tests)
ToKey Tests - Special Keys (26 tests)
ToKey Tests - VK_PACKET (Unicode/IME) (7 tests)
ToKey Tests - OEM Keys (12 tests)
ToKey Tests - NumPad (9 tests)
ToKey Tests - Null/Empty (1 test)
ToKeyInfo Tests - Basic Keys (7 tests)
ToKeyInfo Tests - Special Keys (15 tests)
ToKeyInfo Tests - Modifiers (5 tests)
ToKeyInfo Tests - Scan Codes (8 tests)
Round-Trip Tests (13 tests)
CapsLock/NumLock Tests (2 tests)
Test Results
All 118 tests passing successfully: