mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* iOS keyboard: key haptics are the same in every layout, and stay on while the keyboard records A TestFlight tester on build 37 felt no key haptics with the Portuguese layout added in #2069. The haptic path was traced for every layout (en, nb, es, de, it, fr, pt) and none of it depends on the language. Every key going down calls FullKeyboardView.keyFeedback through KeyboardKeyPlaneView.onKeyDown, accent and trackpad steps call selectionFeedback, and both are gated only by KeyboardViewController.allowsKeyHaptics (Full Access and Settings > Keyboard > Haptics). Layouts only change the letter rows, accent lists and the spelling dictionary. So the cause is the tester's setup or state, not the layout. Two things silence the taps with no code path to see them: - Without Full Access iOS plays no keyboard haptics. Since #2067 the keyboard types without Full Access, so a tester can type in any layout while Haptics shows On and feel nothing. - In-keyboard dictation sets this process's audio session to record (WebKit captures for it), and iOS mutes a recording session's haptics and system sounds by default. The keyboard now calls setAllowHapticsAndSystemSoundsDuringRecording(true) once in viewDidLoad. Verified on an iOS 27.2 iPhone 17 Pro simulator (Mac Studio): the full HEXMobileTests suite passes (278 tests, 0 failures, 1 skipped as before). The new testEveryLayoutAsksForTheSameKeyHaptics drives a letter, space, delete and an accent step through the real FullKeyboardView in each of the seven layouts and gets the same haptic requests in every one. A live Hex keyboard (Full Access granted) with Settings > Keyboard layout set to Portuguese showed Portuguese accents and the "olá" suggestion. A temporary log line, not committed, showed the haptic call firing with haptics allowed for each key and accent step. The Taptic output and the recording-session mute need a physical iPhone. * iOS keyboard: hold delete and slide left to delete word by word A TestFlight tester asked for the delete swipe from Apple's keyboard. - New DeleteWordSwipe (HEXShared/FullKeyboard): once a finger that went down on delete is a key width (layout.letterWidth) left of where it started, each further key width deletes one more word. Sliding back right types back the words this gesture deleted, newest first. Lifting, or a cancelled touch, keeps the result. - Words are counted as Option-Delete does: spaces and punctuation before the cursor go with the word in front of them ("one two, three. four" loses "four", "three. ", "two, "), apostrophes stay inside words ("don't"), and text that is only spaces and punctuation goes in one step. - KeyboardKeyPlaneView starts a DeleteWordSwipe with each delete press, feeds it moves, and stops hold-to-repeat once the swipe is active. A tap, a still hold, or a hold that drifts less than a key width behaves as before. - Each word deleted or restored ticks the selection haptic (gated by allowsHaptics, as the accent and trackpad ticks are). Edits go through the text proxy only (deleteBackward and insertText) and show in typing logs as delete_word / insert with src delete_swipe(_restore). Nothing new in Settings. Not done: Learn how I type's journal isn't told about words a swipe erases. Verified on an iOS 27.2 iPhone 17 Pro simulator (Mac Studio): the full HEXMobileTests suite passes (278 tests, 0 failures, 1 skipped as before), including new FullKeyboardEngineTests cases for step-by-step deletion, a tick per word, restore on slide back, commit on lift, the start of the text, and the word rule. In a live Hex keyboard in a text field ("Running 10 min late, "), driven with AXe, the swipe went to 1, 2 and 3 words deleted, sliding back restored two, and lifting kept "Running 10 ". A 1 s hold with no slide and a hold with an 18 pt drift only repeated, as before.
461 lines
19 KiB
Swift
461 lines
19 KiB
Swift
import UIKit
|
|
import XCTest
|
|
@testable import HEX
|
|
|
|
@MainActor
|
|
final class FullKeyboardEngineTests: XCTestCase {
|
|
private var target: FixtureTextTarget!
|
|
private var engine: FullKeyboardEngine!
|
|
private var now: TimeInterval = 100
|
|
private var suiteName: String!
|
|
private var defaults: UserDefaults!
|
|
|
|
override func setUp() async throws {
|
|
suiteName = "FullKeyboardEngineTests-\(UUID().uuidString)"
|
|
defaults = UserDefaults(suiteName: suiteName)!
|
|
target = FixtureTextTarget()
|
|
target.autocapitalizationType = UITextAutocapitalizationType.none
|
|
let ac = AutocorrectEngine(learnedWords: LearnedWordsStore(defaults: defaults))
|
|
engine = FullKeyboardEngine(target: target, autocorrect: ac)
|
|
engine.width = 393
|
|
engine.clock = { [unowned self] in self.now }
|
|
engine.configureForField()
|
|
}
|
|
|
|
override func tearDown() async throws {
|
|
defaults.removePersistentDomain(forName: suiteName)
|
|
}
|
|
|
|
private func point(_ kind: KeyKind) -> CGPoint {
|
|
let key = engine.layout.key(kind)!
|
|
return CGPoint(x: key.frame.midX, y: key.frame.midY)
|
|
}
|
|
|
|
private func down(_ id: Int, _ kind: KeyKind) { engine.touchBegan(id: id, at: point(kind)) }
|
|
private func up(_ id: Int, _ kind: KeyKind) { engine.touchEnded(id: id, at: point(kind)) }
|
|
|
|
private func tap(_ kind: KeyKind) {
|
|
let at = point(kind)
|
|
engine.touchBegan(id: 1, at: at)
|
|
engine.touchEnded(id: 1, at: at)
|
|
}
|
|
|
|
private func type(_ text: String) {
|
|
for ch in text {
|
|
tap(ch == " " ? .space : .character(String(ch)))
|
|
now += 0.5
|
|
}
|
|
}
|
|
|
|
func testRolloverKeepsOrder() {
|
|
down(1, .character("t"))
|
|
down(2, .character("h"))
|
|
up(1, .character("t"))
|
|
up(2, .character("h"))
|
|
XCTAssertEqual(target.text, "th")
|
|
}
|
|
|
|
func testRolloverWhenTheSecondKeyLiftsFirst() {
|
|
down(1, .character("t"))
|
|
down(2, .character("h"))
|
|
up(2, .character("h"))
|
|
up(1, .character("t"))
|
|
XCTAssertEqual(target.text, "th")
|
|
}
|
|
|
|
func testSlidingToAnotherKeyTypesWhereTheFingerLifts() {
|
|
down(1, .character("f"))
|
|
engine.touchMoved(id: 1, to: point(.character("g")))
|
|
XCTAssertEqual(engine.previewKey?.kind, .character("g"))
|
|
up(1, .character("g"))
|
|
XCTAssertEqual(target.text, "g")
|
|
}
|
|
|
|
func testShiftChordAndOneShot() {
|
|
down(1, .shift)
|
|
down(2, .character("a"))
|
|
up(2, .character("a"))
|
|
down(3, .character("b"))
|
|
up(3, .character("b"))
|
|
up(1, .shift)
|
|
tap(.character("c"))
|
|
XCTAssertEqual(target.text, "ABc")
|
|
|
|
tap(.shift)
|
|
tap(.character("d"))
|
|
tap(.character("e"))
|
|
XCTAssertEqual(target.text, "ABcDe")
|
|
}
|
|
|
|
func testDoubleTapShiftLocks() {
|
|
tap(.shift)
|
|
now += 0.1
|
|
tap(.shift)
|
|
type("hi")
|
|
XCTAssertEqual(target.text, "HI")
|
|
XCTAssertEqual(engine.shift.state, .locked)
|
|
}
|
|
|
|
func testHoldNumbersSlideToADigitAndLetGo() {
|
|
down(1, .layerSwitch(.numbers))
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
engine.touchMoved(id: 1, to: point(.character("7")))
|
|
engine.touchEnded(id: 1, at: point(.character("7")))
|
|
XCTAssertEqual(target.text, "7")
|
|
XCTAssertEqual(engine.layout.layer, .letters)
|
|
}
|
|
|
|
func testNumbersStayUntilSpace() {
|
|
tap(.layerSwitch(.numbers))
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
tap(.character("4"))
|
|
tap(.character("2"))
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
tap(.space)
|
|
XCTAssertEqual(engine.layout.layer, .letters)
|
|
XCTAssertEqual(target.text, "42 ")
|
|
}
|
|
|
|
func testDoubleSpaceTypesAPeriod() {
|
|
type("ok")
|
|
tap(.space)
|
|
now += 0.2
|
|
tap(.space)
|
|
XCTAssertEqual(target.text, "ok. ")
|
|
now += 0.2
|
|
tap(.space)
|
|
XCTAssertEqual(target.text, "ok. ", "a third space is just a space")
|
|
}
|
|
|
|
func testSlowDoubleSpaceStaysTwoSpaces() {
|
|
type("ok")
|
|
tap(.space)
|
|
now += 0.5
|
|
tap(.space)
|
|
XCTAssertEqual(target.text, "ok ")
|
|
}
|
|
|
|
func testSentenceAutoCapitalization() {
|
|
target.autocapitalizationType = .sentences
|
|
engine.configureForField()
|
|
XCTAssertEqual(engine.shift.state, .on)
|
|
type("hi")
|
|
tap(.space)
|
|
now += 0.2
|
|
tap(.space)
|
|
type("there")
|
|
XCTAssertEqual(target.text, "Hi. There")
|
|
}
|
|
|
|
func testAcceleratingDeleteRampAndWordDelete() {
|
|
type("hello world")
|
|
down(1, .delete)
|
|
XCTAssertEqual(target.text, "hello worl")
|
|
// Initial repeat deletes 1 char.
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.repeatDelay)
|
|
XCTAssertEqual(target.text, "hello wor")
|
|
// Accelerated repeat deletes 2 chars per tick.
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.fastRepeatAfter)
|
|
XCTAssertEqual(target.text, "hello w")
|
|
// After 1.4 s, removes whole words backward.
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.wordDeleteAfter)
|
|
XCTAssertEqual(target.text, "hello ")
|
|
engine.repeatDelete(heldFor: FullKeyboardEngine.wordDeleteAfter)
|
|
XCTAssertEqual(target.text, "")
|
|
up(1, .delete)
|
|
}
|
|
|
|
func testLongPressAccentPickerSelectsAndUppercaseWorks() {
|
|
tap(.shift)
|
|
down(1, .character("e"))
|
|
XCTAssertTrue(engine.openAccentMenuIfEligible(forTouch: 1))
|
|
let menu = try! XCTUnwrap(engine.activeAccentMenu)
|
|
XCTAssertNil(engine.previewKey, "single-key balloon hides while accent picker is open")
|
|
XCTAssertEqual(menu.options.first, "E")
|
|
// Slide to index 2 ("É").
|
|
let cell = menu.cellFrames[2]
|
|
engine.touchMoved(id: 1, to: CGPoint(x: cell.midX, y: cell.midY))
|
|
engine.touchEnded(id: 1, at: CGPoint(x: cell.midX, y: cell.midY))
|
|
XCTAssertNil(engine.activeAccentMenu)
|
|
XCTAssertEqual(target.text, "É")
|
|
XCTAssertEqual(engine.shift.state, .off)
|
|
}
|
|
|
|
func testSpacebarTrackpadMovesCaretWithoutInsertingSpace() {
|
|
type("helo")
|
|
let spaceStart = point(.space)
|
|
engine.touchBegan(id: 1, at: spaceStart)
|
|
// Enter trackpad mode (-12 pt) then drag left by 16 pt (-2 chars: before "lo").
|
|
let enterPoint = CGPoint(x: spaceStart.x - 12, y: spaceStart.y)
|
|
engine.touchMoved(id: 1, to: enterPoint)
|
|
XCTAssertTrue(engine.isTrackpadActive)
|
|
engine.touchMoved(id: 1, to: CGPoint(x: enterPoint.x - 16, y: spaceStart.y))
|
|
engine.touchEnded(id: 1, at: CGPoint(x: enterPoint.x - 16, y: spaceStart.y))
|
|
XCTAssertFalse(engine.isTrackpadActive)
|
|
XCTAssertEqual(target.cursorIndex, 2)
|
|
tap(.character("l"))
|
|
XCTAssertEqual(target.text, "hello")
|
|
}
|
|
|
|
func testEnablesReturnKeyAutomaticallyBlocksEmptyField() {
|
|
target.enablesReturnKeyAutomatically = true
|
|
tap(.returnKey)
|
|
XCTAssertEqual(target.text, "")
|
|
type("ok")
|
|
tap(.returnKey)
|
|
XCTAssertEqual(target.text, "ok\n")
|
|
}
|
|
|
|
func testRecordingPanelAllocatesLazilyAndTearsDownOnIdle() {
|
|
let model = KeyboardViewModel()
|
|
let view = FullKeyboardView(model: model, target: target)
|
|
view.frame = CGRect(x: 0, y: 0, width: 393, height: 254)
|
|
view.layoutIfNeeded()
|
|
XCTAssertFalse(view.hasAllocatedRecordingPanel, "no Metal scope allocated while typing")
|
|
|
|
let t: TimeInterval = 1_000
|
|
model.applyBridgeState(
|
|
hasFullAccess: true,
|
|
snapshot: KeyboardSnapshot(state: .recording, heartbeat: t, expiresAt: t + 60, recordingStartedAt: t - 1, jobID: "j1"),
|
|
isModelInstalled: true,
|
|
style: .polished,
|
|
now: t,
|
|
clearPending: false,
|
|
animated: false
|
|
)
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertTrue(view.hasAllocatedRecordingPanel)
|
|
|
|
model.applyBridgeState(
|
|
hasFullAccess: true,
|
|
snapshot: KeyboardSnapshot(state: .ready, heartbeat: t + 1, expiresAt: t + 60),
|
|
isModelInstalled: true,
|
|
style: .polished,
|
|
now: t + 1,
|
|
clearPending: true,
|
|
animated: false
|
|
)
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertFalse(view.hasAllocatedRecordingPanel, "Metal scope torn down once recording ends")
|
|
}
|
|
|
|
/// iOS 26 blurs scroll views' edges inside a keyboard; on the emoji panel's 44 pt rows
|
|
/// that blurred every emoji (TestFlight build 32). Every scroll view in the panel and
|
|
/// the search hides all four edge effects.
|
|
func testEmojiPanelScrollViewsHideTheirEdgeEffects() throws {
|
|
guard #available(iOS 26.0, *) else { throw XCTSkip("edge effects arrived in iOS 26") }
|
|
let view = FullKeyboardView(model: KeyboardViewModel(), target: target)
|
|
view.emojiOverride = true
|
|
let defaults = UserDefaults(suiteName: "anomaly.hex.tests.emoji-panel")
|
|
defaults?.removePersistentDomain(forName: "anomaly.hex.tests.emoji-panel")
|
|
view.makeEmojiUsage = { EmojiUsageStore(defaults: defaults) }
|
|
view.frame = CGRect(x: 0, y: 0, width: 402, height: 306)
|
|
view.layoutIfNeeded()
|
|
view.debugOpenEmoji(search: "piz")
|
|
view.layoutIfNeeded()
|
|
|
|
func scrollViews(in root: UIView) -> [UIScrollView] {
|
|
root.subviews.flatMap { child -> [UIScrollView] in
|
|
if let scrollView = child as? UIScrollView { return [scrollView] }
|
|
return scrollViews(in: child)
|
|
}
|
|
}
|
|
let found = scrollViews(in: view)
|
|
XCTAssertEqual(found.count, 3, "the grid, the suggestion row and the search results")
|
|
for scrollView in found {
|
|
for edge in [scrollView.topEdgeEffect, scrollView.bottomEdgeEffect, scrollView.leftEdgeEffect, scrollView.rightEdgeEffect] {
|
|
XCTAssertTrue(edge.isHidden, "\(Swift.type(of: scrollView)) at \(scrollView.frame)")
|
|
}
|
|
}
|
|
defaults?.removePersistentDomain(forName: "anomaly.hex.tests.emoji-panel")
|
|
}
|
|
|
|
func testSpaceBarNamesTheDictationLanguage() {
|
|
let model = KeyboardViewModel()
|
|
let view = FullKeyboardView(model: model, target: target)
|
|
view.frame = CGRect(x: 0, y: 0, width: 393, height: 262)
|
|
view.layoutIfNeeded()
|
|
XCTAssertNil(view.plane.spaceLabel, "no label until the language is known")
|
|
|
|
model.automaticLanguage = "en-US"
|
|
model.languageChoices = ["nb-NO", "en-US"]
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertEqual(view.plane.spaceLabel, "English")
|
|
|
|
model.dictationLanguage = "nb-NO"
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertEqual(view.plane.spaceLabel, "Norsk")
|
|
|
|
model.dictationLanguage = "ru-RU"
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertEqual(view.plane.spaceLabel, "Русский")
|
|
|
|
model.hasFullAccess = false
|
|
RunLoop.main.run(until: Date().addingTimeInterval(0.05))
|
|
XCTAssertNil(view.plane.spaceLabel, "without Full Access the keyboard can't dictate")
|
|
}
|
|
|
|
func testTypesOnTheNorwegianLayout() {
|
|
engine.language = .norwegian
|
|
XCTAssertNotNil(engine.layout.key(.character("å")))
|
|
XCTAssertEqual(engine.autocorrect.language, .norwegian)
|
|
tap(.shift)
|
|
tap(.character("ø"))
|
|
tap(.character("l"))
|
|
XCTAssertEqual(target.text, "Øl")
|
|
|
|
let o = engine.layout.key(.character("ø"))!
|
|
engine.touchBegan(id: 7, at: CGPoint(x: o.frame.midX, y: o.frame.midY))
|
|
XCTAssertTrue(engine.openAccentMenuIfEligible(forTouch: 7))
|
|
XCTAssertEqual(Set(engine.activeAccentMenu?.options ?? []), ["ø", "ö"])
|
|
engine.touchCancelled(id: 7)
|
|
|
|
engine.language = .german
|
|
XCTAssertNil(engine.layout.key(.character("å")))
|
|
XCTAssertNotNil(engine.layout.key(.character("ü")))
|
|
}
|
|
|
|
/// Spatial autocorrect has English and Spanish models only: Italian falls back to the
|
|
/// dictionary engine in Italian, never to the English model.
|
|
func testSpatialAutocorrectNeverUsesAnotherLanguagesModel() {
|
|
let settings = FullKeyboardSettings()
|
|
let wasOn = settings.spatialAutocorrect
|
|
settings.spatialAutocorrect = true
|
|
defer { settings.spatialAutocorrect = wasOn }
|
|
let view = FullKeyboardView(model: KeyboardViewModel(), target: target)
|
|
view.languageOverride = .spanish
|
|
XCTAssertEqual(view.engine.autocorrect.decoder?.model.language, "es")
|
|
view.languageOverride = .italian
|
|
XCTAssertEqual(view.engine.autocorrect.language, .italian)
|
|
XCTAssertNil(view.engine.autocorrect.decoder)
|
|
// Nor do Russian and Serbian (Latin).
|
|
for language in [KeyboardLanguage.russian, .serbianLatin] {
|
|
view.languageOverride = language
|
|
XCTAssertEqual(view.engine.autocorrect.language, language)
|
|
XCTAssertNil(view.engine.autocorrect.decoder, "\(language)")
|
|
}
|
|
view.languageOverride = .english
|
|
XCTAssertEqual(view.engine.autocorrect.decoder?.model.language, "en")
|
|
}
|
|
|
|
func testEmailFieldShowsAtAndDot() {
|
|
target.keyboardType = .emailAddress
|
|
engine.configureForField()
|
|
tap(.character("@"))
|
|
tap(.character("."))
|
|
XCTAssertEqual(target.text, "@.")
|
|
}
|
|
|
|
func testNumberPadOpensOnNumbers() {
|
|
target.keyboardType = .numberPad
|
|
engine.configureForField()
|
|
XCTAssertEqual(engine.layout.layer, .numbers)
|
|
}
|
|
|
|
// MARK: - Haptics in every layout
|
|
|
|
/// Key haptics come from the same calls whatever the layout (a TestFlight tester felt
|
|
/// none on the Portuguese one): every layout asks for a tap per key going down and a tick
|
|
/// per accent step, the same number of times.
|
|
func testEveryLayoutAsksForTheSameKeyHaptics() {
|
|
var counts: [KeyboardLanguage: Int] = [:]
|
|
for language in KeyboardLanguage.allCases {
|
|
let view = FullKeyboardView(model: KeyboardViewModel(), target: FixtureTextTarget())
|
|
view.languageOverride = language
|
|
view.frame = CGRect(x: 0, y: 0, width: 393, height: 262)
|
|
view.layoutIfNeeded()
|
|
var asked = 0
|
|
view.allowsHaptics = {
|
|
asked += 1
|
|
return true
|
|
}
|
|
for (id, kind) in [KeyKind.character("a"), .space, .delete].enumerated() {
|
|
let key = view.engine.layout.key(kind)!
|
|
let sample = TypingLogTouchSample(point: CGPoint(x: key.frame.midX, y: key.frame.midY), timestamp: 0)
|
|
view.plane.began(id: id + 10, sample: sample)
|
|
view.plane.ended(id: id + 10, sample: sample)
|
|
}
|
|
view.debugHoldAccent("e", selectIndex: 1)
|
|
counts[language] = asked
|
|
}
|
|
XCTAssertGreaterThanOrEqual(counts[.english] ?? 0, 4, "three keys and an accent step")
|
|
for language in KeyboardLanguage.allCases {
|
|
XCTAssertEqual(counts[language], counts[.english], "\(language.rawValue) haptics")
|
|
}
|
|
}
|
|
|
|
// MARK: - Delete swipe
|
|
|
|
private func swipeEngine(_ text: String) -> (FixtureTextTarget, FullKeyboardEngine) {
|
|
let field = FixtureTextTarget(text: text)
|
|
field.autocapitalizationType = UITextAutocapitalizationType.none
|
|
let keys = FullKeyboardEngine(
|
|
target: field,
|
|
autocorrect: AutocorrectEngine(learnedWords: LearnedWordsStore(defaults: defaults))
|
|
)
|
|
keys.width = 393
|
|
keys.configureForField()
|
|
return (field, keys)
|
|
}
|
|
|
|
private func deleteSample(_ keys: FullKeyboardEngine, dx: CGFloat = 0) -> TypingLogTouchSample {
|
|
let key = keys.layout.key(.delete)!
|
|
return TypingLogTouchSample(point: CGPoint(x: key.frame.midX + dx, y: key.frame.midY), timestamp: 0)
|
|
}
|
|
|
|
func testDeleteSwipeDeletesWordByWordRestoresAndCommitsOnLift() {
|
|
let (field, keys) = swipeEngine("one two, three. four")
|
|
let plane = KeyboardKeyPlaneView(engine: keys)
|
|
var ticks = 0
|
|
keys.onSelectionStep = { ticks += 1 }
|
|
let step = keys.layout.letterWidth
|
|
|
|
plane.began(id: 1, sample: deleteSample(keys))
|
|
XCTAssertEqual(field.text, "one two, three. fou", "going down deletes a letter, as a tap does")
|
|
plane.moved(id: 1, sample: deleteSample(keys, dx: -step * 0.6))
|
|
XCTAssertEqual(field.text, "one two, three. fou", "less than a key width deletes nothing more")
|
|
XCTAssertEqual(plane.deleteSwipe?.isActive, false)
|
|
|
|
plane.moved(id: 1, sample: deleteSample(keys, dx: -step * 1.2))
|
|
XCTAssertEqual(field.text, "one two, three. ")
|
|
plane.moved(id: 1, sample: deleteSample(keys, dx: -step * 2.2))
|
|
XCTAssertEqual(field.text, "one two, ", "punctuation and spaces go with the word before them")
|
|
plane.moved(id: 1, sample: deleteSample(keys, dx: -step * 3.2))
|
|
XCTAssertEqual(field.text, "one ")
|
|
XCTAssertEqual(ticks, 3, "a tick per word")
|
|
|
|
plane.moved(id: 1, sample: deleteSample(keys, dx: -step * 1.5))
|
|
XCTAssertEqual(field.text, "one two, three. ", "sliding back types the words back")
|
|
XCTAssertEqual(ticks, 5)
|
|
|
|
plane.ended(id: 1, sample: deleteSample(keys, dx: -step * 1.5))
|
|
XCTAssertEqual(field.text, "one two, three. ", "lifting keeps what is deleted")
|
|
XCTAssertNil(plane.deleteSwipe)
|
|
|
|
plane.began(id: 2, sample: deleteSample(keys))
|
|
plane.ended(id: 2, sample: deleteSample(keys))
|
|
XCTAssertEqual(field.text, "one two, three.", "a tap after it deletes one character")
|
|
}
|
|
|
|
func testDeleteSwipeStopsAtTheStartAndRestoresOnlyItsWords() {
|
|
let (field, keys) = swipeEngine("hi there")
|
|
let plane = KeyboardKeyPlaneView(engine: keys)
|
|
let step = keys.layout.letterWidth
|
|
plane.began(id: 1, sample: deleteSample(keys))
|
|
plane.moved(id: 1, sample: deleteSample(keys, dx: -step * 6))
|
|
XCTAssertEqual(field.text, "")
|
|
plane.moved(id: 1, sample: deleteSample(keys))
|
|
XCTAssertEqual(field.text, "hi ther", "the letter the press deleted stays deleted")
|
|
plane.cancelled(id: 1, sample: deleteSample(keys))
|
|
XCTAssertEqual(field.text, "hi ther")
|
|
}
|
|
|
|
func testDeleteSwipeWordsMatchOptionDelete() {
|
|
XCTAssertNil(DeleteWordSwipe.wordLength(before: ""))
|
|
XCTAssertEqual(DeleteWordSwipe.wordLength(before: "Hello, world. "), 7)
|
|
XCTAssertEqual(DeleteWordSwipe.wordLength(before: "it's don't"), 5)
|
|
XCTAssertEqual(DeleteWordSwipe.wordLength(before: "Olá, você"), 4)
|
|
XCTAssertEqual(DeleteWordSwipe.wordLength(before: "?!"), 2)
|
|
XCTAssertEqual(DeleteWordSwipe.wordLength(before: "line\n"), 5)
|
|
}
|
|
}
|