import Testing import Foundation @testable import 康康 /// 「用药记录」点药设吃药提醒:行拆分与提醒预填的纯函数测试。 /// 入口逻辑见 `TimelineEntryDetailView.medicationBody`。 struct MedicationReminderParsingTests { // MARK: - 行拆分 @Test func splitsMultipleLinesAndDropsBlanks() { let content = "缬沙坦胶囊 80mg · 一日一次\n\n二甲双胍 0.5g · 一日三次\n " let lines = TimelineEntryDetailView.medicationLines(content) #expect(lines == ["缬沙坦胶囊 80mg · 一日一次", "二甲双胍 0.5g · 一日三次"]) } @Test func singleLineNoNewline() { #expect(TimelineEntryDetailView.medicationLines("阿司匹林肠溶片 100mg") == ["阿司匹林肠溶片 100mg"]) } @Test func emptyContentYieldsNoLines() { #expect(TimelineEntryDetailView.medicationLines("\n \n").isEmpty) } // MARK: - 提醒预填 @Test func splitsNameAndUsageOnMiddot() { let f = TimelineEntryDetailView.medicationReminderFields(forLine: "缬沙坦胶囊 80mg · 一日一次") #expect(f.title.contains("缬沙坦胶囊 80mg")) // 标题带药名+规格(可能含「吃药:」前缀) #expect(!f.title.contains("一日一次")) // 用法不进标题 #expect(f.note == "一日一次") // 用法进备注 } @Test func noUsageGivesEmptyNote() { let f = TimelineEntryDetailView.medicationReminderFields(forLine: "阿司匹林 100mg") #expect(f.title.contains("阿司匹林 100mg")) #expect(f.note.isEmpty) } @Test func multipleMiddotsKeepEverythingAfterFirstAsUsage() { let f = TimelineEntryDetailView.medicationReminderFields(forLine: "甲药 · 餐后 · 一日两次") #expect(f.title.contains("甲药")) #expect(f.note == "餐后 · 一日两次") } }