Skip to content

Conversation

@tig
Copy link
Collaborator

@tig tig commented Nov 12, 2025

Summary

This PR adds comprehensive parallelizable unit tests for WindowsKeyConverter to ensure proper keyboard input conversion between Windows native InputRecord format and Terminal.Gui's Key representation.

Changes

  • Added 118 parallelizable unit tests in Tests/UnitTestsParallelizable/Drivers/WindowsKeyConverterTests.cs
  • Comprehensive coverage of ToKey and ToKeyInfo methods
  • Full bidirectional conversion testing with round-trip validation
  • Tests for all key categories including edge cases

Test Coverage

Test Categories (118 tests total)

  1. ToKey Tests - Basic Characters (7 tests)

    • Letter keys (A-Z) with and without Shift
    • Number keys (0-9)
  2. ToKey Tests - Modifiers (5 tests)

    • Ctrl, Alt, Shift combinations
    • Multiple modifier combinations (Ctrl+Alt, Ctrl+Shift+Alt, etc.)
  3. ToKey Tests - Special Keys (26 tests)

    • Navigation keys (Enter, Esc, Tab, Backspace, Delete, Insert, Home, End, PageUp/PageDown)
    • Arrow keys (Up, Down, Left, Right)
    • Function keys (F1-F12)
  4. ToKey Tests - VK_PACKET (Unicode/IME) (7 tests)

    • International characters (Chinese, Japanese, Korean, Greek)
    • Accented characters (é, etc.)
    • Special symbols (€, etc.)
    • Null character handling
  5. ToKey Tests - OEM Keys (12 tests)

    • Keyboard layout-specific keys (semicolon, slash, comma, period, plus, minus)
    • Shifted and unshifted variations
    • US keyboard layout mappings
  6. ToKey Tests - NumPad (9 tests)

    • NumPad number keys (NumPad0-9)
    • NumPad operators (*, +, -, ., /)
  7. ToKey Tests - Null/Empty (1 test)

    • Null key handling
  8. ToKeyInfo Tests - Basic Keys (7 tests)

    • Letter and number keys reverse conversion
    • EventType, VirtualKeyCode, UnicodeChar, KeyDown, RepeatCount validation
  9. ToKeyInfo Tests - Special Keys (15 tests)

    • Special character keys with proper unicode chars
    • Navigation keys
    • Function keys
  10. ToKeyInfo Tests - Modifiers (5 tests)

    • ControlKeyState verification for all modifier combinations
    • ShiftPressed, LeftControlPressed, LeftAltPressed flags
  11. ToKeyInfo Tests - Scan Codes (8 tests)

    • Hardware scan code generation validation
    • Common keys (A, Enter, Esc, Space, F1, F10, CursorUp, Home)
  12. Round-Trip Tests (13 tests)

    • ToKey → ToKeyInfo → ToKey preservation
    • ToKeyInfo → ToKey → ToKeyInfo preservation
    • Modifier state preservation validation
  13. CapsLock/NumLock Tests (2 tests)

    • CapsLock state handling
    • Lock state interaction with Shift key

Test Results

All 118 tests passing successfully:

tig added 3 commits November 12, 2025 09:04
- 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
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.55%. Comparing base (0995148) to head (77e2050).

Additional details and impacted files
@@              Coverage Diff               @@
##           v2_develop    #4390      +/-   ##
==============================================
- Coverage       74.56%   74.55%   -0.01%     
==============================================
  Files             388      388              
  Lines           46568    46568              
  Branches         6548     6548              
==============================================
- Hits            34723    34721       -2     
- Misses           9993     9996       +3     
+ Partials         1852     1851       -1     
Files with missing lines Coverage Δ
Terminal.Gui/App/ApplicationImpl.cs 92.30% <ø> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0995148...77e2050. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot finished reviewing on behalf of tig November 12, 2025 19:40
Copy link
Contributor

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

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 ToKey and ToKeyInfo conversion methods
  • Full bidirectional round-trip conversion validation

tig added 5 commits November 12, 2025 12:48
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.
@tig tig force-pushed the feature/windowskeyconverter-tests branch from 43b0373 to 8ebf25a Compare November 12, 2025 20:26
tig added 3 commits November 12, 2025 15:03
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant