From 918fff21c024d062fec9a15b03c3533c5dab4cff Mon Sep 17 00:00:00 2001 From: demo Date: Fri, 8 May 2026 12:32:26 -0400 Subject: test: start writing basic tests I've also moved the html to the findlinks package directory for now. --- html/ex1.html | 6 ---- html/ex2.html | 17 ---------- html/ex3.html | 62 ---------------------------------- html/ex4.html | 5 --- html/ex_spaces.html | 5 --- internal/findlinks/findlinks_test.go | 51 ++++++++++++++++++++++++++++ internal/findlinks/html/ex1.html | 6 ++++ internal/findlinks/html/ex2.html | 17 ++++++++++ internal/findlinks/html/ex3.html | 62 ++++++++++++++++++++++++++++++++++ internal/findlinks/html/ex4.html | 5 +++ internal/findlinks/html/ex_spaces.html | 5 +++ 11 files changed, 146 insertions(+), 95 deletions(-) delete mode 100644 html/ex1.html delete mode 100644 html/ex2.html delete mode 100644 html/ex3.html delete mode 100644 html/ex4.html delete mode 100644 html/ex_spaces.html create mode 100644 internal/findlinks/findlinks_test.go create mode 100644 internal/findlinks/html/ex1.html create mode 100644 internal/findlinks/html/ex2.html create mode 100644 internal/findlinks/html/ex3.html create mode 100644 internal/findlinks/html/ex4.html create mode 100644 internal/findlinks/html/ex_spaces.html diff --git a/html/ex1.html b/html/ex1.html deleted file mode 100644 index 833f110..0000000 --- a/html/ex1.html +++ /dev/null @@ -1,6 +0,0 @@ - - -

Hello!

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

Social stuffs

-
- - Check me out on twitter - - - - Gophercises is on Github! - -
- - diff --git a/html/ex3.html b/html/ex3.html deleted file mode 100644 index 1e718e2..0000000 --- a/html/ex3.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - 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/html/ex4.html b/html/ex4.html deleted file mode 100644 index 0e893b8..0000000 --- a/html/ex4.html +++ /dev/null @@ -1,5 +0,0 @@ - - - dog cat - - diff --git a/html/ex_spaces.html b/html/ex_spaces.html deleted file mode 100644 index 943f405..0000000 --- a/html/ex_spaces.html +++ /dev/null @@ -1,5 +0,0 @@ - - - - - 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/internal/findlinks/html/ex1.html b/internal/findlinks/html/ex1.html new file mode 100644 index 0000000..833f110 --- /dev/null +++ b/internal/findlinks/html/ex1.html @@ -0,0 +1,6 @@ + + +

Hello!

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

Social stuffs

+
+ + Check me out on twitter + + + + Gophercises is on Github! + +
+ + diff --git a/internal/findlinks/html/ex3.html b/internal/findlinks/html/ex3.html new file mode 100644 index 0000000..1e718e2 --- /dev/null +++ b/internal/findlinks/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/findlinks/html/ex4.html b/internal/findlinks/html/ex4.html new file mode 100644 index 0000000..0e893b8 --- /dev/null +++ b/internal/findlinks/html/ex4.html @@ -0,0 +1,5 @@ + + + dog cat + + diff --git a/internal/findlinks/html/ex_spaces.html b/internal/findlinks/html/ex_spaces.html new file mode 100644 index 0000000..943f405 --- /dev/null +++ b/internal/findlinks/html/ex_spaces.html @@ -0,0 +1,5 @@ + + + + + -- cgit v1.2.3