Converts test cases to Swift.
This commit is contained in:
parent
bce641608b
commit
0b1975bfeb
|
@ -7,7 +7,6 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
6A0D4EA715FC0D2D00ABF4B3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */; };
|
||||
6A0D4F0815FC0DA600ABF4B3 /* Bopomofo.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 6A0D4EEF15FC0DA600ABF4B3 /* Bopomofo.tiff */; };
|
||||
6A0D4F0915FC0DA600ABF4B3 /* Bopomofo@2x.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 6A0D4EF015FC0DA600ABF4B3 /* Bopomofo@2x.tiff */; };
|
||||
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4F2015FC0EB100ABF4B3 /* Mandarin.cpp */; };
|
||||
|
@ -19,12 +18,10 @@
|
|||
6A2E40F6253A69DA00D1AE1D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */; };
|
||||
6A2E40F9253A6AA000D1AE1D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */; };
|
||||
6A38BC1515FC117A00A8A51F /* data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A38BBF615FC117A00A8A51F /* data.txt */; };
|
||||
6A38BC2815FC158A00A8A51F /* InputMethodKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A38BC2715FC158A00A8A51F /* InputMethodKit.framework */; };
|
||||
6A6ED16B2797650A0012872E /* template-phrases-replacement.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1632797650A0012872E /* template-phrases-replacement.txt */; };
|
||||
6A6ED16C2797650A0012872E /* template-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1652797650A0012872E /* template-data.txt */; };
|
||||
6A6ED16D2797650A0012872E /* template-exclude-phrases-plain-bpmf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1672797650A0012872E /* template-exclude-phrases-plain-bpmf.txt */; };
|
||||
6A6ED16E2797650A0012872E /* template-exclude-phrases.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1692797650A0012872E /* template-exclude-phrases.txt */; };
|
||||
6ACA41CD15FC1D7500935EF6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */; };
|
||||
6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EA15FC1D9000935EF6 /* InfoPlist.strings */; };
|
||||
6ACA41FB15FC1D9000935EF6 /* License.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EC15FC1D9000935EF6 /* License.rtf */; };
|
||||
6ACA41FC15FC1D9000935EF6 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EE15FC1D9000935EF6 /* Localizable.strings */; };
|
||||
|
@ -53,6 +50,7 @@
|
|||
D456576E279E4F7B00DF6BC9 /* KeyHandlerInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = D456576D279E4F7B00DF6BC9 /* KeyHandlerInput.swift */; };
|
||||
D461B792279DAC010070E734 /* InputState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D461B791279DAC010070E734 /* InputState.swift */; };
|
||||
D47B92C027972AD100458394 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47B92BF27972AC800458394 /* main.swift */; };
|
||||
D47D73A427A5D43900255A50 /* KeyHandlerBopomofoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47D73A327A5D43900255A50 /* KeyHandlerBopomofoTests.swift */; };
|
||||
D47F7DCE278BFB57002F9DD7 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DCD278BFB57002F9DD7 /* PreferencesWindowController.swift */; };
|
||||
D47F7DD0278C0897002F9DD7 /* NonModalAlertWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DCF278C0897002F9DD7 /* NonModalAlertWindowController.swift */; };
|
||||
D47F7DD3278C1263002F9DD7 /* UserOverrideModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DD2278C1263002F9DD7 /* UserOverrideModel.cpp */; };
|
||||
|
@ -60,10 +58,6 @@
|
|||
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */; };
|
||||
D4A13D5A27A59F0B003BE359 /* InputMethodController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A13D5927A59D5C003BE359 /* InputMethodController.swift */; };
|
||||
D4E569DC27A34D0E00AC2CEF /* KeyHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = D4E569DB27A34CC100AC2CEF /* KeyHandler.mm */; };
|
||||
D4E569DF27A40F1400AC2CEF /* KeyHandlerBopomofoTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = D4E569DE27A40F1400AC2CEF /* KeyHandlerBopomofoTests.mm */; };
|
||||
D4E569E027A4123200AC2CEF /* KeyHandlerInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = D456576D279E4F7B00DF6BC9 /* KeyHandlerInput.swift */; };
|
||||
D4E569E127A4128300AC2CEF /* InputState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D461B791279DAC010070E734 /* InputState.swift */; };
|
||||
D4E569E227A412E700AC2CEF /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = D44FB74427915555003C80A6 /* Preferences.swift */; };
|
||||
D4E569E427A414CB00AC2CEF /* data-plain-bpmf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6AD7CBC715FE555000691B5B /* data-plain-bpmf.txt */; };
|
||||
D4E569E527A414CB00AC2CEF /* data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A38BBF615FC117A00A8A51F /* data.txt */; };
|
||||
D4F0BBDF279AF1AF0071253C /* ArchiveUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F0BBDE279AF1AF0071253C /* ArchiveUtil.swift */; };
|
||||
|
@ -98,9 +92,6 @@
|
|||
|
||||
/* Begin PBXFileReference section */
|
||||
6A0D4EA215FC0D2D00ABF4B3 /* McBopomofo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = McBopomofo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
|
||||
6A0D4EA915FC0D2D00ABF4B3 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
|
||||
6A0D4EAB15FC0D2D00ABF4B3 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
6A0D4EEF15FC0DA600ABF4B3 /* Bopomofo.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = Bopomofo.tiff; sourceTree = "<group>"; };
|
||||
6A0D4EF015FC0DA600ABF4B3 /* Bopomofo@2x.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "Bopomofo@2x.tiff"; sourceTree = "<group>"; };
|
||||
6A0D4EF515FC0DA600ABF4B3 /* McBopomofo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "McBopomofo-Info.plist"; sourceTree = "<group>"; };
|
||||
|
@ -162,7 +153,6 @@
|
|||
6A225A1E23679F2600F685C6 /* NotarizedArchives */ = {isa = PBXFileReference; lastKnownFileType = folder; path = NotarizedArchives; sourceTree = "<group>"; };
|
||||
6A2E40F5253A69DA00D1AE1D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
||||
6A38BBF615FC117A00A8A51F /* data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = data.txt; sourceTree = "<group>"; };
|
||||
6A38BC2715FC158A00A8A51F /* InputMethodKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = InputMethodKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/InputMethodKit.framework; sourceTree = DEVELOPER_DIR; };
|
||||
6A6ED1642797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-phrases-replacement.txt"; sourceTree = "<group>"; };
|
||||
6A6ED1662797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-data.txt"; sourceTree = "<group>"; };
|
||||
6A6ED1682797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-exclude-phrases-plain-bpmf.txt"; sourceTree = "<group>"; };
|
||||
|
@ -212,6 +202,7 @@
|
|||
D456576D279E4F7B00DF6BC9 /* KeyHandlerInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHandlerInput.swift; sourceTree = "<group>"; };
|
||||
D461B791279DAC010070E734 /* InputState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputState.swift; sourceTree = "<group>"; };
|
||||
D47B92BF27972AC800458394 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||
D47D73A327A5D43900255A50 /* KeyHandlerBopomofoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHandlerBopomofoTests.swift; sourceTree = "<group>"; };
|
||||
D47F7DCD278BFB57002F9DD7 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
|
||||
D47F7DCF278C0897002F9DD7 /* NonModalAlertWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonModalAlertWindowController.swift; sourceTree = "<group>"; };
|
||||
D47F7DD1278C1263002F9DD7 /* UserOverrideModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserOverrideModel.h; sourceTree = "<group>"; };
|
||||
|
@ -223,8 +214,6 @@
|
|||
D4A13D5927A59D5C003BE359 /* InputMethodController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMethodController.swift; sourceTree = "<group>"; };
|
||||
D4E569DA27A34CC100AC2CEF /* KeyHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyHandler.h; sourceTree = "<group>"; };
|
||||
D4E569DB27A34CC100AC2CEF /* KeyHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyHandler.mm; sourceTree = "<group>"; };
|
||||
D4E569DD27A40F1300AC2CEF /* McBopomofoTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "McBopomofoTests-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
D4E569DE27A40F1400AC2CEF /* KeyHandlerBopomofoTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyHandlerBopomofoTests.mm; sourceTree = "<group>"; };
|
||||
D4F0BBDE279AF1AF0071253C /* ArchiveUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArchiveUtil.swift; sourceTree = "<group>"; };
|
||||
D4F0BBE0279AF8B30071253C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
D4F0BBE2279B08900071253C /* BundleTranslocate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BundleTranslocate.h; sourceTree = "<group>"; };
|
||||
|
@ -242,11 +231,9 @@
|
|||
D427F7B4279086DC004A2160 /* InputSourceHelper in Frameworks */,
|
||||
D427F7C127908EFC004A2160 /* OpenCCBridge in Frameworks */,
|
||||
D44FB74A2791B829003C80A6 /* VXHanConvert in Frameworks */,
|
||||
6A38BC2815FC158A00A8A51F /* InputMethodKit.framework in Frameworks */,
|
||||
D427F7A927905E90004A2160 /* TooltipUI in Frameworks */,
|
||||
D427F76A278C9E29004A2160 /* CandidateUI in Frameworks */,
|
||||
D427F7AE27907B8A004A2160 /* NotifierUI in Frameworks */,
|
||||
6A0D4EA715FC0D2D00ABF4B3 /* Cocoa.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -255,7 +242,6 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D427F7B6279086F6004A2160 /* InputSourceHelper in Frameworks */,
|
||||
6ACA41CD15FC1D7500935EF6 /* Cocoa.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -275,7 +261,6 @@
|
|||
D427F766278C9CBD004A2160 /* Packages */,
|
||||
6A0D4EC215FC0D3C00ABF4B3 /* Source */,
|
||||
D485D3B72796A8A000657FF3 /* McBopomofoTests */,
|
||||
6A0D4EA515FC0D2D00ABF4B3 /* Frameworks */,
|
||||
6A0D4EA315FC0D2D00ABF4B3 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
|
@ -290,17 +275,6 @@
|
|||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
6A0D4EA515FC0D2D00ABF4B3 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6A0D4EA915FC0D2D00ABF4B3 /* AppKit.framework */,
|
||||
6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */,
|
||||
6A0D4EAB15FC0D2D00ABF4B3 /* Foundation.framework */,
|
||||
6A38BC2715FC158A00A8A51F /* InputMethodKit.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
6A0D4EC215FC0D3C00ABF4B3 /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -500,10 +474,9 @@
|
|||
D485D3B72796A8A000657FF3 /* McBopomofoTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D47D73A327A5D43900255A50 /* KeyHandlerBopomofoTests.swift */,
|
||||
D485D3B82796A8A000657FF3 /* PreferencesTests.swift */,
|
||||
D485D3BF2796CE3200657FF3 /* VersionUpdateTests.swift */,
|
||||
D4E569DE27A40F1400AC2CEF /* KeyHandlerBopomofoTests.mm */,
|
||||
D4E569DD27A40F1300AC2CEF /* McBopomofoTests-Bridging-Header.h */,
|
||||
);
|
||||
path = McBopomofoTests;
|
||||
sourceTree = "<group>";
|
||||
|
@ -750,12 +723,9 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D4E569DF27A40F1400AC2CEF /* KeyHandlerBopomofoTests.mm in Sources */,
|
||||
D47D73A427A5D43900255A50 /* KeyHandlerBopomofoTests.swift in Sources */,
|
||||
D485D3B92796A8A000657FF3 /* PreferencesTests.swift in Sources */,
|
||||
D4E569E227A412E700AC2CEF /* Preferences.swift in Sources */,
|
||||
D4E569E127A4128300AC2CEF /* InputState.swift in Sources */,
|
||||
D485D3C02796CE3200657FF3 /* VersionUpdateTests.swift in Sources */,
|
||||
D4E569E027A4123200AC2CEF /* KeyHandlerInput.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1288,7 +1258,6 @@
|
|||
SDKROOT = macosx;
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_EMIT_LOC_STRINGS = NO;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "McBopomofoTests/McBopomofoTests-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/McBopomofo.app/Contents/MacOS/McBopomofo";
|
||||
|
@ -1333,7 +1302,6 @@
|
|||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = macosx;
|
||||
SWIFT_EMIT_LOC_STRINGS = NO;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "McBopomofoTests/McBopomofoTests-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/McBopomofo.app/Contents/MacOS/McBopomofo";
|
||||
|
|
|
@ -1,655 +0,0 @@
|
|||
#import <XCTest/XCTest.h>
|
||||
#import "KeyHandler.h"
|
||||
#import "LanguageModelManager.h"
|
||||
#import "McBopomofoTests-Swift.h"
|
||||
|
||||
@interface KeyHandlerBopomofoTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KeyHandlerBopomofoTests
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[LanguageModelManager loadDataModels];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
}
|
||||
|
||||
- (void)testPunctuationComma
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"<" keyCode:0 charCode:'<' flags:NSEventModifierFlagShift isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
NSString *composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@","], @"It should be , but %@", composingBuffer);
|
||||
}
|
||||
|
||||
- (void)testPunctuationPeriod
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@">" keyCode:0 charCode:'>' flags:NSEventModifierFlagShift isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
NSString *composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"。"], @"It should be 。 but %@", composingBuffer);
|
||||
}
|
||||
|
||||
- (void)testInputtingNihao
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"s" keyCode:0 charCode:'s' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"u" keyCode:0 charCode:'u' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"c" keyCode:0 charCode:'c' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"l" keyCode:0 charCode:'l' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
NSString *composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
}
|
||||
|
||||
- (void)testCommittingNihao
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"s" keyCode:0 charCode:'s' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"u" keyCode:0 charCode:'u' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"c" keyCode:0 charCode:'c' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"l" keyCode:0 charCode:'l' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
__block NSInteger count = 0;
|
||||
|
||||
__block InputState *empty;
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:0 charCode:13 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
if (!count) {
|
||||
state = inState;
|
||||
}
|
||||
empty = inState;
|
||||
count++;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateCommitting")], @"It should be a committing state %@.", NSStringFromClass([state class]));
|
||||
NSString *poppedText = [(InputStateCommitting *)state poppedText];
|
||||
XCTAssertTrue([poppedText isEqualToString:@"你好"], @"It should be 你好 but %@", poppedText);
|
||||
|
||||
XCTAssertTrue([empty isKindOfClass:NSClassFromString(@"McBopomofo.InputStateEmpty")], @"It should be an empty state %@.", NSStringFromClass([state class]));
|
||||
}
|
||||
|
||||
- (void)testDelete
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"s" keyCode:0 charCode:'s' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"u" keyCode:0 charCode:'u' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"c" keyCode:0 charCode:'c' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"l" keyCode:0 charCode:'l' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
NSString *composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 2);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:123 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 1);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:117 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你"], @"It should be 你 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 1);
|
||||
|
||||
__block BOOL errorCalled = NO;
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:117 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
errorCalled = YES;
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你"], @"It should be 你 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 1);
|
||||
XCTAssertTrue(errorCalled);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:123 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你"], @"It should be 你 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 0);
|
||||
|
||||
errorCalled = NO;
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:117 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
errorCalled = YES;
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateEmptyIgnoringPreviousState")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
XCTAssertFalse(errorCalled);
|
||||
}
|
||||
|
||||
- (void)testBackspace
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"s" keyCode:0 charCode:'s' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"u" keyCode:0 charCode:'u' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"c" keyCode:0 charCode:'c' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"l" keyCode:0 charCode:'l' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
NSString *composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:0 charCode:8 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你"], @"It should be 你 but %@", composingBuffer);
|
||||
|
||||
__block InputStateEmpty *empty;
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:0 charCode:8 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
empty = (InputStateEmpty *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([empty isKindOfClass:NSClassFromString(@"McBopomofo.InputStateEmptyIgnoringPreviousState")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
}
|
||||
|
||||
- (void)testCursor
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"s" keyCode:0 charCode:'s' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"u" keyCode:0 charCode:'u' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"c" keyCode:0 charCode:'c' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"l" keyCode:0 charCode:'l' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
NSString *composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 2);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:123 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 1);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:123 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 0);
|
||||
|
||||
__block BOOL errorCalled = NO;
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:123 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
errorCalled = YES;
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 0);
|
||||
XCTAssertTrue(errorCalled);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:124 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 1);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:124 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 2);
|
||||
|
||||
errorCalled = NO;
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:124 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = (InputStateInputting *)inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
errorCalled = YES;
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 2);
|
||||
XCTAssertTrue(errorCalled);
|
||||
}
|
||||
|
||||
- (void)testCandidateWithDown
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"s" keyCode:0 charCode:'s' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"u" keyCode:0 charCode:'u' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:125 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateChoosingCandidate")], @"It should be a inputting state %@.", NSStringFromClass([state class]));
|
||||
NSArray *candidates = [(InputStateChoosingCandidate *)state candidates];
|
||||
XCTAssertTrue([candidates containsObject:@"你"]);
|
||||
|
||||
}
|
||||
|
||||
- (void)testHomeAndEnd
|
||||
{
|
||||
KeyHandler *handler = [[KeyHandler alloc] init];
|
||||
handler.inputMode = kBopomofoModeIdentifier;
|
||||
|
||||
KeyHandlerInput *input;
|
||||
__block InputState *state;
|
||||
state = [[InputStateEmpty alloc] init];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"s" keyCode:0 charCode:'s' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"u" keyCode:0 charCode:'u' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"c" keyCode:0 charCode:'c' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"l" keyCode:0 charCode:'l' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@"3" keyCode:0 charCode:'3' flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
NSString *composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 2);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:115 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 0);
|
||||
|
||||
input = [[KeyHandlerInput alloc] initWithInputText:@" " keyCode:119 charCode:0 flags:0 isVerticalMode:0];
|
||||
[handler handleInput:input state:state stateCallback:^(InputState * inState) {
|
||||
state = inState;
|
||||
} candidateSelectionCallback:^{
|
||||
} errorCallback:^{
|
||||
}];
|
||||
|
||||
XCTAssertTrue([state isKindOfClass:NSClassFromString(@"McBopomofo.InputStateInputting")], @"It should be an inputting state %@.", NSStringFromClass([state class]));
|
||||
composingBuffer = [(InputStateInputting *)state composingBuffer];
|
||||
XCTAssertTrue([composingBuffer isEqualToString:@"你好"], @"It should be 你好 but %@", composingBuffer);
|
||||
XCTAssertEqual([(InputStateInputting *)state cursorIndex], 2);
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,437 @@
|
|||
import XCTest
|
||||
@testable import McBopomofo
|
||||
|
||||
func charCode(_ string: String) -> UInt16 {
|
||||
let scalars = string.unicodeScalars
|
||||
return UInt16(scalars[scalars.startIndex].value)
|
||||
}
|
||||
|
||||
class KeyHandlerBopomofoTests: XCTestCase {
|
||||
var handler = KeyHandler()
|
||||
|
||||
override func setUpWithError() throws {
|
||||
LanguageModelManager.loadDataModels()
|
||||
handler = KeyHandler()
|
||||
handler.inputMode = kBopomofoModeIdentifier
|
||||
}
|
||||
|
||||
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.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
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.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "。")
|
||||
}
|
||||
}
|
||||
|
||||
func testInputting() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("vul3a945j4up gj bj4z83").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 testInputtingNihao() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("su3cl3").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 testInputtingTianKong() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("wu0 dj/ ").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 testCommittingNihao() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("su3cl3").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, "你好")
|
||||
}
|
||||
|
||||
let enter = KeyHandlerInput(inputText: " ", keyCode: 0, charCode: 13, flags: [], isVerticalMode: false)
|
||||
var committing: InputState?
|
||||
var empty: InputState?
|
||||
var count = 0
|
||||
|
||||
handler.handle(enter, state: state) { newState in
|
||||
switch count {
|
||||
case 0:
|
||||
committing = newState
|
||||
case 1:
|
||||
empty = newState
|
||||
default:
|
||||
break
|
||||
}
|
||||
count += 1
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(committing is InputState.Committing, "\(state)")
|
||||
if let committing = committing as? InputState.Committing {
|
||||
XCTAssertEqual(committing.poppedText, "你好")
|
||||
}
|
||||
XCTAssertTrue(empty is InputState.Empty, "\(state)")
|
||||
}
|
||||
|
||||
func testDelete() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("su3cl3").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, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 2)
|
||||
}
|
||||
|
||||
let left = KeyHandlerInput(inputText: " ", keyCode: KeyCode.left.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||
let delete = KeyHandlerInput(inputText: " ", keyCode: KeyCode.delete.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||
var errorCalled = false
|
||||
|
||||
handler.handle(left, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
}
|
||||
|
||||
handler.handle(delete, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
}
|
||||
|
||||
handler.handle(delete, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
errorCalled = true
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
}
|
||||
XCTAssertTrue(errorCalled)
|
||||
|
||||
errorCalled = false
|
||||
|
||||
handler.handle(left, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你")
|
||||
XCTAssertEqual(state.cursorIndex, 0)
|
||||
}
|
||||
|
||||
handler.handle(delete, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.EmptyIgnoringPreviousState, "\(state)")
|
||||
}
|
||||
|
||||
func testBackspace() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("su3cl3").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, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 2)
|
||||
}
|
||||
|
||||
let backspace = KeyHandlerInput(inputText: " ", keyCode: 0, charCode: 8, flags: [], isVerticalMode: false)
|
||||
|
||||
handler.handle(backspace, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
}
|
||||
|
||||
handler.handle(backspace, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.EmptyIgnoringPreviousState, "\(state)")
|
||||
}
|
||||
|
||||
func testCursor() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("su3cl3").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, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 2)
|
||||
}
|
||||
|
||||
let left = KeyHandlerInput(inputText: " ", keyCode: KeyCode.left.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||
let right = KeyHandlerInput(inputText: " ", keyCode: KeyCode.right.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||
|
||||
var errorCalled = false
|
||||
|
||||
handler.handle(left, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
}
|
||||
|
||||
handler.handle(left, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 0)
|
||||
}
|
||||
|
||||
handler.handle(left, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
errorCalled = true
|
||||
}
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 0)
|
||||
}
|
||||
XCTAssertTrue(errorCalled)
|
||||
|
||||
handler.handle(right, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
}
|
||||
|
||||
handler.handle(right, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 2)
|
||||
}
|
||||
|
||||
errorCalled = false
|
||||
handler.handle(right, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
errorCalled = true
|
||||
}
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 2)
|
||||
}
|
||||
XCTAssertTrue(errorCalled)
|
||||
}
|
||||
|
||||
func testCandidateWithDown() {
|
||||
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.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
}
|
||||
|
||||
let space = KeyHandlerInput(inputText: " ", keyCode: KeyCode.down.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||
handler.handle(space, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.ChoosingCandidate, "\(state)")
|
||||
if let state = state as? InputState.ChoosingCandidate {
|
||||
XCTAssertEqual(state.composingBuffer, "你")
|
||||
XCTAssertEqual(state.cursorIndex, 1)
|
||||
let candidates = state.candidates
|
||||
XCTAssertTrue(candidates.contains("你"))
|
||||
}
|
||||
}
|
||||
|
||||
func testHomeAndEnd() {
|
||||
var state: InputState = InputState.Empty()
|
||||
let keys = Array("su3cl3").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, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 2)
|
||||
}
|
||||
|
||||
let home = KeyHandlerInput(inputText: " ", keyCode: KeyCode.home.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||
let end = KeyHandlerInput(inputText: " ", keyCode: KeyCode.end.rawValue, charCode: 0, flags: [], isVerticalMode: false)
|
||||
|
||||
handler.handle(home, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
XCTAssertTrue(state is InputState.Inputting, "\(state)")
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 0)
|
||||
}
|
||||
|
||||
handler.handle(end, state: state) { newState in
|
||||
state = newState
|
||||
} candidateSelectionCallback: {
|
||||
} errorCallback: {
|
||||
}
|
||||
|
||||
if let state = state as? InputState.Inputting {
|
||||
XCTAssertEqual(state.composingBuffer, "你好")
|
||||
XCTAssertEqual(state.cursorIndex, 2)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import XCTest
|
||||
//@testable import McBopomofo
|
||||
@testable import McBopomofo
|
||||
|
||||
class PreferencesTests: XCTestCase {
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ class McBopomofoInputMethodController: IMKInputController {
|
|||
let optionKeyPressed = NSEvent.modifierFlags.contains(.option)
|
||||
|
||||
if inputMode == kBopomofoModeIdentifier && optionKeyPressed {
|
||||
let phaseReplacementItem = menu.addItem(withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), action: #selector(togglePhraseReplacementEnabled(_:)), keyEquivalent: "")
|
||||
let phaseReplacementItem = menu.addItem(withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "")
|
||||
phaseReplacementItem.state = Preferences.phraseReplacementEnabled.state
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ class McBopomofoInputMethodController: IMKInputController {
|
|||
NotifierController.notify(message: enabled ? NSLocalizedString("Half-width punctuation on", comment: "") : NSLocalizedString("Half-width punctuation off", comment: ""))
|
||||
}
|
||||
|
||||
@objc func togglePhraseReplacementEnabled(_ sender: Any?) {
|
||||
@objc func togglePhraseReplacement(_ sender: Any?) {
|
||||
let enabled = Preferences.togglePhraseReplacementEnabled()
|
||||
LanguageModelManager.phraseReplacementEnabled = enabled
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ class McBopomofoInputMethodController: IMKInputController {
|
|||
}
|
||||
|
||||
private func open(userFileAt path: String) {
|
||||
func checkUserFiles() -> Bool {
|
||||
func checkIfUserFilesExist() -> Bool {
|
||||
if !LanguageModelManager.checkIfUserLanguageModelFilesExist() {
|
||||
let content = String(format: NSLocalizedString("Please check the permission of at \"%@\".", comment: ""), LanguageModelManager.dataFolderPath)
|
||||
NonModalAlertWindowController.shared.show(title: NSLocalizedString("Unable to create the user phrase file.", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("OK", comment: ""), cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
|
||||
|
@ -218,7 +218,7 @@ class McBopomofoInputMethodController: IMKInputController {
|
|||
return true
|
||||
}
|
||||
|
||||
if !checkUserFiles() {
|
||||
if !checkIfUserFilesExist() {
|
||||
return
|
||||
}
|
||||
let url = URL(fileURLWithPath: path)
|
||||
|
@ -429,15 +429,15 @@ extension McBopomofoInputMethodController {
|
|||
let textSize = Preferences.candidateListTextSize
|
||||
let keyLabelSize = max(textSize / 2, kMinKeyLabelSize)
|
||||
|
||||
func fallbackFont(name: String?, size: CGFloat) -> NSFont {
|
||||
func font(name: String?, size: CGFloat) -> NSFont {
|
||||
if let name = name {
|
||||
return NSFont(name: name, size: size) ?? NSFont.systemFont(ofSize: size)
|
||||
}
|
||||
return NSFont.systemFont(ofSize: size)
|
||||
}
|
||||
|
||||
gCurrentCandidateController?.keyLabelFont = fallbackFont(name: Preferences.candidateKeyLabelFontName, size: keyLabelSize)
|
||||
gCurrentCandidateController?.candidateFont = fallbackFont(name: Preferences.candidateTextFontName, size: textSize)
|
||||
gCurrentCandidateController?.keyLabelFont = font(name: Preferences.candidateKeyLabelFontName, size: keyLabelSize)
|
||||
gCurrentCandidateController?.candidateFont = font(name: Preferences.candidateTextFontName, size: textSize)
|
||||
|
||||
let candidateKeys = Preferences.candidateKeys
|
||||
let keyLabels = candidateKeys.count > 4 ? Array(candidateKeys) : Array(Preferences.defaultCandidateKeys)
|
||||
|
|
Loading…
Reference in New Issue