Merge pull request #224 from azooKey/refactor/remove_complicated_boundary_checker

refactor: 特定のローマ字かな変換テーブルを前提にした複雑な境界チェックを廃止する
This commit is contained in:
Miwa
2025-07-21 01:33:47 -07:00
committed by GitHub
parent 3f93209534
commit 59cde2a2ca
4 changed files with 93 additions and 212 deletions

View File

@ -175,6 +175,21 @@ final class DicdataStoreTests: XCTestCase {
}
}
///
func testMustCorrectTypoRoman2Kana() throws {
let dicdataStore = DicdataStore(convertRequestOptions: requestOptions())
let mustWords = [
("tskamatsu", "高松"), // ts ->
("kitsmura", "北村"), // ts ->
]
for (key, word) in mustWords {
var c = ComposingText()
c.insertAtCursorPosition(key, inputStyle: .roman2kana)
let result = dicdataStore.lookupDicdata(composingText: c, inputRange: (0, c.input.endIndex - 1 ..< c.input.endIndex), needTypoCorrection: true)
XCTAssertEqual(result.first(where: {$0.data.word == word})?.data.word, word)
}
}
func testLookupDicdata() throws {
let dicdataStore = DicdataStore(convertRequestOptions: requestOptions())
do {
@ -209,6 +224,12 @@ final class DicdataStoreTests: XCTestCase {
var c = ComposingText()
sequentialInput(&c, sequence: "tukatt", inputStyle: .roman2kana)
let result = dicdataStore.lookupDicdata(composingText: c, inputRange: (0, 4..<6))
XCTAssertFalse(result.contains(where: {$0.data.word == "使っ"}))
}
do {
var c = ComposingText()
sequentialInput(&c, sequence: "tukatt", inputStyle: .roman2kana)
let result = dicdataStore.lookupDicdata(composingText: c, surfaceRange: (0, nil))
XCTAssertTrue(result.contains(where: {$0.data.word == "使っ"}))
}
}
@ -288,9 +309,14 @@ final class DicdataStoreTests: XCTestCase {
do {
var c = ComposingText()
sequentialInput(&c, sequence: "tesutowaーdo", inputStyle: .roman2kana)
let result = dicdataStore.lookupDicdata(composingText: c, inputRange: (0, c.input.endIndex - 1 ..< c.input.endIndex), needTypoCorrection: false)
let result = dicdataStore.lookupDicdata(
composingText: c,
inputRange: (0, c.input.endIndex - 1 ..< c.input.endIndex),
surfaceRange: (0, c.convertTarget.count - 1 ..< c.convertTarget.count),
needTypoCorrection: false
)
XCTAssertTrue(result.contains(where: {$0.data.word == "テストワード"}))
XCTAssertEqual(result.first(where: {$0.data.word == "テストワード"})?.range, .input(from: 0, to: 11))
XCTAssertEqual(result.first(where: {$0.data.word == "テストワード"})?.range, .surface(from: 0, to: 6))
}
//