package links import ( "fmt" "strings" "testing" ) type exampleType struct { expectedCount int content string } var examples = []exampleType{ {2, ` c Ex 1 Example Page Posts `}, {4, ` Ex 2 Example Page Posts A rouge link! `}, } func TestFindCountHrefs(t *testing.T) { for i, ex := range examples { name := fmt.Sprintf("Example %d", i+1) t.Run(name, func(t *testing.T) { r := strings.NewReader(ex.content) hrefs, err := parse(r) if err != nil { t.Error(err) } if actualCount := len(hrefs); actualCount != ex.expectedCount { t.Errorf("got %d, want %d", actualCount, ex.expectedCount) } }) } }