package server
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// A page as the model wants it: title, the main text with headings and
// lists, no scripts, styles or menus.
func TestPageText(t *testing.T) {
page := `
")
}))
defer srv.Close()
p, err := fetchPage(context.Background(), srv.URL+"/page")
if err != nil || p.Title != "T" || !p.Truncated || len([]rune(p.Text)) > fetchMaxChars+10 {
t.Fatalf("page: %v %q %v %d", err, p.Title, p.Truncated, len(p.Text))
}
p, err = fetchPage(context.Background(), srv.URL+"/json")
if err != nil || p.Text != `{"a":1}` {
t.Fatalf("json: %+v %v", p, err)
}
}
// Lines broken in the page's source are one paragraph; code keeps its lines.
func TestPageTextJoinsWrapped(t *testing.T) {
_, text := pageText("
The latest Go release,\n version 1.24,\narrives in February.
a\nb
")
if !strings.Contains(text, "The latest Go release, version 1.24, arrives in February.") || !strings.Contains(text, "a\nb") {
t.Fatalf("%q", text)
}
}