fix: prefer aggregate OCR text

This commit is contained in:
2026-07-09 01:16:36 +08:00
parent 273af6a429
commit 57366ac08f
3 changed files with 197 additions and 36 deletions
@@ -142,6 +142,33 @@ func TestParseOCRTextSupportsWordsResult(t *testing.T) {
}
}
func TestParseOCRTextPrefersOverallContentOverBlocks(t *testing.T) {
text, err := parseOCRText([]byte(`{
"Data": "{\"content\":\"整体识别文本\",\"prism_wordsInfo\":[{\"word\":\"整体\"},{\"word\":\"识别\"},{\"word\":\"文本\"}]}"
}`))
if err != nil {
t.Fatalf("parse ocr text: %v", err)
}
if text != "整体识别文本" {
t.Fatalf("expected overall content only, got %q", text)
}
}
func TestParseOCRTextPrefersResultTextOverWordsResult(t *testing.T) {
text, err := parseOCRText([]byte(`{
"Result": {
"text": "hello world",
"words_result": [{"words":"hello"},{"words":"world"}]
}
}`))
if err != nil {
t.Fatalf("parse ocr text: %v", err)
}
if text != "hello world" {
t.Fatalf("expected result text only, got %q", text)
}
}
func TestParseOCRTextReturnsProviderError(t *testing.T) {
_, err := parseOCRText([]byte(`{"ResponseMetadata":{"Error":{"Code":"BadRequest","Message":"bad image"}}}`))
if err == nil || !strings.Contains(err.Error(), "bad image") {