package webfetch import ( "strings" "testing" ) func TestExtractTitle(t *testing.T) { html := `Hello World` title := ExtractTitle(html) if title != "Hello World" { t.Errorf("expected 'Hello World', got '%s'", title) } } func TestExtractTitle_Empty(t *testing.T) { html := `` title := ExtractTitle(html) if title != "" { t.Errorf("expected empty, got '%s'", title) } } func TestExtractMetaDescription(t *testing.T) { html := `` desc := ExtractMetaDescription(html) if desc != "Test description" { t.Errorf("expected 'Test description', got '%s'", desc) } } func TestExtractContent(t *testing.T) { html := `
` + strings.Repeat("This is article content. ", 20) + `
` content := ExtractContent(html) if !strings.Contains(content, "article content") { t.Errorf("expected content to contain 'article content', got '%s'", content) } } func TestHtmlToMarkdown(t *testing.T) { html := `

Title

Paragraph text

Link ` md := HtmlToMarkdown(html) if !strings.Contains(md, "# Title") { t.Error("expected markdown heading") } if !strings.Contains(md, "Paragraph text") { t.Error("expected paragraph text") } if !strings.Contains(md, "[Link](https://example.com)") { t.Error("expected markdown link") } if !strings.Contains(md, "- Item 1") { t.Error("expected list item") } } func TestHtmlToMarkdown_CodeBlock(t *testing.T) { html := `
func main() {}
` md := HtmlToMarkdown(html) if !strings.Contains(md, "```") { t.Error("expected fenced code block") } if !strings.Contains(md, "func main()") { t.Error("expected code content") } } func TestCapStr(t *testing.T) { s := "hello world" if capStr(s, 5) != "hello" { t.Errorf("expected 'hello', got '%s'", capStr(s, 5)) } if capStr(s, 100) != s { t.Errorf("expected full string, got '%s'", capStr(s, 100)) } }