Skip to content

Commit

Permalink
Merge pull request #230 from mtgto/fix-delete-yomis
Browse files Browse the repository at this point in the history
複数の変換候補があるエントリから1候補を削除すると読み配列から問答無用で削除していたのを修正
  • Loading branch information
mtgto authored Oct 22, 2024
2 parents 8ddfdff + 4a02f47 commit 39327c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 10 additions & 7 deletions macSKK/MemoryDict.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,23 @@ struct MemoryDict: DictProtocol {
/// 辞書からエントリを削除する。
///
/// 辞書にないエントリ (ファイル辞書) の削除は無視されます。
/// 読みの配列の順序は変更されません。
///
/// - Parameters:
/// - yomi: SKK辞書の見出し。複数のひらがな、もしくは複数のひらがな + ローマ字からなる文字列
/// - word: SKK辞書の変換候補。
/// - Returns: エントリを削除できたかどうか
mutating func delete(yomi: String, word: Word.Word) -> Bool {
if let words = entries[yomi] {
if yomi.isOkuriAri {
if let index = okuriAriYomis.firstIndex(of: yomi) {
okuriAriYomis.remove(at: index)
}
} else {
if let index = okuriNashiYomis.firstIndex(of: yomi) {
okuriNashiYomis.remove(at: index)
if words.count == 1 {
if yomi.isOkuriAri {
if let index = okuriAriYomis.firstIndex(of: yomi) {
okuriAriYomis.remove(at: index)
}
} else {
if let index = okuriNashiYomis.firstIndex(of: yomi) {
okuriNashiYomis.remove(at: index)
}
}
}
let filtered = words.filter { $0.word != word }
Expand Down
12 changes: 10 additions & 2 deletions macSKKTests/MemoryDictTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,23 @@ class MemoryDictTests: XCTestCase {
}

func testDelete() throws {
var dict = MemoryDict(entries: ["あr": [Word(""), Word("")]], readonly: false)
var dict = MemoryDict(entries: ["あr": [Word(""), Word("")], "": [Word(""), Word("")]], readonly: false)
XCTAssertEqual(dict.okuriAriYomis, ["あr"])
XCTAssertEqual(dict.okuriNashiYomis, [""])
XCTAssertFalse(dict.delete(yomi: "あr", word: ""))
XCTAssertFalse(dict.delete(yomi: "いr", word: ""), "存在しないエントリを削除しようとする")
XCTAssertFalse(dict.delete(yomi: "", word: ""), "存在しないエントリを削除しようとする")
XCTAssertTrue(dict.delete(yomi: "あr", word: ""))
XCTAssertTrue(dict.delete(yomi: "", word: ""))
XCTAssertEqual(dict.okuriAriYomis, ["あr"], "「有」がまだ残っている")
XCTAssertEqual(dict.okuriNashiYomis, [""], "「柄」がまだ残っている")
XCTAssertEqual(dict.refer("あr", option: nil), [Word("")])
XCTAssertFalse(dict.delete(yomi: "いいい", word: "いいい"))
XCTAssertFalse(dict.delete(yomi: "あr", word: ""))
XCTAssertFalse(dict.delete(yomi: "あr", word: ""), "削除済")
XCTAssertTrue(dict.delete(yomi: "あr", word: ""))
XCTAssertEqual(dict.okuriAriYomis, [])
XCTAssertTrue(dict.delete(yomi: "", word: ""))
XCTAssertEqual(dict.okuriNashiYomis, [])
}

func testDeleteOkuriBlock() throws {
Expand Down

0 comments on commit 39327c4

Please sign in to comment.