From 9dd9e580e04f83aca9a6ed99aae5ea60132af6e5 Mon Sep 17 00:00:00 2001 From: Shawn Schantz Date: Mon, 5 Oct 2026 14:44:26 -0400 Subject: [PATCH] fix(mac): added two unit tests --- mac/Cartfile.resolved | 2 +- .../Keyman4MacIM/KMInputMethodEventHandler.m | 3 +-- .../KeymanTests/InputMethodTests.m | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/mac/Cartfile.resolved b/mac/Cartfile.resolved index c743c88996..7a3ac4d400 100644 --- a/mac/Cartfile.resolved +++ b/mac/Cartfile.resolved @@ -1 +1 @@ -github "erikdoe/ocmock" "v3.9.1" +github "erikdoe/ocmock" "v3.9.4" diff --git a/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodEventHandler.m b/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodEventHandler.m index 640c839abd..50ee8313cf 100644 --- a/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodEventHandler.m +++ b/mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodEventHandler.m @@ -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 } diff --git a/mac/Keyman4MacIM/KeymanTests/InputMethodTests.m b/mac/Keyman4MacIM/KeymanTests/InputMethodTests.m index 667b9cce49..70ea63db2a 100644 --- a/mac/Keyman4MacIM/KeymanTests/InputMethodTests.m +++ b/mac/Keyman4MacIM/KeymanTests/InputMethodTests.m @@ -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