diff options
Diffstat (limited to 'internal/links/find_test.go')
| -rw-r--r-- | internal/links/find_test.go | 48 |
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) + } + }) } } |
