|
| 1 | +import Core |
| 2 | +import Foundation |
| 3 | +import KanaKanjiConverterModule |
| 4 | +import Testing |
| 5 | + |
| 6 | +private let spaceEvent = KeyEventCore( |
| 7 | + modifierFlags: [], |
| 8 | + characters: " ", |
| 9 | + charactersIgnoringModifiers: " ", |
| 10 | + keyCode: 49 |
| 11 | +) |
| 12 | + |
| 13 | +@Suite("InputState space key behavior in composing state") |
| 14 | +struct InputStateSpaceTests { |
| 15 | + @Test func spaceInEnglishComposingAppendsSpace() { |
| 16 | + let (action, _) = InputState.composing.event( |
| 17 | + eventCore: spaceEvent, |
| 18 | + userAction: .space(prefersFullWidthWhenInput: false), |
| 19 | + inputLanguage: .english, |
| 20 | + liveConversionEnabled: false, |
| 21 | + enableDebugWindow: false, |
| 22 | + enableSuggestion: false |
| 23 | + ) |
| 24 | + guard case .appendToMarkedText(let text) = action else { |
| 25 | + Issue.record("Expected appendToMarkedText, got \(action)") |
| 26 | + return |
| 27 | + } |
| 28 | + #expect(text == " ") |
| 29 | + } |
| 30 | + |
| 31 | + @Test func spaceInEnglishComposingAppendsSpaceEvenWithLiveConversion() { |
| 32 | + let (action, _) = InputState.composing.event( |
| 33 | + eventCore: spaceEvent, |
| 34 | + userAction: .space(prefersFullWidthWhenInput: false), |
| 35 | + inputLanguage: .english, |
| 36 | + liveConversionEnabled: true, |
| 37 | + enableDebugWindow: false, |
| 38 | + enableSuggestion: false |
| 39 | + ) |
| 40 | + guard case .appendToMarkedText(let text) = action else { |
| 41 | + Issue.record("Expected appendToMarkedText, got \(action)") |
| 42 | + return |
| 43 | + } |
| 44 | + #expect(text == " ") |
| 45 | + } |
| 46 | + |
| 47 | + @Test func spaceInJapaneseComposingWithLiveConversionEntersCandidateSelection() { |
| 48 | + let (action, callback) = InputState.composing.event( |
| 49 | + eventCore: spaceEvent, |
| 50 | + userAction: .space(prefersFullWidthWhenInput: false), |
| 51 | + inputLanguage: .japanese, |
| 52 | + liveConversionEnabled: true, |
| 53 | + enableDebugWindow: false, |
| 54 | + enableSuggestion: false |
| 55 | + ) |
| 56 | + guard case .enterCandidateSelectionMode = action else { |
| 57 | + Issue.record("Expected enterCandidateSelectionMode, got \(action)") |
| 58 | + return |
| 59 | + } |
| 60 | + guard case .transition(.selecting) = callback else { |
| 61 | + Issue.record("Expected transition(.selecting), got \(callback)") |
| 62 | + return |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @Test func spaceInJapaneseComposingWithoutLiveConversionEntersPreview() { |
| 67 | + let (action, callback) = InputState.composing.event( |
| 68 | + eventCore: spaceEvent, |
| 69 | + userAction: .space(prefersFullWidthWhenInput: false), |
| 70 | + inputLanguage: .japanese, |
| 71 | + liveConversionEnabled: false, |
| 72 | + enableDebugWindow: false, |
| 73 | + enableSuggestion: false |
| 74 | + ) |
| 75 | + guard case .enterFirstCandidatePreviewMode = action else { |
| 76 | + Issue.record("Expected enterFirstCandidatePreviewMode, got \(action)") |
| 77 | + return |
| 78 | + } |
| 79 | + guard case .transition(.previewing) = callback else { |
| 80 | + Issue.record("Expected transition(.previewing), got \(callback)") |
| 81 | + return |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments