Pin Agent-Native as a submodule so the module builds without the multi-repo sibling path. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
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)
|
||
}
|
||
}
|