fix(mac): added two unit tests

This commit is contained in:
Shawn Schantz 2026-10-05 14:44:26 -04:00
parent eedb763e9e
commit 9dd9e580e0
3 changed files with 24 additions and 3 deletions

View file

@ -1 +1 @@
github "erikdoe/ocmock" "v3.9.1"
github "erikdoe/ocmock" "v3.9.4"

View file

@ -363,7 +363,6 @@ CGEventSourceRef _sourceForGeneratedEvent = nil;
if (!self.apiCompliance.canReadText) {
os_log_debug([KMLogs keyTraceLog], "InputMethodEventHandler readContext, unable to read context: non-compliant app");
*outSelection = selectionRange;
return contextString;
}
@ -605,7 +604,7 @@ CGEventSourceRef _sourceForGeneratedEvent = nil;
// guard: must have sufficient context
if ([context length] <= output.textToDelete.length) {
os_log_error([KMLogs keyTraceLog], "cannot replace text, insufficient context");
os_log_debug([KMLogs keyTraceLog], "cannot replace text, insufficient context");
return NO; // return without deleting/replacing
}

View file

@ -118,6 +118,28 @@ id testClient = nil;
XCTAssertTrue(replacementInfo.replacementLength == 2, @"replacementLength should be 2");
}
- (void)testEvaluateReplacement_lowStoreLocation_correctReplacementLocation {
NSString *context = @"testxa";
NSUInteger storeLocation = 10;
NSUInteger deletionLength = 1;
NSUInteger locationOfDeletion = 5;
ReplacementInfo replacementInfo = [testEventHandler evaluateForReplaceability: context textStoreLocation:storeLocation deleteLength:deletionLength locationOfDeletionTarget:locationOfDeletion];
XCTAssertTrue(replacementInfo.replacementLocation==8, @"replacementLocation should be 8");
}
- (void)testEvaluateReplacement_highStoreLocation_correctReplacementLocation {
NSString *context = @"testxa";
NSUInteger storeLocation = 1000;
NSUInteger deletionLength = 1;
NSUInteger locationOfDeletion = 5;
ReplacementInfo replacementInfo = [testEventHandler evaluateForReplaceability: context textStoreLocation:storeLocation deleteLength:deletionLength locationOfDeletionTarget:locationOfDeletion];
XCTAssertTrue(replacementInfo.replacementLocation==998, @"replacementLocation should be 998");
}
// Uses Malar Tirhuta script
- (void)testEvaluateReplacement_latinCharacterPrecededBySurrogatePair_replacementLengthThree {
NSString *context = @"test.𑒏a"; // 𑒏 : U+1148F : TIRHUTA LETTER