hex/ios/HEXMobileTests/KeyboardLayoutTests.swift
Ryan Vogel 52b9e475a6
iOS: the full keyboard's top bar matches the system keyboard (#2135)
* iOS: the full keyboard's top bar matches Apple's predictive bar

Kit's App Store screenshot (dark mode) showed the suggestions sitting low
with a large empty band between the keyboard panel's top edge and the
words. Measured black-box against Apple's English keyboard in the same
Messages field (iOS 27.2 simulator, iPhone 17 Pro, SE 3rd gen, 17 Pro
Max): iOS 26 draws a band of its own above every third-party keyboard
(16.3 pt on the 17 Pro, 12.5 pt on the SE, 13.3 pt on the Pro Max) that
no extension can draw into (checked with a throwaway build drawing at
negative y: the hosted window is exactly the keyboard's height). Hex
then added Apple's whole 44 pt bar and 8 pt gap below it, so its keycaps
started 68 pt below the panel edge where Apple's start 48-52 pt, and its
words sat 38 pt down where Apple's sit 20-24 pt.

What changed:
- The phone strip is the 27 pt of Apple's bar below iOS's band, then the
  same 8 pt gap: row 1 starts 35 pt down (Apple's keycaps are 35.0-35.5 pt
  below the extension's top on all three iPhones), so the panel edge to
  row 1 now measures 51.3 pt against Apple's 51.7 pt on the 17 Pro. The
  keyboard is 253 pt (172 pt landscape) instead of 270 (189); keys do not
  move on screen, only the panel's top edge comes down 17 pt. The Duo
  keeps its 44 pt bar (KeyboardMetrics.insetStripHeight).
- Slots are thirds of the keyboard as Apple's are (dividers end at 134
  and 268 pt on a 402 pt iPhone), with the Hex key's room taken from the
  slot beside it (KeyboardLayout.stripSlotFrames), instead of thirds of
  the strip left of the Hex key. Typing logs record the real slot frames.
- Dividers are Apple's 1 x 24 pt (were 1 px x 22 pt), ending on the
  boundary, in Apple's measured ink.
- Words are Apple's muted ink (dark 0.58 white, light 0.67 black) instead
  of full white/black; the literal word no longer has its own alpha.
- A pending autocorrection is Apple's full-slot capsule with white words
  in regular weight (was a 10 pt-radius pill inset 4 pt, medium weight).
  The capsule is 26 pt tall, not Apple's 38 pt: Apple's top 11 pt falls
  in iOS's band.
- The Hex key, recording bar (Dot Scope well, X and check) and Undo /
  Paste chips use the strip's pill height (26 pt, 4 pt-inset 36 pt on the
  Duo); the Hex mark keeps its 19 pt. The Full Access hint's two lines
  fit 27 pt (13 / 11.5 pt).
- #2100's rule is unchanged: a fast tap on the strip's lower half (below
  its text line, now 13.5 pt down) types the row-1 key below; its tests
  pass as written.

Kept on purpose: words are centred in the 27 pt Hex can draw, about
5.5 pt lower than Apple's relative to the panel edge, so the pill has
room around them; Apple lets long words run past their slot at 17 pt,
Hex still shrinks them to 15 pt and truncates, so nothing runs under
the Hex key. Which suggestions appear (#2125) is untouched.

Verified: xcodebuild test on the iPhone 17 Pro Max simulator, 383 tests,
0 failures, 1 skipped, with updated KeyboardLayoutTests (heights, strip
metrics, row 1 at 35 pt) and a new case for Apple's thirds with the Hex
key on either side. Side-by-side screenshots of Apple's keyboard and
Hex in Messages (empty, typing, literal in quotes, pending correction,
long word, next word) on the 17 Pro and SE in light and dark, and the
recording bar, Full Access hint and Hex key on the left before and after.

* iOS: the top bar's light-mode autocorrection pill matches Apple's

The first pass guessed an opaque white capsule with black words for a
pending autocorrection in light mode. Apple's, measured in Messages on the
iPhone 17 Pro (iOS 27.2 simulator), is a faint white tint, (235,237,240)
on the (226,227,232) platter, under near-black (44,46,49) words; dark mode
was already measured and is unchanged.

Verified: rebuilt and compared the pending-correction state against
Apple's keyboard in the same field in light mode; xcodebuild test.

* iOS: the top bar offers three words in an empty field and between words

Ryan's screenshot of the current build in an empty field (dark mode, shift
on) showed an empty bar with two dividers and nothing in the slots, where
Apple's keyboard shows three sentence starters (I | The | I'm). After a
word, Hex often showed one prediction in the middle with empty slots
beside it, where Apple's fills all three.

- An empty field, and a new sentence (after ". ", "! ", "? " or a new
  line), offers three common first words from a short hand-written list
  per language (the typing model has no start-of-sentence row): English
  I / The / I'm, Spanish Yo / El / La, and so on for every layout,
  Ukrainian included. They take a capital when shift would turn itself on
  (never with Auto-capitalization off; "I" and "I'm" keep theirs), pass
  never-suggest, and are tap-only like #2125's predictions.
- After a word and a space, the model's next words keep #2125's ranking
  for the slots they fill; when it has fewer than three, the language's
  commonest words fill the rest, so no slot stays empty.
- After a comma (or ; : ) ” ’ —) and a space, three words that start a
  clause (English I / but / and). After a handle, a path, a number or a
  second space the bar stays empty, as #2125 had it.
- With Emoji (on by default since #2129) a finished word's emoji no longer
  replaces the predictions: one emoji takes the centre with next words on
  either side ("pizza ": and | 🍕 | hut); two or three fill from the left.
- Picking a starter in an empty field or after a new line inserts it (the
  queued-tap guard now checks that no word was started, not that the text
  ends in a space).

Verified: xcodebuild test on the iPhone 17 Pro simulator (411 tests,
0 failures, 1 skipped), with a new FullKeyboardEngineTests case for the
starters, capitals, the fill and the comma, and #2125's boundary test
updated for ". " and a new line. Held-out tap benchmark (2,000 English
and 2,000 Spanish test sentences, Spatial autocorrect, freshly erased
simulators): finished text is unchanged within the benchmark's own noise
(two runs of the same build differ in 21 English and 32 Spanish sentences,
from the system spell checker); English words broken 528 and 529 before,
528 after, fixed 3,147/3,148 before, 3,147 after; Spanish broken 419/416
before, 417 after, fixed 3,744 before, 3,745 after. Side-by-side shots
against Apple's keyboard in Messages: empty field, after ". ", after
"hi ", after a comma, light and dark, iPhone 17 Pro, SE and 17 Pro Max.

* iOS: the top bar matches Apple's in landscape and on the Duo's cover screen

The 27 pt strip assumed the band iOS draws above a third-party keyboard,
which the iPhone has in portrait. Measured against Apple's keyboard
(iOS 27.2 simulator):

- Landscape (iPhone 17 Pro Max): iOS draws no band, and Apple's keycaps
  start 50 pt below the panel's edge where Hex's started 35 pt down. The
  landscape strip is now 42 pt plus the 8 pt gap (row 1 at 50 pt, keyboard
  187 pt, was 172 pt).
- The Duo folded and upright: the band is 8.7 pt and Apple's keycaps start
  48.7 pt below the edge where Hex's started 52.7 pt down (its 44 pt bar
  sat right on the keys). It is now 32 pt plus the 8 pt gap, so the panel
  edge to row 1 measures 48.7 pt for both. The unfolded postures and the
  cover in landscape keep the 44 pt bar (not measured against the band).
- Pills (an autocorrection, a pressed word, the Hex key, the recording
  bar) are the strip less half a point above and below, at most 36 pt.

Keys do not move on screen; only the panel's top edge does. iPhone
portrait keeps the 27 + 8 pt contract (51.3 pt panel edge to row 1 on
the 17 Pro against Apple's 51.7; 48.67 pt on the 17 Pro Max, the same as
Apple's).

Verified: KeyboardLayoutTests updated for the new heights and metrics;
xcodebuild test (411 tests, 0 failures, 1 skipped); screenshots of the
hosted keyboard next to Apple's in landscape and on the Duo's cover.

* iOS: top-bar dividers, Logging mark and micro-animations follow Apple's

Measured on Apple's keyboard in the iOS 27.2 simulator, recorded at
60 fps with simctl io recordVideo and timed frame by frame:

- A changed word swaps letter by letter: letters the old and new word
  start with stay, the old word's other letters fade from its end and the
  new word's from its start, each in 0.1 s, staggered over 0.2 s (Apple:
  0.14-0.23 s). A word leaving an emptied slot fades the same way. The
  pending-correction capsule and the dividers change at once, as Apple's
  do, and so does a pressed word's capsule on touch down and release.
  Reduce Motion swaps at once. Before, every change was an instant redraw.
- A pressed word gets the same capsule as a pending correction (Apple's
  measured identical: (115,115,115) dark, (235,237,240) light), not a
  lighter one.
- The Undo dictation, Paste and Code from Messages chips and the Full
  Access hint fade in and out over the same 0.2 s instead of popping.
- Dividers are drawn only between two filled slots, so a bar with
  nothing to show (a URL or email field, or a lone "Kq") has none, as
  Apple's has none in secure fields. Apple does draw them beside empty
  slots in URL fields and for a lone literal; Hex doesn't, by request.
- The Logging mark (Record typing logs) sat at the strip's top corner,
  over slot 1's word since the strip became 27 pt ("Logging" overlapped
  "ritsrdo" in the Italian scene). It now sits on the text line at the
  outer end, and that slot centres its word in the room left.

Verified: xcodebuild test (411 tests, 0 failures, 1 skipped); recordings
of Apple's bar and Hex's on the iPhone SE simulator (typing "hello", a
pending correction, a held and released pick, the Paste chip), and
before/after snapshot scenes for the Logging mark on either side.
2026-11-21 03:26:34 +00:00

1016 lines
62 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import CoreGraphics
import XCTest
@testable import HEX
final class KeyboardLayoutTests: XCTestCase {
private let portraitWidths: [CGFloat] = [320, 375, 393, 402, 430, 440]
private let layers: [KeyboardLayer] = [.letters, .numbers, .symbols]
private let fields: [KeyboardFieldKind] = [.text, .url, .email]
private func everyPortraitLayout() -> [KeyboardLayout] {
var layouts: [KeyboardLayout] = []
for width in portraitWidths {
for layer in layers {
for field in fields {
for globe in [false, true] {
layouts.append(KeyboardLayout(width: width, layer: layer, field: field, showsGlobe: globe))
}
}
}
// Only the letters differ between languages.
for language in KeyboardLanguage.allCases where language != .english {
for globe in [false, true] {
layouts.append(KeyboardLayout(width: width, showsGlobe: globe, language: language))
}
layouts.append(KeyboardLayout(width: width, field: .email, language: language))
}
}
return layouts
}
func testPortraitIs253PointsAndLandscapeIs187Points() {
for width in portraitWidths {
XCTAssertEqual(KeyboardLayout(width: width).totalHeight, 253, "width \(width)")
}
XCTAssertEqual(KeyboardLayout.height(for: .portrait), 253)
XCTAssertEqual(KeyboardLayout.height(for: .landscape), 187)
}
/// The strip is the 27 pt of Apple's predictive bar below the band iOS draws over a
/// third-party keyboard on every iPhone; row 1 starts 35 pt down, where Apple's keycaps start
/// relative to this view (35-35.5 pt, iOS 27.2). Turned there is no band: 42 pt, row 1 at
/// 50 pt, as Apple's. On the Duo folded and
/// upright it is 32 pt and the same gap (row 1 at 40 pt, as Apple's); elsewhere on the Duo,
/// Apple's whole 44 pt bar right on the keys.
func testStripIsPinnedInEveryOrientationAndPosture() {
let postures: [KeyboardPosture] = [.phone, .cover, .unfoldedWide, .unfoldedTall]
for posture in postures {
for orientation in [KeyboardOrientation.portrait, .landscape] {
let m = KeyboardMetrics.for(orientation, posture: posture)
XCTAssertEqual(m.stripTop, 0, "\(posture) \(orientation)")
let cover = posture == .cover && orientation == .portrait
let phone: (CGFloat, CGFloat, CGFloat) = orientation == .portrait ? (27, 35, 26) : (42, 50, 36)
let expected = posture == .phone ? phone : cover ? (32, 40, 31) : (44, 44, 36)
XCTAssertEqual(m.stripHeight, expected.0, "\(posture) \(orientation)")
XCTAssertEqual(m.stripArea, expected.1, "\(posture) \(orientation)")
XCTAssertEqual(m.stripPillHeight, expected.2, "\(posture) \(orientation)")
}
}
for layout in everyPortraitLayout() + landscapeLayouts() + duoLayouts() {
XCTAssertEqual(layout.stripFrame.height, layout.metrics.stripHeight, describe(layout))
XCTAssertTrue([27, 32, 42, 44].contains(layout.stripFrame.height), describe(layout))
let rowOneTop = layout.keys.filter { $0.row == 0 }.map(\.frame.minY).min()
XCTAssertEqual(rowOneTop ?? -1, layout.metrics.stripArea, accuracy: 0.001, describe(layout))
}
}
/// The iPhone Duo (iOS 27.2 simulator): Apple's row pitch for each screen, keycaps starting
/// as far in from the screen's side as Apple's, and keys filling the width.
func testDuoKeysMatchApplesRowsAndEdges() {
let cases: [(KeyboardLayout, windowInset: CGFloat, pitch: CGFloat, appleEdge: CGFloat)] = [
(KeyboardLayout(width: 452, posture: .cover, windowInset: 7), 7, 56, 8),
(KeyboardLayout(width: 655, posture: .unfoldedTall, windowInset: 7), 7, 59.7, 19),
(KeyboardLayout(width: 801, posture: .unfoldedWide, windowInset: 75), 75, 51.7, 86),
]
for (layout, windowInset, pitch, appleEdge) in cases {
let q = layout.key(.character("q"))!.frame
let a = layout.key(.character("a"))!.frame
let p = layout.key(.character("p"))!.frame
XCTAssertEqual(a.minY - q.minY, pitch, accuracy: 0.001, describe(layout))
XCTAssertEqual(windowInset + q.minX, appleEdge, accuracy: 0.5, describe(layout))
XCTAssertEqual(p.maxX, layout.width - layout.metrics.side, accuracy: 0.001, describe(layout))
XCTAssertEqual(layout.totalHeight, KeyboardLayout.height(for: .portrait, posture: layout.posture), describe(layout))
}
// Folded in landscape the Duo keeps the iPhone's landscape keys.
let land = KeyboardLayout(width: 528, orientation: .landscape, posture: .cover, windowInset: 75)
XCTAssertEqual(land.metrics.keyHeight, KeyboardMetrics.landscape.keyHeight)
XCTAssertEqual(land.totalHeight, 181)
}
/// Apple's split keyboard on the Duo unfolded upright (iOS 27.2 simulator, keyboard at
/// x = 75 pt on the 951 pt screen): each half's keys, G and V on both, and the keys'
/// positions and widths.
func testSplitMatchesApplesOnTheUnfoldedDuo() {
let layout = KeyboardLayout(width: 801, posture: .unfoldedWide, windowInset: 75)
XCTAssertTrue(layout.isSplit)
func half(_ row: Int, right: Bool) -> [String] {
layout.keys.filter { $0.row == row && ($0.frame.midX > layout.split!.middle) == right }
.sorted { $0.frame.minX < $1.frame.minX }.map(\.label)
}
XCTAssertEqual(half(0, right: false), ["q", "w", "e", "r", "t"])
XCTAssertEqual(half(0, right: true), ["y", "u", "i", "o", "p"])
XCTAssertEqual(half(1, right: false), ["a", "s", "d", "f", "g"])
XCTAssertEqual(half(1, right: true), ["g", "h", "j", "k", "l"])
XCTAssertEqual(half(2, right: false), ["shift", "z", "x", "c", "v"])
XCTAssertEqual(half(2, right: true), ["v", "b", "n", "m", "delete"])
XCTAssertEqual(half(3, right: false), ["123", "space"])
XCTAssertEqual(half(3, right: true), ["space", "return"])
// Apple's keycaps, in screen points (keyboard at 75): q 85.3, t ends 359.3, y 591.3,
// p ends 865.3, a 114, the right G 563, z 171, shift ends 148.3, delete 802.3.
func x(_ label: String, right: Bool = false) -> CGRect {
layout.keys.first { $0.label == label && ($0.frame.midX > layout.split!.middle) == right }!.frame.offsetBy(dx: 75, dy: 0)
}
XCTAssertEqual(x("q").minX, 85.3, accuracy: 1)
XCTAssertEqual(x("t").maxX, 359.3, accuracy: 1)
XCTAssertEqual(x("y", right: true).minX, 591.3, accuracy: 1)
XCTAssertEqual(x("p", right: true).maxX, 865.3, accuracy: 1)
XCTAssertEqual(x("a").minX, 114, accuracy: 1.5)
XCTAssertEqual(x("g", right: true).minX, 563, accuracy: 1)
XCTAssertEqual(x("z").minX, 171, accuracy: 1)
XCTAssertEqual(x("shift").maxX, 148.3, accuracy: 1)
XCTAssertEqual(x("delete", right: true).minX, 802.3, accuracy: 1)
XCTAssertEqual(x("q").width, 46.3, accuracy: 0.01)
// The strip sits over the right half, where Apple's predictions are.
XCTAssertEqual(layout.stripFrame.minX + 75, 552.7, accuracy: 1)
}
/// Each half's targets tile it; the middle maps to no key; both of a doubled letter's keys
/// read as one for Spatial autocorrect.
func testSplitTargetsLeaveTheMiddleToNoKey() {
var layouts: [KeyboardLayout] = []
for layer in layers {
for field in fields {
layouts.append(KeyboardLayout(width: 801, layer: layer, field: field, showsGlobe: true, showsEmoji: true, posture: .unfoldedWide, windowInset: 75))
}
}
for language in KeyboardLanguage.allCases {
layouts.append(KeyboardLayout(width: 801, language: language, posture: .unfoldedWide, windowInset: 75))
}
for layout in layouts {
let split = layout.split!
let area = layout.touchAreaFrame
for row in 0..<4 {
let keys = layout.keys.filter { $0.row == row }
let y = keys[0].hitFrame.midY
XCTAssertNil(layout.hitTest(CGPoint(x: split.middle, y: y)), "\(describe(layout)) row \(row) middle")
for key in keys {
XCTAssertTrue(key.hitFrame.contains(key.frame), "\(describe(layout)) \(key.label)")
XCTAssertLessThan(key.frame.maxX, layout.width + 0.001, describe(layout))
}
// No point of a half is without a key: its edge to just past its inner key.
for x in stride(from: 0.5, to: layout.width, by: 3) {
let point = CGPoint(x: x, y: y)
let hits = keys.filter { $0.hitFrame.contains(point) }
XCTAssertLessThanOrEqual(hits.count, 1, "\(describe(layout)) \(point)")
let inLeft = x <= keys.filter { $0.frame.midX < split.middle }.map(\.hitFrame.maxX).max()!
let inRight = x >= keys.filter { $0.frame.midX > split.middle }.map(\.hitFrame.minX).min()!
if inLeft || inRight {
XCTAssertEqual(hits.count, 1, "\(describe(layout)) \(point)")
}
}
}
XCTAssertEqual(area.maxY, layout.totalHeight, accuracy: 0.001)
XCTAssertLessThan(layout.unsplitX(split.rightEdge), split.middle)
}
let english = KeyboardLayout(width: 801, posture: .unfoldedWide, windowInset: 75)
let gs = english.keys.filter { $0.label == "g" }
XCTAssertEqual(gs.count, 2)
XCTAssertEqual(english.unsplitX(gs[0].frame.midX), english.unsplitX(gs[1].frame.midX), accuracy: 0.5)
let keys = TypingDecoder.Keys(layout: english)!
let g = keys.centres["g"]!
XCTAssertEqual(g.x, english.unsplitX(gs[0].frame.midX), accuracy: 0.5)
}
func testSplitHalvesFollowEachLayout() {
XCTAssertEqual(SplitGeometry.halves(Array("qwertyuiop").map(String.init)).left.joined(), "qwert")
XCTAssertEqual(SplitGeometry.halves(Array("asdfghjkl").map(String.init)).right.joined(), "ghjkl")
XCTAssertEqual(SplitGeometry.halves(Array("zxcvbnm").map(String.init)).left.joined(), "zxcv")
// Odd rows of other layouts share their middle key too (Russian's 11-key first row).
let russian = SplitGeometry.halves(KeyboardLanguage.russian.letterRows[0])
XCTAssertEqual(russian.left.last, russian.right.first)
// Only the Duo unfolded upright splits.
XCTAssertFalse(KeyboardLayout(width: 655, posture: .unfoldedTall, windowInset: 7).isSplit)
XCTAssertFalse(KeyboardLayout(width: 452, posture: .cover, windowInset: 7).isSplit)
XCTAssertFalse(KeyboardLayout(width: 724, orientation: .landscape).isSplit)
}
func testPostureFollowsTheScreen() {
XCTAssertEqual(KeyboardPosture.current(screenSize: CGSize(width: 402, height: 874), isFoldable: false), .phone)
XCTAssertEqual(KeyboardPosture.current(screenSize: CGSize(width: 874, height: 402), isFoldable: false), .phone)
XCTAssertEqual(KeyboardPosture.current(screenSize: CGSize(width: 466, height: 678), isFoldable: true), .cover)
XCTAssertEqual(KeyboardPosture.current(screenSize: CGSize(width: 678, height: 466), isFoldable: true), .cover)
XCTAssertEqual(KeyboardPosture.current(screenSize: CGSize(width: 951, height: 669), isFoldable: true), .unfoldedWide)
XCTAssertEqual(KeyboardPosture.current(screenSize: CGSize(width: 669, height: 951), isFoldable: true), .unfoldedTall)
}
func testPortraitMetricsMatchAppleIOS26() {
let proMax = KeyboardLayout(width: 440)
XCTAssertEqual(proMax.letterWidth, (440 - 13 - 54) / 10, accuracy: 0.001)
let q = proMax.key(.character("q"))!
XCTAssertEqual(q.frame.minX, 6.5, accuracy: 0.001)
XCTAssertEqual(q.frame.minY, 35, accuracy: 0.001)
XCTAssertEqual(q.frame.height, 45)
let shift = proMax.key(.shift)!
XCTAssertEqual(shift.frame.width, proMax.letterWidth * 1.34, accuracy: 0.001)
}
func testHitTargetsTileTheKeyAreaWithNoDeadZonesOrOverlaps() {
var generator = SystemRandomNumberGenerator()
for layout in everyPortraitLayout() + landscapeLayouts() + duoLayouts() where !layout.isSplit {
let area = layout.touchAreaFrame
// Row 1 also takes the gap under the strip (or, on the Duo, the strip's bottom band,
// under its pills), as Apple's keys reach above their keycaps; the Hex key in the
// strip stops where it starts.
XCTAssertEqual(area.minY, layout.keysAreaFrame.minY - layout.rowOneReach, describe(layout))
XCTAssertGreaterThanOrEqual(area.minY, layout.stripFrame.maxY - KeyboardLayout.stripTouchBand, describe(layout))
if let hex = layout.key(.hex), hex.row < 0 {
XCTAssertLessThanOrEqual(hex.hitFrame.maxY, area.minY, describe(layout))
}
for key in layout.keys where key.row == 0 {
let justAbove = CGPoint(x: key.frame.midX, y: key.frame.minY - 2)
XCTAssertEqual(layout.hitTest(justAbove)?.kind, key.kind, "\(describe(layout)) \(key.label)")
}
var rowTop = area.minY
for row in 0..<4 {
let targets = layout.keys.filter { $0.row == row }.map(\.hitFrame).sorted { $0.minX < $1.minX }
XCTAssertEqual(targets.first?.minX, 0, describe(layout))
XCTAssertEqual(targets.last?.maxX, layout.width, describe(layout))
for target in targets {
XCTAssertEqual(target.minY, rowTop, accuracy: 0.0001, "\(describe(layout)) row \(row)")
}
for (a, b) in zip(targets, targets.dropFirst()) {
XCTAssertEqual(a.maxX, b.minX, accuracy: 0.0001, "\(describe(layout)) row \(row)")
}
rowTop = targets[0].maxY
}
XCTAssertEqual(rowTop, area.maxY, accuracy: 0.0001, describe(layout))
for _ in 0..<400 {
let point = CGPoint(
x: CGFloat.random(in: 0..<layout.width, using: &generator),
y: CGFloat.random(in: area.minY..<area.maxY, using: &generator)
)
let hits = layout.keys.filter { $0.hitFrame.contains(point) }
XCTAssertEqual(hits.count, 1, "\(describe(layout)) at \(point): \(hits.map(\.label))")
}
XCTAssertNil(layout.hitTest(CGPoint(x: 20, y: layout.stripFrame.midY)), "strip is not a key")
}
}
func testKeycapsSitInsideTheirTargetsAndNeverOverlap() {
for layout in everyPortraitLayout() + landscapeLayouts() + duoLayouts() {
let bounds = CGRect(x: 0, y: 0, width: layout.width, height: layout.totalHeight)
for key in layout.keys {
XCTAssertTrue(key.hitFrame.contains(key.frame), "\(describe(layout)) \(key.label)")
XCTAssertTrue(bounds.contains(key.frame), "\(describe(layout)) \(key.label)")
XCTAssertGreaterThan(key.frame.width, 20, "\(describe(layout)) \(key.label)")
}
for (i, a) in layout.keys.enumerated() {
for b in layout.keys[(i + 1)...] {
XCTAssertFalse(a.frame.intersects(b.frame), "\(describe(layout)) \(a.label) × \(b.label)")
}
}
}
}
func testBalloonsStayInsideTheKeyboard() {
for layout in everyPortraitLayout() {
let bounds = CGRect(x: 0, y: 0, width: layout.width, height: layout.totalHeight)
for key in layout.keys where key.character != nil {
guard let balloon = layout.balloon(for: key) else {
return XCTFail("\(describe(layout)) \(key.label) has no balloon")
}
XCTAssertTrue(
bounds.insetBy(dx: -0.001, dy: -0.001).contains(balloon.bounds),
"\(describe(layout)) \(key.label): \(balloon.bubble)"
)
XCTAssertGreaterThanOrEqual(balloon.bubble.width, key.frame.width)
}
}
}
func testAccentMenusClampInwardAcrossEveryWidth() {
for width in portraitWidths {
let layout = KeyboardLayout(width: width)
let bounds = CGRect(x: 0, y: 0, width: layout.width, height: layout.totalHeight)
for ch in ["e", "a", "i", "o", "u", "n", "c", "s", "z"] {
let key = layout.key(.character(ch))!
let options = AccentCatalog.options(for: ch, uppercase: false)!
let menu = AccentMenu.build(for: key.frame, rawOptions: options, in: layout.width)
XCTAssertTrue(
bounds.insetBy(dx: -0.01, dy: -0.01).contains(menu.bubbleFrame),
"width \(width) key \(ch): \(menu.bubbleFrame)"
)
XCTAssertEqual(menu.selectedOption, ch)
}
}
}
func testEdgeBalloonsArePushedInward() {
let layout = KeyboardLayout(width: 375)
let q = layout.balloon(for: layout.key(.character("q"))!)!
let p = layout.balloon(for: layout.key(.character("p"))!)!
let g = layout.balloon(for: layout.key(.character("g"))!)!
XCTAssertGreaterThan(q.offsetX, 0)
XCTAssertLessThan(p.offsetX, 0)
XCTAssertEqual(g.offsetX, 0, accuracy: 0.001)
XCTAssertEqual(q.bubble.minY, 0, accuracy: 0.001)
}
func testNoBalloonsForModifiersOrInLandscape() {
let portrait = KeyboardLayout(width: 393)
XCTAssertNil(portrait.balloon(for: portrait.key(.space)!))
XCTAssertNil(portrait.balloon(for: portrait.key(.shift)!))
let landscape = KeyboardLayout(width: 852, orientation: .landscape)
XCTAssertNil(landscape.balloon(for: landscape.key(.character("a"))!))
}
func testBottomRowMatchesIOS26EmailAndURLRightOfSpace() {
// The Hex key sits at the strip's trailing edge, so the bottom row is Apple's.
XCTAssertEqual(bottomRow(KeyboardLayout(width: 393)), [.layerSwitch(.numbers), .space, .returnKey])
XCTAssertEqual(
bottomRow(KeyboardLayout(width: 375, showsGlobe: true)),
[.layerSwitch(.numbers), .globe, .space, .returnKey]
)
XCTAssertEqual(
bottomRow(KeyboardLayout(width: 393, layer: .numbers, field: .email)),
[.layerSwitch(.letters), .space, .character("@"), .character("."), .returnKey]
)
XCTAssertEqual(
bottomRow(KeyboardLayout(width: 393, field: .url)),
[.layerSwitch(.numbers), .space, .character("."), .character("/"), .returnKey]
)
}
func testHexKeySitsAtTheStripsTrailingEdge() {
let layout = KeyboardLayout(width: 402)
let hex = layout.key(.hex)!
XCTAssertEqual(hex.row, -1)
XCTAssertEqual(hex.frame.maxX, 402 - layout.metrics.side, accuracy: 0.001)
XCTAssertEqual(hex.frame.midY, layout.metrics.stripHeight / 2, accuracy: 0.001)
XCTAssertLessThanOrEqual(layout.stripFrame.maxX, hex.frame.minX)
}
/// Apple's slots are thirds of the keyboard (dividers end at 134 and 268 pt on a 402 pt
/// iPhone); the Hex key takes its room from the slot beside it, on either side.
func testSuggestionSlotsAreThirdsOfTheBarLessTheHexKey() {
let right = KeyboardLayout(width: 402)
let slots = right.stripSlotFrames
for (x, expected) in zip(slots.map(\.minX), [0, 134, 268] as [CGFloat]) { XCTAssertEqual(x, expected, accuracy: 0.001) }
XCTAssertEqual(slots[0].maxX, 134, accuracy: 0.001)
XCTAssertEqual(slots[1].maxX, 268, accuracy: 0.001)
XCTAssertEqual(slots[2].maxX, right.stripFrame.maxX, accuracy: 0.001)
XCTAssertTrue(slots.allSatisfy { $0.minY == right.stripFrame.minY && $0.height == right.stripFrame.height })
let left = KeyboardLayout(width: 402, hexPlacement: .stripLeading)
let mirrored = left.stripSlotFrames
XCTAssertEqual(mirrored[0].minX, left.stripFrame.minX, accuracy: 0.001)
for (x, expected) in zip(mirrored.map(\.maxX), [134, 268, 402] as [CGFloat]) { XCTAssertEqual(x, expected, accuracy: 0.001) }
for layout in everyPortraitLayout() + landscapeLayouts() + duoLayouts() {
let frames = layout.stripSlotFrames
XCTAssertEqual(frames.first!.minX, layout.stripFrame.minX, accuracy: 0.001, describe(layout))
XCTAssertEqual(frames.last!.maxX, layout.stripFrame.maxX, accuracy: 0.001, describe(layout))
XCTAssertTrue(frames.allSatisfy { $0.width > 40 }, describe(layout))
}
}
/// Settings › Keyboard › Hex key › Left: the key at the strip's leading edge, the strip
/// after it to the keyboard's side, and every other key where Right puts it.
func testHexKeyOnTheLeftSitsAtTheStripsLeadingEdge() {
let right = KeyboardLayout(width: 402, hexPlacement: .stripTrailing)
let layout = KeyboardLayout(width: 402, hexPlacement: .stripLeading)
let hex = layout.key(.hex)!
XCTAssertTrue(layout.hexOnLeading)
XCTAssertFalse(right.hexOnLeading)
XCTAssertEqual(hex.row, -1)
XCTAssertEqual(hex.frame.minX, layout.metrics.side, accuracy: 0.001)
XCTAssertEqual(hex.frame.size, right.key(.hex)!.frame.size)
XCTAssertGreaterThanOrEqual(layout.stripFrame.minX, hex.frame.maxX)
XCTAssertEqual(layout.stripFrame.maxX, 402, accuracy: 0.001)
XCTAssertEqual(layout.stripFrame.width, right.stripFrame.width, accuracy: 0.001)
XCTAssertEqual(layout.keys.filter { $0.row >= 0 }, right.keys.filter { $0.row >= 0 })
XCTAssertNil(layout.hitTest(CGPoint(x: layout.stripFrame.maxX - 20, y: layout.stripFrame.midY)), "strip is not a key")
}
/// On the unfolded Duo's split keyboard, Left puts the strip and the Hex key over the left
/// half, mirroring Right's right half.
func testHexKeyOnTheLeftPutsTheSplitStripOverTheLeftHalf() {
let right = KeyboardLayout(width: 801, posture: .unfoldedWide, windowInset: 75, hexPlacement: .stripTrailing)
let layout = KeyboardLayout(width: 801, posture: .unfoldedWide, windowInset: 75, hexPlacement: .stripLeading)
let split = layout.split!
let hex = layout.key(.hex)!
XCTAssertEqual(hex.frame.minX, layout.metrics.side, accuracy: 0.001)
XCTAssertLessThan(layout.stripFrame.maxX, split.middle)
XCTAssertEqual(layout.stripFrame.maxX, split.leftEdge + SplitGeometry.stripLead, accuracy: 0.001)
XCTAssertGreaterThanOrEqual(layout.stripFrame.minX, hex.frame.maxX)
XCTAssertGreaterThan(right.stripFrame.minX, split.middle)
XCTAssertEqual(layout.stripFrame.width, right.stripFrame.width, accuracy: 0.5)
XCTAssertEqual(layout.keys.filter { $0.row >= 0 }, right.keys.filter { $0.row >= 0 })
}
func testRowThreeModifiersFollowTheLayer() {
XCTAssertNotNil(KeyboardLayout(width: 393).key(.shift))
XCTAssertEqual(KeyboardLayout(width: 393, layer: .numbers).key(.layerSwitch(.symbols))?.row, 2)
XCTAssertEqual(KeyboardLayout(width: 393, layer: .symbols).key(.layerSwitch(.numbers))?.row, 2)
let numbers = KeyboardLayout(width: 393, layer: .numbers)
XCTAssertEqual(numbers.keys.filter { $0.row == 2 }.compactMap(\.character), [".", ",", "?", "!", "'"])
}
func testRowTwoIsCentred() {
let layout = KeyboardLayout(width: 402)
let a = layout.key(.character("a"))!.frame
let l = layout.key(.character("l"))!.frame
XCTAssertEqual(a.minX, layout.width - l.maxX, accuracy: 0.001)
XCTAssertEqual(layout.key(.character("a"))!.hitFrame.minX, 0)
XCTAssertEqual(layout.key(.character("l"))!.hitFrame.maxX, layout.width)
}
func testLandscapeKeepsInsetsAndHeight() {
let layout = KeyboardLayout(width: 932, orientation: .landscape, horizontalInset: 60)
XCTAssertEqual(layout.totalHeight, 187)
XCTAssertEqual(layout.key(.character("q"))!.frame.minX, 64, accuracy: 0.001)
XCTAssertEqual(layout.key(.character("q"))!.hitFrame.minX, 0)
}
// MARK: - Languages
func testLetterRowsMatchApplesLayouts() {
let rows: [KeyboardLanguage: [String]] = [
.english: ["qwertyuiop", "asdfghjkl", "zxcvbnm"],
.norwegian: ["qwertyuiopå", "asdfghjkløæ", "zxcvbnm"],
.spanish: ["qwertyuiop", "asdfghjklñ", "zxcvbnm"],
.german: ["qwertzuiopü", "asdfghjklöä", "yxcvbnm"],
.italian: ["qwertyuiop", "asdfghjkl", "zxcvbnm"],
.french: ["azertyuiop", "qsdfghjklm", "wxcvbn"],
.frenchCanadian: ["qwertyuiop", "asdfghjkl", "zxcvbnm"],
.frenchSwiss: ["qwertzuiop", "asdfghjkl", "yxcvbnm"],
.portuguese: ["qwertyuiop", "asdfghjkl", "zxcvbnm"],
.russian: ["йцукенгшщзх", "фывапролджэ", "ячсмитьбю"],
.ukrainian: ["йцукенгшщзхї", "фівапролджєʼ", "ячсмитьбюґ"],
.serbianLatin: ["qwertzuiop", "asdfghjkl", "yxcvbnm"],
]
for (language, expected) in rows {
let layout = KeyboardLayout(width: 402, language: language)
for row in 0..<3 {
XCTAssertEqual(letters(layout, row: row).joined(), expected[row], "\(language) row \(row + 1)")
}
}
}
func testElevenKeyRowsFitEveryIPhoneWidthAndLandscape() {
let cases: [(CGFloat, KeyboardOrientation, CGFloat)] = [
(375, .portrait, 0), (402, .portrait, 0), (440, .portrait, 0),
(667, .landscape, 0), (874, .landscape, 0), (956, .landscape, 60),
]
for language in [KeyboardLanguage.norwegian, .german] {
for (width, orientation, inset) in cases {
let layout = KeyboardLayout(width: width, orientation: orientation, horizontalInset: inset, language: language)
let english = KeyboardLayout(width: width, orientation: orientation, horizontalInset: inset)
let m = layout.metrics
let label = "\(language) \(width)pt \(orientation)"
let inner = width - 2 * inset
XCTAssertEqual(layout.characterWidth, (inner - 2 * m.side - 10 * m.gap) / 11, accuracy: 0.001, label)
XCTAssertGreaterThan(layout.characterWidth, 26, label)
for row in 0..<2 {
let keys = layout.keys.filter { $0.row == row }.sorted { $0.frame.minX < $1.frame.minX }
XCTAssertEqual(keys.count, 11, label)
// Rows 1 and 2 run edge to edge, like English row 1.
XCTAssertEqual(keys.first!.frame.minX, inset + m.side, accuracy: 0.001, label)
XCTAssertEqual(keys.last!.frame.maxX, width - inset - m.side, accuracy: 0.001, label)
}
// Row 3's letters are as wide as the others and centred between shift and delete,
// which keep their English size, as does the whole bottom row.
let row3 = layout.keys.filter { $0.row == 2 && $0.character != nil }.sorted { $0.frame.minX < $1.frame.minX }
XCTAssertEqual(row3.first!.frame.width, layout.characterWidth, accuracy: 0.001, label)
XCTAssertEqual(row3.first!.frame.minX - inset, width - inset - row3.last!.frame.maxX, accuracy: 0.001, label)
XCTAssertEqual(layout.key(.shift)!.frame, english.key(.shift)!.frame, label)
XCTAssertEqual(layout.key(.delete)!.frame, english.key(.delete)!.frame, label)
XCTAssertLessThan(layout.key(.shift)!.frame.maxX, row3.first!.frame.minX, label)
XCTAssertEqual(
layout.keys.filter { $0.row == 3 }.map(\.frame),
english.keys.filter { $0.row == 3 }.map(\.frame),
label
)
}
}
}
/// Russian's nine-letter third row keeps its letters as wide as rows 1 and 2; shift and
/// delete narrow to fit beside them, as on Apple's Russian keyboard.
func testRussiansNineLetterRowFitsBetweenNarrowerShiftAndDelete() {
let cases: [(CGFloat, KeyboardOrientation, CGFloat)] = [
(320, .portrait, 0), (375, .portrait, 0), (402, .portrait, 0), (440, .portrait, 0),
(667, .landscape, 0), (956, .landscape, 60),
]
for (width, orientation, inset) in cases {
let layout = KeyboardLayout(width: width, orientation: orientation, horizontalInset: inset, language: .russian)
let english = KeyboardLayout(width: width, orientation: orientation, horizontalInset: inset)
let label = "\(width)pt \(orientation)"
let row3 = layout.keys.filter { $0.row == 2 && $0.character != nil }.sorted { $0.frame.minX < $1.frame.minX }
XCTAssertEqual(row3.count, 9, label)
XCTAssertEqual(row3.first!.frame.width, layout.characterWidth, accuracy: 0.001, label)
let shift = layout.key(.shift)!.frame
let delete = layout.key(.delete)!.frame
XCTAssertEqual(row3.first!.frame.minX - shift.maxX, layout.metrics.gap, accuracy: 0.001, label)
XCTAssertEqual(delete.minX - row3.last!.frame.maxX, layout.metrics.gap, accuracy: 0.001, label)
XCTAssertEqual(shift.width, delete.width, accuracy: 0.001, label)
XCTAssertLessThan(shift.width, english.key(.shift)!.frame.width, label)
XCTAssertGreaterThanOrEqual(shift.width, layout.characterWidth - 0.001, label)
XCTAssertEqual(
layout.keys.filter { $0.row == 3 }.map(\.frame),
english.keys.filter { $0.row == 3 }.map(\.frame),
label
)
}
// The numbers and symbols pages are English's.
for layer in [KeyboardLayer.numbers, .symbols] {
XCTAssertEqual(
KeyboardLayout(width: 402, layer: layer, language: .russian).keys,
KeyboardLayout(width: 402, layer: layer).keys
)
}
}
/// The standard Ukrainian ЙЦУКЕН in the rows the system Ukrainian keyboard shows on an
/// iPhone 17 Pro (iOS 27.2 simulator, 402 pt, read through accessibility): rows 1 and 2
/// are twelve keys edge to edge (Й at 5 pt, Ї at 367 pt, a 33 pt pitch), row 3's ten letters
/// sit between a shift and delete one letter wide, and the bottom row and the numbers and
/// symbols pages are English's.
func testUkrainiansTwelveKeyRowsMatchApples() {
let cases: [(CGFloat, KeyboardOrientation, CGFloat)] = [
(320, .portrait, 0), (375, .portrait, 0), (402, .portrait, 0), (440, .portrait, 0),
(667, .landscape, 0), (956, .landscape, 60),
]
for (width, orientation, inset) in cases {
let layout = KeyboardLayout(width: width, orientation: orientation, horizontalInset: inset, language: .ukrainian)
let english = KeyboardLayout(width: width, orientation: orientation, horizontalInset: inset)
let m = layout.metrics
let label = "\(width)pt \(orientation)"
XCTAssertEqual(layout.characterWidth, (width - 2 * inset - 2 * m.side - 11 * m.gap) / 12, accuracy: 0.001, label)
for row in 0..<2 {
let keys = layout.keys.filter { $0.row == row }.sorted { $0.frame.minX < $1.frame.minX }
XCTAssertEqual(keys.count, 12, label)
XCTAssertEqual(keys.first!.frame.minX, inset + m.side, accuracy: 0.001, label)
XCTAssertEqual(keys.last!.frame.maxX, width - inset - m.side, accuracy: 0.001, label)
}
let row3 = layout.keys.filter { $0.row == 2 && $0.character != nil }.sorted { $0.frame.minX < $1.frame.minX }
XCTAssertEqual(row3.count, 10, label)
let shift = layout.key(.shift)!.frame
let delete = layout.key(.delete)!.frame
XCTAssertEqual(shift.width, layout.characterWidth, accuracy: 0.001, label)
XCTAssertEqual(delete.width, layout.characterWidth, accuracy: 0.001, label)
XCTAssertEqual(row3.first!.frame.minX - shift.maxX, m.gap, accuracy: 0.001, label)
XCTAssertEqual(delete.minX - row3.last!.frame.maxX, m.gap, accuracy: 0.001, label)
XCTAssertEqual(
layout.keys.filter { $0.row == 3 }.map(\.frame),
english.keys.filter { $0.row == 3 }.map(\.frame),
label
)
}
let pro = KeyboardLayout(width: 402, language: .ukrainian)
XCTAssertEqual(pro.key(.character("й"))!.frame.minX, 5, accuracy: 2)
XCTAssertEqual(pro.key(.character("ї"))!.frame.minX, 367, accuracy: 2)
for layer in [KeyboardLayer.numbers, .symbols] {
XCTAssertEqual(
KeyboardLayout(width: 402, layer: layer, language: .ukrainian).keys,
KeyboardLayout(width: 402, layer: layer).keys
)
}
}
/// Apple's AZERTY on the tester's iPhone 17 Pro (402 pt; their French and English
/// keyboard): rows 1 and 2 run edge to edge, W to N sit under E to I, and shift and
/// delete keep their English size with a gap beside them. A tap in that gap goes to the
/// nearer key, and every point of the row still types something.
func testFrenchIsApplesAzerty() {
for width: CGFloat in [375, 402, 440] {
let layout = KeyboardLayout(width: width, language: .french)
let english = KeyboardLayout(width: width)
let label = "\(width)pt"
XCTAssertEqual(layout.characterWidth, layout.letterWidth, accuracy: 0.001, label)
for row in 0..<2 {
let keys = layout.keys.filter { $0.row == row }.sorted { $0.frame.minX < $1.frame.minX }
XCTAssertEqual(keys.count, 10, label)
XCTAssertEqual(keys.first!.frame.minX, layout.metrics.side, accuracy: 0.001, label)
XCTAssertEqual(keys.last!.frame.maxX, width - layout.metrics.side, accuracy: 0.001, label)
}
for (bottom, top) in zip(["w", "n"], ["e", "i"]) {
XCTAssertEqual(layout.key(.character(bottom))!.frame.minX, layout.key(.character(top))!.frame.minX, accuracy: 0.001, label)
XCTAssertEqual(layout.key(.character(bottom))!.frame.width, layout.letterWidth, accuracy: 0.001, label)
}
let shift = layout.key(.shift)!
let delete = layout.key(.delete)!
let w = layout.key(.character("w"))!
let n = layout.key(.character("n"))!
XCTAssertEqual(shift.frame, english.key(.shift)!.frame, label)
XCTAssertEqual(delete.frame, english.key(.delete)!.frame, label)
XCTAssertGreaterThan(w.frame.minX - shift.frame.maxX, 4 * layout.metrics.gap, "a gap beside shift, \(label)")
XCTAssertGreaterThan(delete.frame.minX - n.frame.maxX, 4 * layout.metrics.gap, "and beside delete, \(label)")
XCTAssertEqual(layout.keys.filter { $0.row == 3 }.map(\.frame), english.keys.filter { $0.row == 3 }.map(\.frame), label)
let y = shift.frame.midY
for (x, expected) in [
(shift.frame.maxX + 1, KeyKind.shift), (w.frame.minX - 1, .character("w")),
(delete.frame.minX - 1, .delete), (n.frame.maxX + 1, .character("n")),
] {
XCTAssertEqual(layout.hitTest(CGPoint(x: x, y: y))?.kind, expected, "x \(x), \(label)")
}
XCTAssertEqual(
layout.hitTest(CGPoint(x: (shift.frame.maxX + w.frame.minX) / 2 - 0.5, y: y))?.kind, .shift, label
)
}
// Apple's measured cells on 402 pt: the A key's 4.7 to 44, shift's 4.7 to 56, W from 63.7.
let apple = KeyboardLayout(width: 402, language: .french)
XCTAssertEqual(apple.key(.character("a"))!.frame.midX, (4.7 + 44) / 2, accuracy: 1.5)
XCTAssertEqual(apple.key(.character("m"))!.frame.midX, (360 + 399.7) / 2, accuracy: 1.5)
// The numbers and symbols pages are English's, as Apple's are.
for layer in [KeyboardLayer.numbers, .symbols] {
XCTAssertEqual(KeyboardLayout(width: 402, layer: layer, language: .french).keys, KeyboardLayout(width: 402, layer: layer).keys)
}
}
func testSpanishKeepsTenKeysWithNOnRowTwo() {
for width: CGFloat in [375, 402, 440] {
let layout = KeyboardLayout(width: width, language: .spanish)
XCTAssertEqual(layout.characterWidth, layout.letterWidth, accuracy: 0.001)
let n = layout.key(.character("ñ"))!
XCTAssertEqual(n.frame.maxX, width - layout.metrics.side, accuracy: 0.001)
XCTAssertEqual(n.hitFrame.maxX, width)
XCTAssertEqual(layout.key(.character("a"))!.frame.minX, layout.metrics.side, accuracy: 0.001)
}
}
func testAccentsMatchEachLanguage() {
XCTAssertEqual(AccentCatalog.options(for: "ø", uppercase: false, language: .norwegian), ["ø", "ö"])
XCTAssertEqual(AccentCatalog.options(for: "æ", uppercase: true, language: .norwegian), ["Æ", "Ä"])
XCTAssertNil(AccentCatalog.options(for: "å", uppercase: false, language: .norwegian))
let norwegianA = AccentCatalog.options(for: "a", uppercase: false, language: .norwegian)!
XCTAssertFalse(norwegianA.contains("å") || norwegianA.contains("æ"), "they have their own keys")
XCTAssertTrue(AccentCatalog.options(for: "s", uppercase: false, language: .german)!.contains("ß"))
XCTAssertFalse(AccentCatalog.options(for: "u", uppercase: false, language: .german)!.contains("ü"))
XCTAssertEqual(AccentCatalog.options(for: "e", uppercase: false, language: .spanish)?.dropFirst().first, "é")
XCTAssertEqual(AccentCatalog.options(for: "n", uppercase: true, language: .spanish), ["N", "Ñ", "Ń"])
XCTAssertEqual(
AccentCatalog.options(for: "a", uppercase: false),
AccentCatalog.options(for: "a", uppercase: false, language: .english),
"English is unchanged"
)
// Italian's accents come first on each vowel: à è ì ò ù, and é right after è.
let italian = ["a", "e", "i", "o", "u"].map {
AccentCatalog.options(for: $0, uppercase: false, language: .italian)!.dropFirst().first
}
XCTAssertEqual(italian, ["à", "è", "ì", "ò", "ù"])
XCTAssertEqual(AccentCatalog.options(for: "e", uppercase: false, language: .italian)?.dropFirst(2).first, "é")
XCTAssertEqual(AccentCatalog.options(for: "o", uppercase: true, language: .italian)?.prefix(2), ["O", "Ò"])
XCTAssertEqual(AccentCatalog.options(for: "e", uppercase: false, language: .french)?.dropFirst().first, "é")
XCTAssertEqual(AccentCatalog.options(for: "c", uppercase: false, language: .french)?.dropFirst().first, "ç")
// Apple's French order (TextInput_fr): û before ù, and ª and º after the French accents.
XCTAssertEqual(AccentCatalog.options(for: "u", uppercase: false, language: .french)?.prefix(3), ["u", "û", "ù"])
XCTAssertEqual(AccentCatalog.options(for: "a", uppercase: true, language: .french)?.prefix(4), ["A", "À", "Â", "ª"])
XCTAssertEqual(AccentCatalog.options(for: "o", uppercase: false, language: .french)?.prefix(4), ["o", "ô", "œ", "º"])
for language in [KeyboardLanguage.frenchCanadian, .frenchSwiss] {
for letter in ["a", "e", "i", "o", "u", "c"] {
XCTAssertEqual(
AccentCatalog.options(for: letter, uppercase: false, language: language),
AccentCatalog.options(for: letter, uppercase: false, language: .french),
"\(language) \(letter)"
)
}
}
XCTAssertEqual(AccentCatalog.options(for: "a", uppercase: false, language: .portuguese)?.prefix(3), ["a", "á", "ã"])
// Russian: ё on е and ъ on ь, as on Apple's; Serbian (Latin): č ć on c, đ on d, š on s, ž on z.
XCTAssertEqual(AccentCatalog.options(for: "е", uppercase: false, language: .russian)?.prefix(2), ["е", "ё"])
XCTAssertEqual(AccentCatalog.options(for: "Е", uppercase: true, language: .russian)?.prefix(2), ["Е", "Ё"])
XCTAssertEqual(AccentCatalog.options(for: "ь", uppercase: false, language: .russian)?.prefix(2), ["ь", "ъ"])
XCTAssertEqual(AccentCatalog.options(for: "ь", uppercase: true, language: .russian)?.prefix(2), ["Ь", "Ъ"])
XCTAssertNil(AccentCatalog.options(for: "б", uppercase: false, language: .russian))
// Ukrainian, as the system keyboard's long-press options were observed: only ʼ offers
// anything (the other apostrophes); ₴ on $; no ё, and no other Cyrillic language's
// letters.
XCTAssertEqual(AccentCatalog.options(for: "ʼ", uppercase: false, language: .ukrainian), ["ʼ", "'", "’", "‘", "`"])
for letter in KeyboardLanguage.ukrainian.letterRows.joined() where letter != "ʼ" {
XCTAssertNil(AccentCatalog.options(for: letter, uppercase: false, language: .ukrainian), letter)
}
XCTAssertEqual(AccentCatalog.options(for: "$", uppercase: false, language: .ukrainian)?.prefix(2), ["$", "₴"])
XCTAssertFalse(AccentCatalog.options(for: "$", uppercase: false)?.contains("₴") ?? true, "the hryvnia is Ukrainian's")
XCTAssertNil(AccentCatalog.options(for: "е", uppercase: false, language: .ukrainian))
XCTAssertNil(AccentCatalog.options(for: "и", uppercase: false, language: .ukrainian))
XCTAssertFalse(KeyboardLanguage.ukrainian.letterRows.joined().contains { ["ы", "э", "ъ", "ё"].contains($0) })
XCTAssertEqual(AccentCatalog.options(for: "c", uppercase: false, language: .serbianLatin)?.prefix(3), ["c", "č", "ć"])
XCTAssertEqual(AccentCatalog.options(for: "d", uppercase: true, language: .serbianLatin), ["D", "Đ"])
XCTAssertEqual(AccentCatalog.options(for: "s", uppercase: false, language: .serbianLatin)?.prefix(2), ["s", "š"])
XCTAssertEqual(AccentCatalog.options(for: "z", uppercase: false, language: .serbianLatin)?.prefix(2), ["z", "ž"])
}
func testAccentMenusOnTheNewKeysStayInside() {
let keys: [KeyboardLanguage: [String]] = [
.norwegian: ["å", "ø", "æ", "a", "o"],
.spanish: ["ñ", "a", "o", "n"],
.german: ["ü", "ö", "ä", "s", "a", "u"],
.russian: ["й", "е", "х", "ж", "э", "ь", "ю", "я"],
.ukrainian: ["й", "ї", "є", "ʼ", "ґ"],
.serbianLatin: ["c", "d", "s", "z"],
]
for width in portraitWidths {
for (language, characters) in keys {
let layout = KeyboardLayout(width: width, language: language)
let bounds = CGRect(x: 0, y: 0, width: layout.width, height: layout.totalHeight)
for ch in characters {
let key = layout.key(.character(ch))!
guard let options = AccentCatalog.options(for: ch, uppercase: false, language: language) else { continue }
let menu = AccentMenu.build(for: key.frame, rawOptions: options, in: layout.width)
XCTAssertTrue(
bounds.insetBy(dx: -0.01, dy: -0.01).contains(menu.bubbleFrame),
"\(language) \(width) \(ch): \(menu.bubbleFrame)"
)
XCTAssertEqual(menu.selectedOption, ch)
}
}
}
}
func testTheLayoutFollowsTheDictationLanguage() {
func automatic(_ dictation: String?, modes: [String] = [], preferred: [String] = []) -> KeyboardLanguage {
KeyboardLanguage.automatic(dictationLanguage: dictation, inputModes: modes, preferredLanguages: preferred)
}
XCTAssertEqual(automatic("nb-NO"), .norwegian)
XCTAssertEqual(automatic("es-MX"), .spanish)
XCTAssertEqual(automatic("de-AT"), .german)
XCTAssertEqual(automatic("en-GB", modes: ["nb-NO"]), .english, "the dictation language wins")
XCTAssertEqual(automatic("he-IL", preferred: ["he-IL", "de-DE"]), .english, "Hebrew has no layout yet")
// Italian, French and Portuguese type in their own language, never English.
XCTAssertEqual(automatic("it-IT", modes: ["it-IT", "en-US"]), .italian)
XCTAssertEqual(automatic("it-CH"), .italian)
// French follows Apple's keyboard for the region: AZERTY in France and Belgium,
// QWERTY in Canada, QWERTZ in Switzerland.
XCTAssertEqual(automatic("fr-FR"), .french)
XCTAssertEqual(automatic("fr-BE"), .french)
XCTAssertEqual(automatic("fr"), .french)
XCTAssertEqual(automatic("fr-CA"), .frenchCanadian)
XCTAssertEqual(automatic("fr_CA"), .frenchCanadian)
XCTAssertEqual(automatic("fr-CH"), .frenchSwiss)
XCTAssertEqual(automatic("pt-BR"), .portuguese)
XCTAssertEqual(automatic("en-US", modes: ["it-IT"]), .english, "the dictation language still wins")
// Russian, and Serbian in Latin script (Hex has no Cyrillic Serbian layout).
XCTAssertEqual(automatic("ru-RU", modes: ["en-US"]), .russian)
XCTAssertEqual(automatic("sr-Latn-RS"), .serbianLatin)
XCTAssertEqual(automatic("sr_Latn"), .serbianLatin)
XCTAssertEqual(automatic("sr-RS"), .english, "Cyrillic Serbian has no layout")
XCTAssertEqual(automatic("en-US", modes: ["ru-RU", "sr-Latn"]), .english, "the dictation language still wins")
XCTAssertEqual(automatic("uk-UA", modes: ["ru-RU", "en-US"]), .ukrainian)
XCTAssertEqual(automatic("uk_UA"), .ukrainian)
XCTAssertEqual(automatic(nil, modes: ["emoji", "uk-UA", "en-US"], preferred: ["ru-RU"]), .ukrainian)
XCTAssertEqual(automatic(nil, preferred: ["uk-UA", "en-US"]), .ukrainian)
// Before Hex knows the dictation language: the first keyboard, then language, with a layout.
XCTAssertEqual(automatic(nil, modes: ["emoji", "nb-NO", "en-US"]), .norwegian)
XCTAssertEqual(automatic(nil, preferred: ["nn-NO"]), .norwegian)
XCTAssertEqual(automatic(nil, modes: ["emoji", "it-IT"], preferred: ["en-US"]), .italian)
XCTAssertEqual(automatic(nil, preferred: ["it-IT", "en-US"]), .italian)
XCTAssertEqual(automatic(nil, preferred: ["fr-FR"]), .french)
XCTAssertEqual(automatic(nil, preferred: ["fr-CA", "en-CA"]), .frenchCanadian)
XCTAssertEqual(automatic(nil, modes: ["fr-CH"], preferred: ["fr-FR"]), .frenchSwiss)
XCTAssertEqual(automatic(nil, preferred: ["ru-RU"]), .russian)
XCTAssertEqual(automatic(nil, modes: ["emoji", "sr-Latn"], preferred: ["en-US"]), .serbianLatin)
XCTAssertEqual(automatic(nil, modes: ["sr"], preferred: ["en-US"]), .english, "Apple's Cyrillic Serbian keyboard")
XCTAssertEqual(automatic(nil, preferred: ["el-GR"]), .english)
}
/// Settings › Keyboard › Languages: empty is Automatic (one language, as before); the
/// language last switched to counts only while it is still chosen; the space bar's label
/// names a French layout's region only beside another French one.
func testTheChosenLanguagesSwitchInOrder() {
let automatic = KeyboardLanguageList.resolve(chosen: [], stored: .french, automatic: .norwegian)
XCTAssertEqual(automatic.languages, [.norwegian])
XCTAssertEqual(automatic.current, .norwegian)
XCTAssertFalse(automatic.switches)
XCTAssertNil(automatic.spaceLabel)
let list = KeyboardLanguageList.resolve(chosen: [.english, .french, .russian, .english], stored: .russian, automatic: .german)
XCTAssertEqual(list.languages, [.english, .french, .russian])
XCTAssertEqual(list.current, .russian)
XCTAssertEqual(list.switched(by: 1), .english, "round the list")
XCTAssertEqual(list.switched(by: -1), .french)
XCTAssertEqual(list.spaceLabel, "Русский")
XCTAssertEqual(KeyboardLanguageList.resolve(chosen: [.english, .french], stored: .german, automatic: .german).current, .english)
XCTAssertEqual(KeyboardLanguageList.resolve(chosen: [.french, .english], stored: nil, automatic: .german).spaceLabel, "Français")
XCTAssertEqual(
KeyboardLanguageList.resolve(chosen: [.french, .frenchCanadian], stored: .frenchCanadian, automatic: .english).spaceLabel,
"Français (Canada)"
)
}
/// Bilingual autocorrect pairs the current language with the first other Latin-script one
/// that has a dictionary: none for Russian, nor for Serbian (no iOS dictionary), nor
/// between two French layouts (one dictionary).
func testBilingualAutocorrectPairsTwoLatinLanguagesWithDictionaries() {
let available = ["en_US", "fr_FR", "fr_CA", "ru_RU", "de_DE"]
func partner(_ chosen: [KeyboardLanguage], _ current: KeyboardLanguage) -> KeyboardLanguage? {
KeyboardLanguageList.resolve(chosen: chosen, stored: current, automatic: .english).partner(available: available)
}
XCTAssertEqual(partner([.english, .french, .russian], .french), .english)
XCTAssertEqual(partner([.english, .french, .russian], .english), .french)
XCTAssertNil(partner([.english, .french, .russian], .russian))
XCTAssertEqual(partner([.russian, .german, .english], .english), .german, "the first other Latin one")
XCTAssertNil(partner([.french, .frenchCanadian], .frenchCanadian), "one language, two layouts")
XCTAssertNil(partner([.serbianLatin, .english], .serbianLatin), "Serbian has no dictionary to check")
XCTAssertNil(partner([.english, .serbianLatin], .english))
XCTAssertNil(partner([.ukrainian, .english], .ukrainian), "Cyrillic has no bilingual partner")
XCTAssertNil(partner([.english, .ukrainian], .english))
XCTAssertNil(partner([.english], .english))
}
/// Settings › Keyboard › Languages offers the iPhone's own keyboards first, then its
/// languages; Switch dictation too dictates in the iPhone's region where it has one.
func testLanguagesOfferTheIPhonesKeyboardsAndDictateInItsRegion() {
XCTAssertEqual(
KeyboardLanguage.suggested(inputModes: ["en-GB", "emoji", "fr-FR", "en-US"], preferred: ["ru-RU", "fr-CA", "he-IL"]),
[.english, .french, .russian, .frenchCanadian]
)
let supported = ["en-US", "en-GB", "fr-FR", "fr-CA", "ru-RU", "nb-NO", "pt-BR", "pt-PT"]
XCTAssertEqual(KeyboardLanguage.english.dictationLanguage(supported: supported, preferred: ["en-GB", "fr-FR"]), "en-GB")
XCTAssertEqual(KeyboardLanguage.english.dictationLanguage(supported: supported, preferred: ["fr-FR"]), "en-US")
XCTAssertEqual(KeyboardLanguage.french.dictationLanguage(supported: supported, preferred: ["en-GB"]), "fr-FR")
XCTAssertEqual(KeyboardLanguage.frenchCanadian.dictationLanguage(supported: supported, preferred: ["fr-FR"]), "fr-CA")
XCTAssertEqual(KeyboardLanguage.portuguese.dictationLanguage(supported: supported, preferred: ["pt-PT"]), "pt-PT")
XCTAssertEqual(KeyboardLanguage.norwegian.dictationLanguage(supported: supported, preferred: ["nn-NO"]), "nb-NO")
XCTAssertNil(KeyboardLanguage.serbianLatin.dictationLanguage(supported: supported, preferred: ["sr-Latn-RS"]))
XCTAssertNil(KeyboardLanguage.german.dictationLanguage(supported: supported, preferred: []), "Apple Speech has no German here")
XCTAssertEqual(KeyboardLanguage.german.dictationLanguage(supported: [], preferred: []), "de-DE", "not listed yet")
XCTAssertEqual(
KeyboardLanguage.suggested(inputModes: ["uk-UA", "emoji", "en-US"], preferred: ["uk-UA", "ru-RU"]),
[.ukrainian, .english, .russian]
)
XCTAssertEqual(KeyboardLanguage.ukrainian.dictationLanguage(supported: supported + ["uk-UA"], preferred: ["uk-UA"]), "uk-UA")
XCTAssertNil(KeyboardLanguage.ukrainian.dictationLanguage(supported: supported, preferred: []), "not Russian instead")
XCTAssertEqual(KeyboardLanguage.ukrainian.dictationLanguage(supported: [], preferred: []), "uk-UA", "not listed yet")
}
/// The languages read the one layout chosen before them, and write their first for an
/// older build.
func testLanguagesReadTheOneLayoutChosenBefore() {
let suite = "KeyboardLayoutTests-\(UUID().uuidString)"
let defaults = UserDefaults(suiteName: suite)!
defer { defaults.removePersistentDomain(forName: suite) }
let settings = LanguageSettings(defaults: defaults)
XCTAssertEqual(settings.keyboardLanguages, [], "Automatic")
defaults.set("fr-CA", forKey: "settings.keyboardLayout")
XCTAssertEqual(settings.keyboardLanguages, [.frenchCanadian])
settings.keyboardLanguages = [.english, .french, .english]
XCTAssertEqual(settings.keyboardLanguages, [.english, .french])
XCTAssertEqual(defaults.string(forKey: "settings.keyboardLayout"), "en")
settings.keyboardLanguages = []
XCTAssertEqual(settings.keyboardLanguages, [])
XCTAssertNil(defaults.string(forKey: "settings.keyboardLayout"))
XCTAssertFalse(settings.dictationFollowsKeyboard, "off by default")
}
func testSpellCheckUsesTheLayoutsLanguageOrNone() {
XCTAssertEqual(KeyboardLanguage.norwegian.spellCheckLanguage(available: ["en_US", "nb"]), "nb")
XCTAssertNil(KeyboardLanguage.norwegian.spellCheckLanguage(available: ["en_US", "da"]))
XCTAssertEqual(KeyboardLanguage.german.spellCheckLanguage(available: ["de"]), "de")
XCTAssertEqual(KeyboardLanguage.italian.spellCheckLanguage(available: ["en_US", "it_IT"]), "it_IT")
XCTAssertEqual(KeyboardLanguage.french.spellCheckLanguage(available: ["en_US", "fr_FR"]), "fr_FR")
XCTAssertEqual(KeyboardLanguage.frenchCanadian.spellCheckLanguage(available: ["fr_FR", "fr_CA"]), "fr_CA")
XCTAssertEqual(KeyboardLanguage.frenchCanadian.spellCheckLanguage(available: ["en_US", "fr_FR"]), "fr_FR")
XCTAssertEqual(KeyboardLanguage.frenchSwiss.spellCheckLanguage(available: ["en_US", "fr_FR"]), "fr_FR")
XCTAssertEqual(KeyboardLanguage.portuguese.spellCheckLanguage(available: ["pt_PT", "pt_BR"]), "pt_BR")
XCTAssertNil(KeyboardLanguage.italian.spellCheckLanguage(available: ["en_US", "es"]), "never English")
XCTAssertEqual(KeyboardLanguage.russian.spellCheckLanguage(available: ["en_US", "ru_RU"]), "ru_RU")
XCTAssertNil(KeyboardLanguage.russian.spellCheckLanguage(available: ["en_US", "uk_UA"]), "never English")
XCTAssertEqual(KeyboardLanguage.ukrainian.spellCheckLanguage(available: ["en_US", "ru_RU", "uk_UA"]), "uk_UA")
XCTAssertNil(KeyboardLanguage.ukrainian.spellCheckLanguage(available: ["en_US", "ru_RU"]), "never Russian or English")
XCTAssertEqual(KeyboardLanguage.spellCheckLanguage(forDictation: "uk-UA", available: ["en_US", "uk_UA"]), "uk_UA")
XCTAssertEqual(KeyboardLanguage.serbianLatin.spellCheckLanguage(available: ["en_US", "sr_Latn"]), "sr_Latn")
XCTAssertNil(KeyboardLanguage.serbianLatin.spellCheckLanguage(available: ["en_US", "sr", "hr_HR"]), "no Cyrillic or Croatian")
}
// MARK: - Helpers
private func landscapeLayouts() -> [KeyboardLayout] {
[
KeyboardLayout(width: 667, orientation: .landscape),
KeyboardLayout(width: 852, orientation: .landscape, layer: .numbers),
KeyboardLayout(width: 956, orientation: .landscape, field: .email, horizontalInset: 60),
] + KeyboardLanguage.allCases.flatMap { language in
[
KeyboardLayout(width: 667, orientation: .landscape, language: language),
KeyboardLayout(width: 956, orientation: .landscape, showsGlobe: true, horizontalInset: 60, language: language),
]
}
}
/// The iPhone Duo's keyboard views (iOS 27.2 simulator): 452 pt of the 466 pt cover screen
/// folded, 655 of 669 pt unfolded and turned, 801 of 951 pt unfolded upright, and 528 of
/// 678 pt folded in landscape.
private func duoLayouts() -> [KeyboardLayout] {
var layouts: [KeyboardLayout] = []
for (width, posture, inset) in [(452.0, KeyboardPosture.cover, 7.0), (655, .unfoldedTall, 7), (801, .unfoldedWide, 75)] {
for layer in layers {
for field in fields {
layouts.append(KeyboardLayout(width: width, layer: layer, field: field, showsGlobe: true, posture: posture, windowInset: inset))
}
}
for language in KeyboardLanguage.allCases {
layouts.append(KeyboardLayout(width: width, language: language, posture: posture, windowInset: inset))
}
}
layouts.append(KeyboardLayout(width: 528, orientation: .landscape, posture: .cover, windowInset: 75))
layouts.append(KeyboardLayout(width: 528, orientation: .landscape, showsGlobe: true, posture: .cover, windowInset: 75))
return layouts
}
private func letters(_ layout: KeyboardLayout, row: Int) -> [String] {
layout.keys.filter { $0.row == row && $0.character != nil }
.sorted { $0.frame.minX < $1.frame.minX }
.compactMap(\.character)
}
private func bottomRow(_ layout: KeyboardLayout) -> [KeyKind] {
layout.keys.filter { $0.row == 3 }.sorted { $0.frame.minX < $1.frame.minX }.map(\.kind)
}
private func describe(_ layout: KeyboardLayout) -> String {
"\(layout.width)pt \(layout.orientation) \(layout.layer) \(layout.field) globe=\(layout.showsGlobe) \(layout.language) \(layout.posture)"
}
}
@MainActor
final class FullKeyboardSettingsTests: XCTestCase {
func testFullKeyboardAndAutocorrectAreOnByDefault() throws {
let suite = "FullKeyboardSettingsTests-\(UUID().uuidString)"
let defaults = try XCTUnwrap(UserDefaults(suiteName: suite))
defer { defaults.removePersistentDomain(forName: suite) }
let settings = FullKeyboardSettings(defaults: defaults)
XCTAssertTrue(settings.isEnabled)
XCTAssertTrue(settings.autocorrect)
settings.applyLaunchArguments(["HEX"])
XCTAssertTrue(settings.isEnabled)
settings.applyLaunchArguments(["HEX", FullKeyboardSettings.keyboardLaunchArgument, "dictation-bar"])
XCTAssertFalse(settings.isEnabled)
settings.applyLaunchArguments(["HEX", FullKeyboardSettings.launchArgument])
XCTAssertTrue(settings.isEnabled)
settings.autocorrect = false
XCTAssertFalse(FullKeyboardSettings(defaults: defaults).autocorrect)
}
func testHexKeyIsOnTheRightByDefault() throws {
let suite = "FullKeyboardSettingsTests-\(UUID().uuidString)"
let defaults = try XCTUnwrap(UserDefaults(suiteName: suite))
defer { defaults.removePersistentDomain(forName: suite) }
let settings = FullKeyboardSettings(defaults: defaults)
XCTAssertFalse(settings.hexKeyOnLeft)
XCTAssertEqual(settings.hexKeyPlacement, .stripTrailing)
XCTAssertEqual(FullKeyboardSettings(defaults: nil).hexKeyPlacement, .stripTrailing, "without the App Group")
settings.hexKeyOnLeft = true
XCTAssertEqual(FullKeyboardSettings(defaults: defaults).hexKeyPlacement, .stripLeading)
settings.applyLaunchArguments(["HEX", FullKeyboardSettings.hexKeyLaunchArgument, "right"])
XCTAssertFalse(settings.hexKeyOnLeft)
settings.applyLaunchArguments(["HEX", FullKeyboardSettings.hexKeyLaunchArgument, "left"])
XCTAssertTrue(settings.hexKeyOnLeft)
}
/// Testers who turned the full keyboard experiment off chose the dictation bar and keep
/// it; those who never touched it (unset) get the full keyboard.
func testExplicitlyOffKeepsTheDictationBar() throws {
let suite = "FullKeyboardSettingsTests-\(UUID().uuidString)"
let defaults = try XCTUnwrap(UserDefaults(suiteName: suite))
defer { defaults.removePersistentDomain(forName: suite) }
defaults.set(false, forKey: "experiments.fullKeyboard")
XCTAssertFalse(FullKeyboardSettings(defaults: defaults).isEnabled)
defaults.set(true, forKey: "experiments.fullKeyboard")
XCTAssertTrue(FullKeyboardSettings(defaults: defaults).isEnabled)
FullKeyboardSettings(defaults: defaults).isEnabled = false
XCTAssertEqual(defaults.object(forKey: "experiments.fullKeyboard") as? Bool, false)
}
/// Without Full Access the keyboard reads no App Group: the full keyboard, which types.
func testNoAppGroupReadsAsFullKeyboard() {
XCTAssertTrue(FullKeyboardSettings(defaults: nil).isEnabled)
}
/// Swipe typing and Emoji are on by default: an unset key (a fresh install, or a tester
/// who never touched the old experiments) is on, a stored off stays off, and the keyboard
/// without the App Group reads them as on.
func testSwipeTypingAndEmojiAreOnByDefaultAndAStoredOffStaysOff() throws {
let suite = "FullKeyboardSettingsTests-\(UUID().uuidString)"
let defaults = try XCTUnwrap(UserDefaults(suiteName: suite))
defer { defaults.removePersistentDomain(forName: suite) }
let fresh = FullKeyboardSettings(defaults: defaults)
XCTAssertTrue(fresh.swipeTyping)
XCTAssertTrue(fresh.emoji)
XCTAssertNil(defaults.object(forKey: "experiments.swipeTyping"), "reading writes nothing")
XCTAssertNil(defaults.object(forKey: "experiments.emoji"))
XCTAssertTrue(FullKeyboardSettings(defaults: nil).swipeTyping, "without the App Group")
XCTAssertTrue(FullKeyboardSettings(defaults: nil).emoji)
defaults.set(false, forKey: "experiments.swipeTyping")
defaults.set(false, forKey: "experiments.emoji")
XCTAssertFalse(FullKeyboardSettings(defaults: defaults).swipeTyping, "an upgrade that turned it off")
XCTAssertFalse(FullKeyboardSettings(defaults: defaults).emoji)
fresh.applyLaunchArguments(["HEX"])
XCTAssertFalse(fresh.swipeTyping, "no launch argument leaves a stored off")
fresh.applyLaunchArguments(["HEX", FullKeyboardSettings.swipeLaunchArgument, FullKeyboardSettings.emojiLaunchArgument])
XCTAssertTrue(fresh.swipeTyping)
XCTAssertTrue(fresh.emoji)
fresh.swipeTyping = false
XCTAssertEqual(defaults.object(forKey: "experiments.swipeTyping") as? Bool, false)
}
}