Adds tests.
This commit is contained in:
parent
063164d0ab
commit
9c8d740fc6
|
@ -60,6 +60,7 @@
|
||||||
D485D3B92796A8A000657FF3 /* PreferencesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3B82796A8A000657FF3 /* PreferencesTests.swift */; };
|
D485D3B92796A8A000657FF3 /* PreferencesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3B82796A8A000657FF3 /* PreferencesTests.swift */; };
|
||||||
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */; };
|
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */; };
|
||||||
D4A13D5A27A59F0B003BE359 /* InputMethodController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A13D5927A59D5C003BE359 /* InputMethodController.swift */; };
|
D4A13D5A27A59F0B003BE359 /* InputMethodController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A13D5927A59D5C003BE359 /* InputMethodController.swift */; };
|
||||||
|
D4A8E43627A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A8E43527A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift */; };
|
||||||
D4E33D8A27A838CF006DB1CF /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8827A838CF006DB1CF /* Localizable.strings */; };
|
D4E33D8A27A838CF006DB1CF /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8827A838CF006DB1CF /* Localizable.strings */; };
|
||||||
D4E33D8F27A838F0006DB1CF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8D27A838F0006DB1CF /* InfoPlist.strings */; };
|
D4E33D8F27A838F0006DB1CF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8D27A838F0006DB1CF /* InfoPlist.strings */; };
|
||||||
D4E569DC27A34D0E00AC2CEF /* KeyHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = D4E569DB27A34CC100AC2CEF /* KeyHandler.mm */; };
|
D4E569DC27A34D0E00AC2CEF /* KeyHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = D4E569DB27A34CC100AC2CEF /* KeyHandler.mm */; };
|
||||||
|
@ -218,6 +219,7 @@
|
||||||
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionUpdateTests.swift; sourceTree = "<group>"; };
|
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionUpdateTests.swift; sourceTree = "<group>"; };
|
||||||
D495583A27A5C6C4006ADE1C /* LanguageModelManager+Privates.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LanguageModelManager+Privates.h"; sourceTree = "<group>"; };
|
D495583A27A5C6C4006ADE1C /* LanguageModelManager+Privates.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LanguageModelManager+Privates.h"; sourceTree = "<group>"; };
|
||||||
D4A13D5927A59D5C003BE359 /* InputMethodController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMethodController.swift; sourceTree = "<group>"; };
|
D4A13D5927A59D5C003BE359 /* InputMethodController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMethodController.swift; sourceTree = "<group>"; };
|
||||||
|
D4A8E43527A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHandlerPlainBopomofoTests.swift; sourceTree = "<group>"; };
|
||||||
D4E33D8927A838CF006DB1CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
|
D4E33D8927A838CF006DB1CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||||
D4E33D8B27A838D5006DB1CF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
|
D4E33D8B27A838D5006DB1CF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||||
D4E33D8C27A838D8006DB1CF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
|
D4E33D8C27A838D8006DB1CF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
|
||||||
|
@ -501,6 +503,7 @@
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
D47D73A327A5D43900255A50 /* KeyHandlerBopomofoTests.swift */,
|
D47D73A327A5D43900255A50 /* KeyHandlerBopomofoTests.swift */,
|
||||||
|
D4A8E43527A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift */,
|
||||||
D485D3B82796A8A000657FF3 /* PreferencesTests.swift */,
|
D485D3B82796A8A000657FF3 /* PreferencesTests.swift */,
|
||||||
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */,
|
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */,
|
||||||
);
|
);
|
||||||
|
@ -754,6 +757,7 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
D4A8E43627A9E982002F7A07 /* KeyHandlerPlainBopomofoTests.swift in Sources */,
|
||||||
D47D73A427A5D43900255A50 /* KeyHandlerBopomofoTests.swift in Sources */,
|
D47D73A427A5D43900255A50 /* KeyHandlerBopomofoTests.swift in Sources */,
|
||||||
D485D3B92796A8A000657FF3 /* PreferencesTests.swift in Sources */,
|
D485D3B92796A8A000657FF3 /* PreferencesTests.swift in Sources */,
|
||||||
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */,
|
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */,
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
import XCTest
|
||||||
|
@testable import McBopomofo
|
||||||
|
|
||||||
|
class KeyHandlerPlainBopomofoTests: XCTestCase {
|
||||||
|
var handler = KeyHandler()
|
||||||
|
|
||||||
|
override func setUpWithError() throws {
|
||||||
|
LanguageModelManager.loadDataModels()
|
||||||
|
handler = KeyHandler()
|
||||||
|
handler.inputMode = .plainBopomofo
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tearDownWithError() throws {
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPunctuationComma() {
|
||||||
|
let input = KeyHandlerInput(inputText: "<", keyCode: 0, charCode: charCode("<"), flags: .shift, isVerticalMode: false)
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
|
||||||
|
if let state = state as? InputState.ChoosingCandidate {
|
||||||
|
XCTAssertEqual(state.composingBuffer, ",")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPunctuationPeriod() {
|
||||||
|
let input = KeyHandlerInput(inputText: ">", keyCode: 0, charCode: charCode(">"), flags: .shift, isVerticalMode: false)
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
|
||||||
|
if let state = state as? InputState.ChoosingCandidate {
|
||||||
|
XCTAssertEqual(state.composingBuffer, "。")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInputNe() {
|
||||||
|
let input = KeyHandlerInput(inputText: "s", keyCode: 0, charCode: charCode("s"), flags: .shift, isVerticalMode: false)
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||||
|
if let state = state as? InputState.Inputting {
|
||||||
|
XCTAssertEqual(state.composingBuffer, "ㄋ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInputNi() {
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
let keys = Array("su").map { String($0) }
|
||||||
|
for key in keys {
|
||||||
|
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||||
|
if let state = state as? InputState.Inputting {
|
||||||
|
XCTAssertEqual(state.composingBuffer, "ㄋㄧ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInputNi3() {
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
let keys = Array("su3").map { String($0) }
|
||||||
|
for key in keys {
|
||||||
|
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
|
||||||
|
if let state = state as? InputState.ChoosingCandidate {
|
||||||
|
XCTAssertTrue(state.candidates.contains("你"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCancelCandidateUsingDelete() {
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
let keys = Array("su3").map { String($0) }
|
||||||
|
for key in keys {
|
||||||
|
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = KeyHandlerInput(inputText: " ", keyCode: KeyCode.delete.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.EmptyIgnoringPreviousState, "\(state)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCancelCandidateUsingEsc() {
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
let keys = Array("su3").map { String($0) }
|
||||||
|
for key in keys {
|
||||||
|
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = KeyHandlerInput(inputText: " ", keyCode: 0, charCode: 27, flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.EmptyIgnoringPreviousState, "\(state)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAssociatedPhrases() {
|
||||||
|
let enabled = Preferences.associatedPhrasesEnabled
|
||||||
|
Preferences.associatedPhrasesEnabled = true
|
||||||
|
var state: InputState = InputState.Empty()
|
||||||
|
let keys = Array("aul ").map { String($0) }
|
||||||
|
for key in keys {
|
||||||
|
let input = KeyHandlerInput(inputText: key, keyCode: 0, charCode: charCode(key), flags: [], isVerticalMode: false)
|
||||||
|
handler.handle(input, state: state) { newState in
|
||||||
|
state = newState
|
||||||
|
} candidateSelectionCallback: {
|
||||||
|
} errorCallback: {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(state is InputState.AssociatedPhrases, "\(state)")
|
||||||
|
if let state = state as? InputState.AssociatedPhrases {
|
||||||
|
XCTAssertTrue(state.candidates.contains("嗚"))
|
||||||
|
}
|
||||||
|
Preferences.associatedPhrasesEnabled = enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -3,12 +3,37 @@ import XCTest
|
||||||
|
|
||||||
class PreferencesTests: XCTestCase {
|
class PreferencesTests: XCTestCase {
|
||||||
|
|
||||||
|
func reset() {
|
||||||
|
Preferences.allKeys.forEach {
|
||||||
|
UserDefaults.standard.removeObject(forKey: $0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeSnapshot() -> [String: Any] {
|
||||||
|
var dict = [String: Any]()
|
||||||
|
Preferences.allKeys.forEach {
|
||||||
|
dict[$0] = UserDefaults.standard.object(forKey: $0)
|
||||||
|
}
|
||||||
|
return dict
|
||||||
|
}
|
||||||
|
|
||||||
|
func restore(from snapshot:[String: Any]) {
|
||||||
|
Preferences.allKeys.forEach {
|
||||||
|
UserDefaults.standard.set(snapshot[$0], forKey: $0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var snapshot: [String: Any]?
|
||||||
|
|
||||||
override func setUpWithError() throws {
|
override func setUpWithError() throws {
|
||||||
Preferences.reset()
|
snapshot = makeSnapshot()
|
||||||
|
reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tearDownWithError() throws {
|
override func tearDownWithError() throws {
|
||||||
Preferences.reset()
|
if let snapshot = snapshot {
|
||||||
|
restore(from: snapshot)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testKeyboardLayout() {
|
func testKeyboardLayout() {
|
||||||
|
|
|
@ -198,29 +198,29 @@ struct ComposingBufferSize {
|
||||||
// MARK: -
|
// MARK: -
|
||||||
|
|
||||||
class Preferences: NSObject {
|
class Preferences: NSObject {
|
||||||
static func reset() {
|
static var allKeys:[String] {
|
||||||
let defaults = UserDefaults.standard
|
[kKeyboardLayoutPreferenceKey,
|
||||||
defaults.removeObject(forKey: kKeyboardLayoutPreferenceKey)
|
kBasisKeyboardLayoutPreferenceKey,
|
||||||
defaults.removeObject(forKey: kBasisKeyboardLayoutPreferenceKey)
|
kFunctionKeyKeyboardLayoutPreferenceKey,
|
||||||
defaults.removeObject(forKey: kFunctionKeyKeyboardLayoutPreferenceKey)
|
kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey,
|
||||||
defaults.removeObject(forKey: kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey)
|
kCandidateListTextSizeKey,
|
||||||
defaults.removeObject(forKey: kCandidateListTextSizeKey)
|
kSelectPhraseAfterCursorAsCandidatePreferenceKey,
|
||||||
defaults.removeObject(forKey: kSelectPhraseAfterCursorAsCandidatePreferenceKey)
|
kUseHorizontalCandidateListPreferenceKey,
|
||||||
defaults.removeObject(forKey: kUseHorizontalCandidateListPreferenceKey)
|
kComposingBufferSizePreferenceKey,
|
||||||
defaults.removeObject(forKey: kComposingBufferSizePreferenceKey)
|
kChooseCandidateUsingSpaceKey,
|
||||||
defaults.removeObject(forKey: kChooseCandidateUsingSpaceKey)
|
kChineseConversionEnabledKey,
|
||||||
defaults.removeObject(forKey: kChineseConversionEnabledKey)
|
kHalfWidthPunctuationEnabledKey,
|
||||||
defaults.removeObject(forKey: kHalfWidthPunctuationEnabledKey)
|
kEscToCleanInputBufferKey,
|
||||||
defaults.removeObject(forKey: kEscToCleanInputBufferKey)
|
kCandidateTextFontName,
|
||||||
defaults.removeObject(forKey: kCandidateTextFontName)
|
kCandidateKeyLabelFontName,
|
||||||
defaults.removeObject(forKey: kCandidateKeyLabelFontName)
|
kCandidateKeys,
|
||||||
defaults.removeObject(forKey: kCandidateKeys)
|
kPhraseReplacementEnabledKey,
|
||||||
defaults.removeObject(forKey: kPhraseReplacementEnabledKey)
|
kChineseConversionEngineKey,
|
||||||
defaults.removeObject(forKey: kChineseConversionEngineKey)
|
kChineseConversionStyle,
|
||||||
defaults.removeObject(forKey: kChineseConversionStyle)
|
kAssociatedPhrasesEnabledKey]
|
||||||
defaults.removeObject(forKey: kAssociatedPhrasesEnabledKey)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@UserDefault(key: kKeyboardLayoutPreferenceKey, defaultValue: 0)
|
@UserDefault(key: kKeyboardLayoutPreferenceKey, defaultValue: 0)
|
||||||
@objc static var keyboardLayout: Int
|
@objc static var keyboardLayout: Int
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue