mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
fix template parse logic
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
//
|
||||
// CandidateTests.swift
|
||||
//
|
||||
//
|
||||
// Created by miwa on 2023/08/16.
|
||||
//
|
||||
|
||||
|
||||
import XCTest
|
||||
@testable import KanaKanjiConverterModule
|
||||
|
||||
@MainActor final class CandidateTests: XCTestCase {
|
||||
// テンプレートのパース
|
||||
func testParseTemplate() throws {
|
||||
do {
|
||||
let text = #"<random type="int" value="1,3">"#
|
||||
let candidate = Candidate(
|
||||
text: text,
|
||||
value: -40,
|
||||
correspondingCount: 4,
|
||||
lastMid: 5,
|
||||
data: [DicdataElement(word: text, ruby: "サイコロ", cid: 0, mid: 5, value: -40)]
|
||||
)
|
||||
// ランダムなので繰り返し実行しておく
|
||||
for _ in 0 ..< 10 {
|
||||
var candidate2 = candidate
|
||||
candidate2.parseTemplate()
|
||||
print(candidate2.text)
|
||||
XCTAssertTrue(Set((1...3).map(String.init)).contains(candidate2.text))
|
||||
XCTAssertEqual(candidate.value, candidate2.value)
|
||||
XCTAssertEqual(candidate.correspondingCount, candidate2.correspondingCount)
|
||||
XCTAssertEqual(candidate.lastMid, candidate2.lastMid)
|
||||
XCTAssertEqual(candidate.data, candidate2.data)
|
||||
XCTAssertEqual(candidate.actions, candidate2.actions)
|
||||
}
|
||||
}
|
||||
do {
|
||||
let text = #"\n"#
|
||||
let candidate = Candidate(
|
||||
text: text,
|
||||
value: 0,
|
||||
correspondingCount: 0,
|
||||
lastMid: 0,
|
||||
data: [DicdataElement(word: text, ruby: "", cid: 0, mid: 0, value: 0)]
|
||||
)
|
||||
var candidate2 = candidate
|
||||
candidate2.parseTemplate()
|
||||
XCTAssertEqual(candidate.text, candidate2.text)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
//
|
||||
// ConversionTests.swift
|
||||
//
|
||||
//
|
||||
// Created by miwa on 2023/08/16.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import KanaKanjiConverterModule
|
||||
|
||||
@MainActor final class ConverterTests: XCTestCase {
|
||||
func requestOptions() -> ConvertRequestOptions {
|
||||
ConvertRequestOptions(
|
||||
N_best: 5,
|
||||
requireJapanesePrediction: true,
|
||||
requireEnglishPrediction: false,
|
||||
keyboardLanguage: .ja_JP,
|
||||
typographyLetterCandidate: false,
|
||||
unicodeCandidate: true,
|
||||
englishCandidateInRoman2KanaInput: true,
|
||||
fullWidthRomanCandidate: false,
|
||||
halfWidthKanaCandidate: false,
|
||||
learningType: .nothing,
|
||||
maxMemoryCount: 0,
|
||||
shouldResetMemory: false,
|
||||
dictionaryResourceURL: Bundle(for: type(of: self)).bundleURL.appendingPathComponent("DictionaryMock", isDirectory: true),
|
||||
memoryDirectoryURL: URL(fileURLWithPath: ""),
|
||||
sharedContainerURL: URL(fileURLWithPath: ""),
|
||||
metadata: .init(appVersionString: "Tests")
|
||||
)
|
||||
}
|
||||
|
||||
// 変換されてはいけないケースを示す
|
||||
func testMustNotCases() throws {
|
||||
do {
|
||||
// 改行文字に対して本当に改行が入ってしまうケース
|
||||
let converter = KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
c.insertAtCursorPosition("\\n", inputStyle: .direct)
|
||||
let results = converter.requestCandidates(c, options: requestOptions())
|
||||
XCTAssertFalse(results.mainResults.contains(where: {$0.text == "\n"}))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -17,7 +17,7 @@ import XCTest
|
||||
convertTarget: input
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
func testFromUnicode() throws {
|
||||
do {
|
||||
let converter = KanaKanjiConverter()
|
||||
|
Reference in New Issue
Block a user