mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
Merge pull request #224 from azooKey/refactor/remove_complicated_boundary_checker
refactor: 特定のローマ字かな変換テーブルを前提にした複雑な境界チェックを廃止する
This commit is contained in:
@ -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()
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
// 動的ユーザ辞書の単語が通常の辞書よりも優先されることのテスト
|
||||
|
Reference in New Issue
Block a user