test: add tests for Template

This commit is contained in:
Miwa / Ensan
2025-07-21 11:18:32 +09:00
parent 80be12f3ef
commit cf6139e245

View File

@ -1,8 +1,41 @@
//
// File.swift
// AzooKeyKanakanjiConverter
//
// Created by miwa on 2025/07/21.
//
import Foundation
@testable import KanaKanjiConverterModule
import XCTest
final class TemplateConversionTests: XCTestCase {
func requestOptions() -> ConvertRequestOptions {
.default
}
func testTemplateConversion() async throws {
let converter = await KanaKanjiConverter()
let template = #"<date format="yyyy年MM月dd日" type="western" language="ja_JP" delta="0" deltaunit="1">"#
await converter.sendToDicdataStore(.importDynamicUserDict([
.init(word: template, ruby: "キョウ", cid: CIDData..cid, mid: MIDData..mid, value: 5)
]))
let formatter = DateFormatter()
formatter.dateFormat = "yyyy年MM月dd日"
formatter.calendar = Calendar(identifier: .gregorian)
let todayString = formatter.string(from: Date())
do {
var c = ComposingText()
c.insertAtCursorPosition("きょう", inputStyle: .direct)
let results = await converter.requestCandidates(c, options: requestOptions())
XCTAssertTrue(results.mainResults.contains(where: { $0.text == todayString} ))
XCTAssertFalse(results.mainResults.contains(where: { $0.text == template} ))
XCTAssertFalse(results.firstClauseResults.contains(where: { $0.text == template} ))
await converter.stopComposition()
}
do {
var c = ComposingText()
c.insertAtCursorPosition("kyou", inputStyle: .roman2kana)
let results = await converter.requestCandidates(c, options: requestOptions())
XCTAssertTrue(results.mainResults.contains(where: { $0.text == todayString} ))
XCTAssertFalse(results.mainResults.contains(where: { $0.text == template} ))
XCTAssertFalse(results.firstClauseResults.contains(where: { $0.text == template} ))
await converter.stopComposition()
}
}
}