summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-10 12:14:14 -0400
committerdemo <demo@antix1>2026-05-10 12:14:26 -0400
commit0a3679b2b108f1c5aaf61e8379f37b024196ed65 (patch)
tree5fe1e3405dffbf5f29955de0e622139b18ddf488
parent2735a0388e96fd4d09201ae5451e1a972ef2130a (diff)
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.
-rw-r--r--internal/links/find_test.go48
1 files changed, 35 insertions, 13 deletions
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 = `
-<html>
+type exampleType struct {
+ expectedCount int
+ content string
+}
+
+var examples = []exampleType{
+ {2, `
+<html>c
<head>
<title>Ex 1</title>
<head>
@@ -16,19 +22,35 @@ const (
<a href="/posts">Posts</a>
</body>
</html>
-`
-)
+`},
+
+ {4, `<html>
+ <head>
+ <title>Ex 2</title>
+ <head>
+ <body>
+ <a href="https://example.com/">Example Page</a>
+ <a href="/posts">Posts</a>
+ <a href="#">A <a href="#">rouge</a> link!</a>
+ </body>
+</html>
+`},
+}
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)
+ }
+ })
}
}