mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
Merge pull request #227 from azooKey/feat/mapped_input_style
feat: `.mapped(id)`を新たな入力スタイルとして導入し、カスタムローマ字かな変換テーブルに対応
This commit is contained in:
@ -140,7 +140,7 @@ final class ComposingTextTests: XCTestCase {
|
||||
ComposingText.InputElement(character: "a", inputStyle: .roman2kana),
|
||||
ComposingText.InputElement(character: "k", inputStyle: .roman2kana),
|
||||
ComposingText.InputElement(character: "a", inputStyle: .roman2kana),
|
||||
ComposingText.InputElement(character: "ふ", inputStyle: .direct)
|
||||
ComposingText.InputElement(character: "ふ", inputStyle: .frozen)
|
||||
])
|
||||
XCTAssertEqual(c.convertTarget, "あかふ")
|
||||
XCTAssertEqual(c.convertTargetCursorPosition, 3)
|
||||
|
@ -0,0 +1,28 @@
|
||||
@testable import KanaKanjiConverterModule
|
||||
import XCTest
|
||||
|
||||
final class InputStyleManagerTests: XCTestCase {
|
||||
func testCustomTableLoading() throws {
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent("custom.tsv")
|
||||
try "a\tあ\nka\tか\n".write(to: url, atomically: true, encoding: .utf8)
|
||||
let table = InputStyleManager.shared.table(for: .custom(url))
|
||||
XCTAssertEqual(table.toHiragana(currentText: [], added: "a"), Array("あ"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: ["k"], added: "a"), Array("か"))
|
||||
}
|
||||
|
||||
func testCustomTableLoadingWithBlankLines() throws {
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent("custom.tsv")
|
||||
try "a\tあ\n\n\nka\tか\n".write(to: url, atomically: true, encoding: .utf8)
|
||||
let table = InputStyleManager.shared.table(for: .custom(url))
|
||||
XCTAssertEqual(table.toHiragana(currentText: [], added: "a"), Array("あ"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: ["k"], added: "a"), Array("か"))
|
||||
}
|
||||
|
||||
func testCustomTableLoadingWithCommentLines() throws {
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent("custom.tsv")
|
||||
try "a\tあ\n# here is comment\nka\tか\n".write(to: url, atomically: true, encoding: .utf8)
|
||||
let table = InputStyleManager.shared.table(for: .custom(url))
|
||||
XCTAssertEqual(table.toHiragana(currentText: [], added: "a"), Array("あ"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: ["k"], added: "a"), Array("か"))
|
||||
}
|
||||
}
|
@ -3,24 +3,25 @@ import XCTest
|
||||
|
||||
final class Roman2KanaTests: XCTestCase {
|
||||
func testToHiragana() throws {
|
||||
let table = InputStyleManager.shared.table(for: .defaultRomanToKana)
|
||||
// xtsu -> っ
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array(""), added: "x"), Array("x"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("x"), added: "t"), Array("xt"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("xt"), added: "s"), Array("xts"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("xts"), added: "u"), Array("っ"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array(""), added: "x"), Array("x"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("x"), added: "t"), Array("xt"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("xt"), added: "s"), Array("xts"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("xts"), added: "u"), Array("っ"))
|
||||
|
||||
// kanto -> かんと
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array(""), added: "k"), Array("k"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("k"), added: "a"), Array("か"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("か"), added: "n"), Array("かn"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("かn"), added: "t"), Array("かんt"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("かんt"), added: "o"), Array("かんと"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array(""), added: "k"), Array("k"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("k"), added: "a"), Array("か"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("か"), added: "n"), Array("かn"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("かn"), added: "t"), Array("かんt"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("かんt"), added: "o"), Array("かんと"))
|
||||
|
||||
// zl -> →
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array(""), added: "z"), Array("z"))
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("z"), added: "l"), Array("→"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array(""), added: "z"), Array("z"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("z"), added: "l"), Array("→"))
|
||||
|
||||
// TT -> TT
|
||||
XCTAssertEqual(Roman2Kana.toHiragana(currentText: Array("T"), added: "T"), Array("TT"))
|
||||
XCTAssertEqual(table.toHiragana(currentText: Array("T"), added: "T"), Array("TT"))
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,29 @@ final class ConverterTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testAzikFullConversion() async throws {
|
||||
for needTypoCorrection in [true, false] {
|
||||
do {
|
||||
let converter = await KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
// : -> ー, sk -> しん, dq → だい, kf -> き, ds: です
|
||||
c.insertAtCursorPosition("azu:ki:haskzidqnokf:bo:doapurids", inputStyle: .mapped(id: .defaultAZIK))
|
||||
XCTAssertEqual(c.convertTarget, "あずーきーはしんじだいのきーぼーどあぷりです")
|
||||
let results = await converter.requestCandidates(c, options: requestOptions(needTypoCorrection: needTypoCorrection))
|
||||
XCTAssertEqual(results.mainResults.first?.text, "azooKeyは新時代のキーボードアプリです")
|
||||
}
|
||||
do {
|
||||
let converter = await KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
// yp -> よう, xp -> しょう, kf -> き, kr -> から, kyh -> きゅう, rk -> りん, kd -> けん, pp -> ぽう, : -> ー, kw -> けい, gr -> がら, ; -> っ, kp -> こう, dq -> だい, sz -> さん, kk -> きん, tq -> たい, zq -> ざい, tw -> てい
|
||||
c.insertAtCursorPosition("ypxpkfkrtenisusuieiyakyhxprkzikdppnadosamazamanasupo:tuwokwkdsinagrsodatixpga;kpzidqharoszzerusukkkpnitqzqsiteorigoruhuyatenisuwonara;twta", inputStyle: .mapped(id: .defaultAZIK))
|
||||
XCTAssertEqual(c.convertTarget, "ようしょうきからてにすすいえいやきゅうしょうりんじけんぽうなどさまざまなすぽーつをけいけんしながらそだちしょうがっこうじだいはろさんぜるすきんこうにたいざいしておりごるふやてにすをならっていた")
|
||||
let results = await converter.requestCandidates(c, options: requestOptions(needTypoCorrection: needTypoCorrection))
|
||||
XCTAssertEqual(results.mainResults.first?.text, "幼少期からテニス水泳野球少林寺拳法など様々なスポーツを経験しながら育ち小学校時代はロサンゼルス近郊に滞在しておりゴルフやテニスを習っていた")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1文字ずつ変換する
|
||||
// memo: 内部実装としては別のモジュールが呼ばれるのだが、それをテストする方法があまりないかもしれない
|
||||
func testGradualConversion() async throws {
|
||||
|
@ -331,7 +331,7 @@ final class DicdataStoreTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testPossibleNexts() throws {
|
||||
let possibleNexts = DicdataStore.possibleNexts
|
||||
let possibleNexts = InputStyleManager.shared.table(for: .defaultRomanToKana).possibleNexts
|
||||
XCTAssertEqual(Set(possibleNexts["f", default: []]).symmetricDifference(["ファ", "フィ", "フ", "フェ", "フォ", "フャ", "フュ", "フョ", "フゥ", "ッf"]), [])
|
||||
XCTAssertEqual(Set(possibleNexts["xy", default: []]).symmetricDifference(["ャ", "ョ", "ュ"]), [])
|
||||
XCTAssertEqual(possibleNexts["", default: []], [])
|
||||
|
@ -24,18 +24,6 @@ final class CharacterUtilsTests: XCTestCase {
|
||||
XCTAssertFalse(CharacterUtils.isKogana("!"))
|
||||
}
|
||||
|
||||
func testIsRomanLetter() throws {
|
||||
XCTAssertTrue(CharacterUtils.isRomanLetter("a"))
|
||||
XCTAssertTrue(CharacterUtils.isRomanLetter("A"))
|
||||
XCTAssertTrue(CharacterUtils.isRomanLetter("b"))
|
||||
|
||||
XCTAssertFalse(CharacterUtils.isRomanLetter("ぁ"))
|
||||
XCTAssertFalse(CharacterUtils.isRomanLetter("'"))
|
||||
XCTAssertFalse(CharacterUtils.isRomanLetter("あ"))
|
||||
XCTAssertFalse(CharacterUtils.isRomanLetter("カ"))
|
||||
XCTAssertFalse(CharacterUtils.isRomanLetter("!"))
|
||||
}
|
||||
|
||||
func testIsDakuten() throws {
|
||||
XCTAssertTrue(CharacterUtils.isDakuten("が"))
|
||||
XCTAssertTrue(CharacterUtils.isDakuten("ば"))
|
||||
|
Reference in New Issue
Block a user