hex/ios/HEXMobileTests/KeyboardCoreLinkTests.swift
Sebastian Herrlinger e9ed297161 iOS keyboard: autocorrect runs on the Rust core
AutocorrectEngine keeps its Swift API and decides nothing itself: every suggestion,
replacement, revision and answer about a word is the core's (hk_autocorrect_*), with
the spelling dictionary behind a callback (KeyboardCoreChecker over TextChecking, so
SystemTextChecker and Hex's own words stay as they are) and your lexicon, vocabulary,
learning and settings handed over as plain data. LearnedWordsStore stays on disk here:
before each call the engine hands the core the kept words of a list that is another
one, or changed (its new revision). The letter grid goes over from
KeyboardLanguage.keyCoordinates whenever the layout language or letters change.

OffensiveWords and GermanCapitals are the core's lists (hk_never_suggest_*,
hk_german_capitals_*). The bundled never-suggest.tsv is Android's, the union of both
apps' lists (decided: French and Italian rows on iOS too, read by base language).
Swift's copies of what moved go: the starters, common and two-letter words, accents,
dictionary codes (spellCheckCandidates reads the manifest), typo and contraction
lists, and the decision logic (AutocorrectEngine+Accents, +Dictionaries and
+Vocabulary). KeyboardCoreLinkTests checks every keyboard language has a manifest.
2026-11-23 07:42:38 +01:00

27 lines
1.1 KiB
Swift

import HexKeyboardCore
import XCTest
@testable import HEX
/// The keyboard's Rust core (`crates/keyboard`) links into the app and opens the model the
/// keyboard ships.
@MainActor
final class KeyboardCoreLinkTests: XCTestCase {
func testTheCoreIsTheHeadersVersion() {
XCTAssertEqual(hk_abi_version(), UInt32(HK_ABI_VERSION))
for language in KeyboardLanguage.allCases {
XCTAssertEqual(hk_text_is(4, nil, nil, language.rawValue), 1, "the core has \(language.rawValue)'s language manifest")
}
}
func testTheCoreOpensTheBundledEnglishModel() throws {
let model = try XCTUnwrap(TypingDecoderModel.bundled("en"), "the English model is bundled")
let core = try XCTUnwrap(KeyboardCoreModel(url: model.url))
XCTAssertEqual(core.wordCount, 86_247)
XCTAssertEqual(model.core?.wordCount, model.wordCount)
XCTAssertTrue(model.core === model.core, "opened once")
}
func testTheCoreOpensNothingWhereThereIsNoModel() {
XCTAssertNil(KeyboardCoreModel(url: URL(fileURLWithPath: "/nonexistent/en.hextm")))
}
}