-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkscanner_test.go
77 lines (73 loc) · 2.22 KB
/
linkscanner_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package linkscanner
import (
"strings"
"testing"
)
func TestFixWWW(t *testing.T) {
var testlink = "www.example.com"
var resultlink = "http://www.example.com"
linklist, errs := HTTPScanner(testlink)
if len(errs) != 0 {
t.Errorf("FAIL: Unexpected errors parsing WWW %v", errs)
}
if len(linklist) > 0 && len(linklist) == 1 {
if linklist[0] != resultlink {
t.Errorf("FAIL: WWW not fixed %s became %s", testlink, linklist[0])
}
}
FixWWW(false)
linklist, errs = HTTPScanner(testlink)
if len(errs) != 0 {
t.Errorf("FAIL: Unexpected errors parsing WWW %v", errs)
}
if len(linklist) > 0 && len(linklist) == 1 {
if linklist[0] != testlink {
t.Errorf("FAIL: WWW incorrectly changed %s became %s", testlink, linklist[0])
}
}
}
func TestIndexOutput(t *testing.T) {
var testSentence = "this is a short www.example.com sentence."
var pos = 5
linklist, errs := HTTPScannerIndex(testSentence)
if len(errs) != 0 {
t.Errorf("FAIL: Unexpected errors parsing WWW %v", errs)
}
if len(linklist) > 0 && len(linklist) == 1 {
for x := range linklist {
for k := range linklist[x] {
if k != pos {
t.Errorf("FAIL: Index returned is different than expected %d received, expected %d", k, pos)
}
}
}
}
}
func TestLoadExtensions(t *testing.T) {
originalLen := len(ListProtocols())
// Info is a good example, registry here: https://en.wikipedia.org/wiki/Info_URI_scheme
arr := []string{"pw://", "info:ark/", "go:", "info:pronom/", "info:hdl/"}
LoadExtensions(arr)
if len(ListProtocols()) != (originalLen + len(arr)) {
t.Errorf("FAIL: length of protocols (%d) following extension is not the correct length (%d)", originalLen, len(arr))
}
template := "{{proto}}"
var testSentence = "this is a short {{proto}}example.com sentence."
var pos = 5
for _, proto := range arr {
testString := strings.Replace(testSentence, template, proto, 1)
linklist, errs := HTTPScannerIndex(testString)
if len(errs) != 0 {
t.Errorf("FAIL: Unexpected errors parsing %s %v", proto, errs)
}
if len(linklist) > 0 && len(linklist) == 1 {
for x := range linklist {
for k := range linklist[x] {
if k != pos {
t.Errorf("FAIL: Index returned is different than expected %d received, expected %d", k, pos)
}
}
}
}
}
}