From 29d93b1089c591b0d9de60f983e5528caa42b7f6 Mon Sep 17 00:00:00 2001 From: demo Date: Sat, 9 May 2026 09:45:58 -0400 Subject: refactor: move tests to dedicated package --- internal/test/findlinks_test.go | 52 ++++++++++++++++++++++++++++++++ internal/test/html/ex1.html | 6 ++++ internal/test/html/ex2.html | 17 +++++++++++ internal/test/html/ex3.html | 62 +++++++++++++++++++++++++++++++++++++++ internal/test/html/ex4.html | 5 ++++ internal/test/html/ex_spaces.html | 5 ++++ 6 files changed, 147 insertions(+) create mode 100644 internal/test/findlinks_test.go create mode 100644 internal/test/html/ex1.html create mode 100644 internal/test/html/ex2.html create mode 100644 internal/test/html/ex3.html create mode 100644 internal/test/html/ex4.html create mode 100644 internal/test/html/ex_spaces.html (limited to 'internal/test') diff --git a/internal/test/findlinks_test.go b/internal/test/findlinks_test.go new file mode 100644 index 0000000..1bc2f20 --- /dev/null +++ b/internal/test/findlinks_test.go @@ -0,0 +1,52 @@ +package test + +import ( + "os" + "testing" + + "git.brandonirizarry.xyz/links/internal/findlinks" + "github.com/google/go-cmp/cmp" +) + +func findLinksFile(filename string) ([]findlinks.Link, error) { + f, err := os.Open(filename) + if err != nil { + panic("can't open test file") + } + defer f.Close() + + return findlinks.FindLinks(f) +} + +func TestFindlinks(t *testing.T) { + type test struct { + filename string + links []findlinks.Link + } + + tests := []test{ + { + "html/ex1.html", + []findlinks.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/internal/test/html/ex1.html b/internal/test/html/ex1.html new file mode 100644 index 0000000..833f110 --- /dev/null +++ b/internal/test/html/ex1.html @@ -0,0 +1,6 @@ + + +

Hello!

+ A link to another page + + diff --git a/internal/test/html/ex2.html b/internal/test/html/ex2.html new file mode 100644 index 0000000..3d22f94 --- /dev/null +++ b/internal/test/html/ex2.html @@ -0,0 +1,17 @@ + + + + + +

Social stuffs

+
+ + Check me out on twitter + + + + Gophercises is on Github! + +
+ + diff --git a/internal/test/html/ex3.html b/internal/test/html/ex3.html new file mode 100644 index 0000000..1e718e2 --- /dev/null +++ b/internal/test/html/ex3.html @@ -0,0 +1,62 @@ + + + + + + + + + + + Gophercises - Coding exercises for budding gophers + + + +
+
+ +
+ +

coding exercises for budding gophers

+
+
+
+ + + Lost? Need help? +
+
+

Gophercises is 100% FREE, but is currently in beta. There will be bugs, and things will be changing significantly over the coming weeks.

+
+
+
+ + + diff --git a/internal/test/html/ex4.html b/internal/test/html/ex4.html new file mode 100644 index 0000000..0e893b8 --- /dev/null +++ b/internal/test/html/ex4.html @@ -0,0 +1,5 @@ + + + dog cat + + diff --git a/internal/test/html/ex_spaces.html b/internal/test/html/ex_spaces.html new file mode 100644 index 0000000..943f405 --- /dev/null +++ b/internal/test/html/ex_spaces.html @@ -0,0 +1,5 @@ + + + + + -- cgit v1.2.3