From 0a3679b2b108f1c5aaf61e8379f37b024196ed65 Mon Sep 17 00:00:00 2001 From: demo Date: Sun, 10 May 2026 12:14:14 -0400 Subject: test: use multiple examples of counting hrefs inside html One of the examples uses a nested anchor tag. While this is illegal, it may well reflect the intention of whoever wrote the HTML and so could be valuable as input data for the sitemap. --- internal/links/find_test.go | 48 +++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'internal/links/find_test.go') diff --git a/internal/links/find_test.go b/internal/links/find_test.go index a4c952e..de88678 100644 --- a/internal/links/find_test.go +++ b/internal/links/find_test.go @@ -1,13 +1,19 @@ package links import ( + "fmt" "strings" "testing" ) -const ( - ex1 = ` - +type exampleType struct { + expectedCount int + content string +} + +var examples = []exampleType{ + {2, ` +c Ex 1 @@ -16,19 +22,35 @@ const ( Posts -` -) +`}, + + {4, ` + + Ex 2 + + + Example Page + Posts + A rouge link! + + +`}, +} func TestFindCountHrefs(t *testing.T) { - r := strings.NewReader(ex1) - hrefs, err := find(r) - if err != nil { - t.Error(err) - } + for i, ex := range examples { + name := fmt.Sprintf("Example %d", i+1) - const expectedLen = 2 + t.Run(name, func(t *testing.T) { + r := strings.NewReader(ex.content) + hrefs, err := find(r) + if err != nil { + t.Error(err) + } - if actualLen := len(hrefs); actualLen != expectedLen { - t.Errorf("got %d, want %d", actualLen, expectedLen) + if actualCount := len(hrefs); actualCount != ex.expectedCount { + t.Errorf("got %d, want %d", actualCount, ex.expectedCount) + } + }) } } -- cgit v1.2.3