import Testing
@testable import 康康

struct VLPromptsOCRTests {

    @Test func emptyOCRKeepsPromptClean() {
        let p = VLPrompts.reportExtraction(ocrText: "")
        #expect(!p.contains("OCR 参考文本"))
        #expect(!p.contains("{{OCR_SECTION}}"))
        #expect(p.contains("现在请识别图片并输出 JSON"))
    }

    @Test func ocrTextIsInjectedBeforeFinalInstruction() {
        let p = VLPrompts.reportExtraction(ocrText: "尿酸  486  208-428  μmol/L")
        #expect(p.contains("OCR 参考文本"))
        #expect(p.contains("尿酸  486"))
        let ocrPos = p.range(of: "尿酸  486")!.lowerBound
        let endPos = p.range(of: "现在请识别图片并输出 JSON")!.lowerBound
        #expect(ocrPos < endPos)
    }

    @Test func clipKeepsShortTextIntact() {
        #expect(VLPrompts.clipOCR("短文本") == "短文本")
    }

    @Test func clipCutsAtLineBoundary() {
        let long = Array(repeating: "指标行 1.23 mmol/L", count: 400).joined(separator: "\n")
        let clipped = VLPrompts.clipOCR(long, limit: 200)
        #expect(clipped.count < 260)
        #expect(clipped.hasSuffix("(后续内容过长已截断)"))
    }
}
