diff options
| author | demo <demo@antix1> | 2026-05-08 12:32:26 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-08 12:32:26 -0400 |
| commit | 918fff21c024d062fec9a15b03c3533c5dab4cff (patch) | |
| tree | 0c61ab3aff135eba7da8ca42b75dbff838ea403e | |
| parent | 1e5825c17624208d0d3ec7af1bd9a5b0b12da013 (diff) | |
test: start writing basic tests
I've also moved the html to the findlinks package directory for now.
| -rw-r--r-- | internal/findlinks/findlinks_test.go | 51 | ||||
| -rw-r--r-- | internal/findlinks/html/ex1.html (renamed from html/ex1.html) | 0 | ||||
| -rw-r--r-- | internal/findlinks/html/ex2.html (renamed from html/ex2.html) | 0 | ||||
| -rw-r--r-- | internal/findlinks/html/ex3.html (renamed from html/ex3.html) | 0 | ||||
| -rw-r--r-- | internal/findlinks/html/ex4.html (renamed from html/ex4.html) | 0 | ||||
| -rw-r--r-- | internal/findlinks/html/ex_spaces.html (renamed from html/ex_spaces.html) | 0 |
6 files changed, 51 insertions, 0 deletions
diff --git a/internal/findlinks/findlinks_test.go b/internal/findlinks/findlinks_test.go new file mode 100644 index 0000000..79fb241 --- /dev/null +++ b/internal/findlinks/findlinks_test.go @@ -0,0 +1,51 @@ +package findlinks + +import ( + "os" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func findLinksFile(filename string) ([]Link, error) { + f, err := os.Open(filename) + if err != nil { + panic("can't open test file") + } + defer f.Close() + + return FindLinks(f) +} + +func TestFindlinks(t *testing.T) { + type test struct { + filename string + links []Link + } + + tests := []test{ + { + "html/ex1.html", + []Link{ + { + Href: "/other-page", + Text: "A link to another page", + }, + }, + }, + } + + for _, test := range tests { + t.Run(test.filename, func(t *testing.T) { + links, err := findLinksFile(test.filename) + if err != nil { + t.Error(err) + } + + if !cmp.Equal(links, test.links) { + t.Errorf("got %v, want %v", links, test.links) + } + }) + } + +} diff --git a/html/ex1.html b/internal/findlinks/html/ex1.html index 833f110..833f110 100644 --- a/html/ex1.html +++ b/internal/findlinks/html/ex1.html diff --git a/html/ex2.html b/internal/findlinks/html/ex2.html index 3d22f94..3d22f94 100644 --- a/html/ex2.html +++ b/internal/findlinks/html/ex2.html diff --git a/html/ex3.html b/internal/findlinks/html/ex3.html index 1e718e2..1e718e2 100644 --- a/html/ex3.html +++ b/internal/findlinks/html/ex3.html diff --git a/html/ex4.html b/internal/findlinks/html/ex4.html index 0e893b8..0e893b8 100644 --- a/html/ex4.html +++ b/internal/findlinks/html/ex4.html diff --git a/html/ex_spaces.html b/internal/findlinks/html/ex_spaces.html index 943f405..943f405 100644 --- a/html/ex_spaces.html +++ b/internal/findlinks/html/ex_spaces.html |
