fix: prefer aggregate OCR text
This commit is contained in:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user