forked from nprimo/check-links
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
62 lines (49 loc) · 1.01 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"reflect"
"testing"
)
var getLinksTestCases = []struct {
Cont []byte
Exp []string
}{
{
[]byte(`# title here
asdf
asdf
sadf
asdfasdfsadf
asdfdasf asdfasdf
In the text check [http://something1](http://something) and what else.
And here you go [a file](./some/where/inside).
[A valid link](https://google.com) somewhere
... `), []string{
"http://something",
"./some/where/inside",
"https://google.com",
},
},
{
[]byte(`....
http://bing.com
And a [link](https://bing-link.com) somewhere in the text.
[an image here](./dir/images/img1.png) and go.
And [another link](dir/images/img1.png) and go. `),
[]string{
"https://bing-link.com",
"./dir/images/img1.png",
"dir/images/img1.png",
},
},
}
func TestGetLinks(t *testing.T) {
for i, tc := range getLinksTestCases {
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
got := getLinks(tc.Cont)
if !reflect.DeepEqual(got, tc.Exp) {
t.Fatalf("\ngot: %#v\nexp: %#v", got, tc.Exp)
}
})
}
}