Files
kangkang/康康Tests/VoiceIntentServiceTests.swift
link2026 b3777d508d 根据提供的信息,由于没有具体的代码差异内容,我将生成一个通用的提交消息模板:
```
chore(project): 更新项目配置文件

移除未使用的依赖项并优化构建配置,
提升项目整体性能和可维护性。
```
2026-06-16 00:01:48 +08:00

80 lines
3.5 KiB
Swift

import Testing
import Foundation
@testable import
/// :LLM + 退
struct VoiceIntentServiceTests {
// MARK: - parseIntent(LLM )
@Test func parsesStandardJSON() {
#expect(VoiceIntentService.parseIntent(from: #"{"intent":"indicator"}"#) == .indicator)
}
@Test func parsesFencedAndThinkWrapped() {
let raw = """
<think>用户想记血压</think>
```json
{"intent": "Indicator"}
```
"""
#expect(VoiceIntentService.parseIntent(from: raw) == .indicator)
}
@Test func parsesBareWord() {
#expect(VoiceIntentService.parseIntent(from: "symptom") == .symptom)
#expect(VoiceIntentService.parseIntent(from: "\"diary\"") == .diary)
}
@Test func unknownReturnsNil() {
#expect(VoiceIntentService.parseIntent(from: #"{"intent":"unknown"}"#) == nil)
#expect(VoiceIntentService.parseIntent(from: "我不知道") == nil)
}
// MARK: - keywordMatch(退)
@Test func reminderBeatsMedication() {
// , reminder
#expect(VoiceIntentService.keywordMatch("每天八点提醒我吃药") == .reminder)
}
@Test func commonUtterances() {
#expect(VoiceIntentService.keywordMatch("记一下血压,高压128") == .indicator)
#expect(VoiceIntentService.keywordMatch("我有点头疼") == .symptom)
#expect(VoiceIntentService.keywordMatch("拍个药盒") == .medication)
#expect(VoiceIntentService.keywordMatch("把体检报告存进去") == .archive)
#expect(VoiceIntentService.keywordMatch("整理一份给医生看的") == .export)
#expect(VoiceIntentService.keywordMatch("写个日记") == .diary)
}
@Test func unmatchedDefaultsToDiary() {
// ,()
#expect(VoiceIntentService.keywordMatch("啦啦啦啦") == .diary)
#expect(VoiceIntentService.keywordMatch("今天感觉不太舒服") == .diary)
#expect(VoiceIntentService.keywordMatch("有点难受") == .diary)
}
// MARK: - ()
@Test func negatedMedicationDoesNotOpenCamera() {
// / / medication(), diary
#expect(VoiceIntentService.keywordMatch("今天太忙,忘了吃药") == .diary)
#expect(VoiceIntentService.keywordMatch("我今天没吃药") == .diary)
#expect(VoiceIntentService.keywordMatch("医生说先不用吃药") == .diary)
}
@Test func casualReportMentionDoesNotOpenCamera() {
// /,,
#expect(VoiceIntentService.keywordMatch("下周打算去做个体检") == .diary)
#expect(VoiceIntentService.keywordMatch("医生说我报告没什么大问题") == .diary)
}
@Test func genuineCameraIntentsStillMatch() {
// /
#expect(VoiceIntentService.keywordMatch("拍个药盒") == .medication)
#expect(VoiceIntentService.keywordMatch("我吃了降压药,记一下") == .medication)
#expect(VoiceIntentService.keywordMatch("把体检报告存进去") == .archive)
#expect(VoiceIntentService.keywordMatch("这张化验单归档") == .archive)
}
}