summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/findlinks/findlinks_test.go51
-rw-r--r--internal/findlinks/html/ex1.html6
-rw-r--r--internal/findlinks/html/ex2.html17
-rw-r--r--internal/findlinks/html/ex3.html62
-rw-r--r--internal/findlinks/html/ex4.html5
-rw-r--r--internal/findlinks/html/ex_spaces.html5
6 files changed, 146 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/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 @@
+<html>
+<body>
+ <h1>Hello!</h1>
+ <a href="/other-page">A link to another page</a>
+</body>
+</html>
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 @@
+<html>
+<head>
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
+</head>
+<body>
+ <h1>Social stuffs</h1>
+ <div>
+ <a href="https://www.twitter.com/joncalhoun">
+ Check me out on twitter
+ <i class="fa fa-twitter" aria-hidden="true"></i>
+ </a>
+ <a href="https://github.com/gophercises">
+ Gophercises is on <strong>Github</strong>!
+ </a>
+ </div>
+</body>
+</html>
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 @@
+<!DOCTYPE html>
+<!--[if lt IE 7]> <html class="ie ie6 lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
+<!--[if IE 7]> <html class="ie ie7 lt-ie9 lt-ie8" lang="en"> <![endif]-->
+<!--[if IE 8]> <html class="ie ie8 lt-ie9" lang="en"> <![endif]-->
+<!--[if IE 9]> <html class="ie ie9" lang="en"> <![endif]-->
+<!--[if !IE]><!-->
+<html lang="en" class="no-ie">
+<!--<![endif]-->
+
+<head>
+ <title>Gophercises - Coding exercises for budding gophers</title>
+</head>
+
+<body>
+ <section class="header-section">
+ <div class="jumbo-content">
+ <div class="pull-right login-section">
+ Already have an account?
+ <a href="#" class="btn btn-login">Login <i class="fa fa-sign-in" aria-hidden="true"></i></a>
+ </div>
+ <center>
+ <img src="https://gophercises.com/img/gophercises_logo.png" style="max-width: 85%; z-index: 3;">
+ <h1>coding exercises for budding gophers</h1>
+ <br/>
+ <form action="/do-stuff" method="post">
+ <div class="input-group">
+ <input type="email" id="drip-email" name="fields[email]" class="btn-input" placeholder="Email Address" required>
+ <button class="btn btn-success btn-lg" type="submit">Sign me up!</button>
+ <a href="/lost">Lost? Need help?</a>
+ </div>
+ </form>
+ <p class="disclaimer disclaimer-box">Gophercises is 100% FREE, but is currently in beta. There will be bugs, and things will be changing significantly over the coming weeks.</p>
+ </center>
+ </div>
+ </section>
+ <section class="footer-section">
+ <div class="row">
+ <div class="col-md-6 col-md-offset-1 vcenter">
+ <div class="quote">
+ "Success is no accident. It is hard work, perseverance, learning, studying, sacrifice and most of all, love of what you are doing or learning to do." - Pele
+ </div>
+ </div>
+ <div class="col-md-4 col-md-offset-0 vcenter">
+ <center>
+ <img src="https://gophercises.com/img/gophercises_lifting.gif" style="width: 80%">
+ <br/>
+ <br/>
+ </center>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col-md-10 col-md-offset-1">
+ <center>
+ <p class="disclaimer">
+ Artwork created by Marcus Olsson (<a href="https://twitter.com/marcusolsson">@marcusolsson</a>), animated by Jon Calhoun (that's me!), and inspired by the original Go Gopher created by Renee French.
+ </p>
+ </center>
+ </div>
+ </div>
+ </section>
+</body>
+</html>
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 @@
+<html>
+<body>
+ <a href="/dog-cat">dog cat <!-- commented text SHOULD NOT be included! --></a>
+</body>
+</html>
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 @@
+<html>
+ <body>
+ <a href="/spaces"> </a>
+ </body>
+</html>