mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
fix: 動的ユーザ辞書が適切に読めていなかった問題を修正
This commit is contained in:
@ -223,4 +223,83 @@ final class DicdataStoreTests: XCTestCase {
|
||||
XCTAssertTrue(result.contains(where: {$0.word == "九千九百九十九億九千九百九十九万九千九百九十九"}))
|
||||
}
|
||||
}
|
||||
|
||||
func testDynamicUserDict() throws {
|
||||
let dicdataStore = DicdataStore(convertRequestOptions: requestOptions())
|
||||
|
||||
// 動的ユーザ辞書を設定
|
||||
let testDynamicUserDict = [
|
||||
DicdataElement(word: "テスト単語", ruby: "テストタンゴ", lcid: CIDData.固有名詞.cid, rcid: CIDData.固有名詞.cid, mid: MIDData.一般.mid, value: -10),
|
||||
DicdataElement(word: "カスタム変換", ruby: "カスタムヘンカン", lcid: CIDData.固有名詞.cid, rcid: CIDData.固有名詞.cid, mid: MIDData.一般.mid, value: -12),
|
||||
DicdataElement(word: "動的辞書", ruby: "ドウテキジショ", lcid: CIDData.固有名詞.cid, rcid: CIDData.固有名詞.cid, mid: MIDData.一般.mid, value: -11)
|
||||
]
|
||||
dicdataStore.sendToDicdataStore(.importDynamicUserDict(testDynamicUserDict))
|
||||
|
||||
// 完全一致テスト
|
||||
do {
|
||||
let result = dicdataStore.getMatchDynamicUserDict("テストタンゴ")
|
||||
XCTAssertEqual(result.count, 1)
|
||||
XCTAssertEqual(result.first?.word, "テスト単語")
|
||||
XCTAssertEqual(result.first?.ruby, "テストタンゴ")
|
||||
}
|
||||
|
||||
// 前方一致テスト
|
||||
do {
|
||||
let result = dicdataStore.getPrefixMatchDynamicUserDict("カスタム")
|
||||
XCTAssertEqual(result.count, 1)
|
||||
XCTAssertEqual(result.first?.word, "カスタム変換")
|
||||
XCTAssertEqual(result.first?.ruby, "カスタムヘンカン")
|
||||
}
|
||||
|
||||
// 変換動作テスト
|
||||
do {
|
||||
var c = ComposingText()
|
||||
c.insertAtCursorPosition("テストタンゴ", inputStyle: .direct)
|
||||
let result = dicdataStore.getLOUDSDataInRange(inputData: c, from: 0, toIndexRange: c.input.endIndex - 1 ..< c.input.endIndex, needTypoCorrection: false)
|
||||
XCTAssertTrue(result.contains(where: {$0.data.word == "テスト単語"}))
|
||||
}
|
||||
|
||||
// 複数の動的ユーザ辞書エントリの変換テスト
|
||||
do {
|
||||
var c = ComposingText()
|
||||
c.insertAtCursorPosition("ドウテキジショ", inputStyle: .direct)
|
||||
let result = dicdataStore.getLOUDSDataInRange(inputData: c, from: 0, toIndexRange: c.input.endIndex - 1 ..< c.input.endIndex, needTypoCorrection: false)
|
||||
XCTAssertTrue(result.contains(where: {$0.data.word == "動的辞書"}))
|
||||
}
|
||||
|
||||
// 存在しないエントリのテスト
|
||||
do {
|
||||
let result = dicdataStore.getMatchDynamicUserDict("ソンザイシナイ")
|
||||
XCTAssertEqual(result.count, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func testDynamicUserDictWithConversion() throws {
|
||||
let dicdataStore = DicdataStore(convertRequestOptions: requestOptions())
|
||||
|
||||
// 動的ユーザ辞書を設定
|
||||
let testDynamicUserDict = [
|
||||
DicdataElement(word: "テストワード", ruby: "テストワード", lcid: CIDData.固有名詞.cid, rcid: CIDData.固有名詞.cid, mid: MIDData.一般.mid, value: -8),
|
||||
DicdataElement(word: "特殊読み", ruby: "トクシュヨミ", lcid: CIDData.固有名詞.cid, rcid: CIDData.固有名詞.cid, mid: MIDData.一般.mid, value: -9)
|
||||
]
|
||||
dicdataStore.sendToDicdataStore(.importDynamicUserDict(testDynamicUserDict))
|
||||
|
||||
// ローマ字入力での変換テスト
|
||||
do {
|
||||
var c = ComposingText()
|
||||
sequentialInput(&c, sequence: "tesutowaーdo", inputStyle: .roman2kana)
|
||||
let result = dicdataStore.getLOUDSDataInRange(inputData: c, from: 0, toIndexRange: c.input.endIndex - 1 ..< c.input.endIndex, needTypoCorrection: false)
|
||||
XCTAssertTrue(result.contains(where: {$0.data.word == "テストワード"}))
|
||||
}
|
||||
|
||||
// 動的ユーザ辞書の単語が通常の辞書よりも優先されることのテスト
|
||||
do {
|
||||
var c = ComposingText()
|
||||
c.insertAtCursorPosition("トクシュヨミ", inputStyle: .direct)
|
||||
let result = dicdataStore.getLOUDSDataInRange(inputData: c, from: 0, toIndexRange: c.input.endIndex - 1 ..< c.input.endIndex, needTypoCorrection: false)
|
||||
let dynamicUserDictResult = result.first(where: {$0.data.word == "特殊読み"})
|
||||
XCTAssertNotNil(dynamicUserDictResult)
|
||||
XCTAssertEqual(dynamicUserDictResult?.data.metadata, .isFromUserDictionary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user