-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnormalizers_test.go
70 lines (63 loc) · 1.82 KB
/
normalizers_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
package main
import (
"io"
"os"
"testing"
"github.com/usher2/u2ckdump/internal/logger"
)
func init() {
logger.LogInit(io.Discard, os.Stdout, os.Stderr, os.Stderr)
}
// TestNormalizeDomain tests the NormalizeDomain function.
func TestNormalizeDomain(t *testing.T) {
testCases := []struct {
input string
expected string
}{
{"example.com", "example.com"},
{"http://example.com", "example.com"},
{"http:\\example.com", "example.com"},
{"http//example.com", "example.com"},
{"//example.com", "example.com"},
{"http:/example.com", "example.com"},
{"http/exmaple.com", "exmaple.com"},
{"http://example.com/test", "example.com"},
{"Example,com", "example.com"},
{"example . com", "example.com"},
{"*.example.com", "example.com"},
{"example.com.", "example.com"},
}
for _, tc := range testCases {
t.Run(tc.input, func(t *testing.T) {
result := NormalizeDomain(tc.input)
if result != tc.expected {
t.Errorf("expected %q, got %q", tc.expected, result)
}
})
}
}
// TestNormalizeURL tests the NormalizeURL function.
func TestNormalizeURL(t *testing.T) {
testCases := []struct {
input string
expected string
}{
{"http://example.com", "http://example.com"},
{"https://example.com", "https://example.com"},
{"http:\\\\example.com", "http://example.com"},
{"http:/example.com", "http://example.com"},
{"http:example.com", "http://example.com"},
{"http://Example,com", "http://example.com"},
{"http://example.com/test%t", "http://example.com/test%t"},
{"http://example.com/test#fragment", "http://example.com/test"},
{"https://example.com:8080", "https://example.com:8080"},
}
for _, tc := range testCases {
t.Run(tc.input, func(t *testing.T) {
result := NormalizeURL(tc.input)
if result != tc.expected {
t.Errorf("expected %q, got %q", tc.expected, result)
}
})
}
}