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

@ -148,52 +148,6 @@ final class ComposingTextTests: XCTestCase {
}
func testIsRightSideValid() throws {
do {
var c = ComposingText()
c.insertAtCursorPosition("akafatta", inputStyle: .roman2kana) // |
XCTAssertTrue(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "a", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: [""], inputStyle: .roman2kana)], of: c.input, to: 1))
XCTAssertFalse(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "k", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: ["", "k"], inputStyle: .roman2kana)], of: c.input, to: 2))
XCTAssertTrue(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "a", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: ["", ""], inputStyle: .roman2kana)], of: c.input, to: 3))
XCTAssertFalse(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "f", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: ["", "", "f"], inputStyle: .roman2kana)], of: c.input, to: 4))
XCTAssertTrue(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "a", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: ["", "", "", ""], inputStyle: .roman2kana)], of: c.input, to: 5))
// true
XCTAssertTrue(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "t", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: ["", "", "", "", "t"], inputStyle: .roman2kana)], of: c.input, to: 6))
// false
XCTAssertFalse(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "t", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: ["", "", "", "", "t", "t"], inputStyle: .roman2kana)], of: c.input, to: 7))
XCTAssertTrue(ComposingText.isRightSideValid(lastElement: ComposingText.InputElement(character: "a", inputStyle: .roman2kana), convertTargetElements: [ComposingText.ConvertTargetElement(string: ["", "", "", "", "", ""], inputStyle: .roman2kana)], of: c.input, to: 8))
}
}
func testGetConvertTargetIfRightSideIsValid() throws {
do {
var c = ComposingText()
c.insertAtCursorPosition("akafatta", inputStyle: .roman2kana) // |
XCTAssertEqual(
ComposingText.getConvertTargetIfRightSideIsValid(
lastElement: ComposingText.InputElement(character: "t", inputStyle: .roman2kana),
of: c.input,
to: 6,
convertTargetElements: [ComposingText.ConvertTargetElement(string: Array("あかふぁt"), inputStyle: .roman2kana)]
),
Array("あかふぁっ")
)
}
do {
var c = ComposingText()
c.insertAtCursorPosition("kintarou", inputStyle: .roman2kana) // |
XCTAssertEqual(
ComposingText.getConvertTargetIfRightSideIsValid(
lastElement: ComposingText.InputElement(character: "n", inputStyle: .roman2kana),
of: c.input,
to: 3,
convertTargetElements: [ComposingText.ConvertTargetElement(string: Array("きn"), inputStyle: .roman2kana)]
),
Array("きん")
)
}
}
func testDifferenceSuffix() throws {
do {
var c1 = ComposingText()

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))
}
//