Files
Agent-Squad/textextract/textextract_test.go
weichenandCursor bfec3c8930
ci / vet-and-test (push) Failing after 3s
ci / docker-checkout-hostgateway (push) Failing after 3s
Import agent-squad as a standalone repository.
Pin Agent-Native as a submodule so the module builds without the multi-repo sibling path.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-29 12:38:35 +00:00

43 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package textextract
import (
"strings"
"testing"
)
func TestExtractPlainText(t *testing.T) {
out, err := ExtractTextWithAnchors("a.md", []byte("# 标题\n正文"))
if err != nil {
t.Fatal(err)
}
if !strings.Contains(out, "# 标题") || !strings.Contains(out, "page 1") {
t.Fatalf("plain text + anchor missing: %q", out)
}
}
func TestInjectPageAnchors(t *testing.T) {
long := strings.Repeat("x", 7000)
out := InjectPageAnchors(long)
if got := strings.Count(out, "<!-- page"); got < 3 {
t.Fatalf("want >=3 anchors for 7000 chars, got %d", got)
}
}
func TestExtractDocx(t *testing.T) {
// 最小 docx:zip 内 word/document.xml。
if _, err := ExtractTextWithAnchors("a.docx", []byte("not-a-zip")); err == nil {
t.Fatal("invalid docx must fail")
}
}
func TestExtractBinaryFallback(t *testing.T) {
data := []byte{0x00, 0x01, 'a', 'b', 'c', 'd', 'e', 0x00, 'f', 'g', 'h', 'i', 0xff}
out, err := ExtractTextWithAnchors("a.pdf", data)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(out, "abcde") {
t.Fatalf("visible strings missing: %q", out)
}
}