-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_test.go
57 lines (50 loc) · 1.1 KB
/
format_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
package urlparser
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFormat(t *testing.T) {
tests := []struct {
name string
rawUrl string
format string
expected string
expectErr bool
}{
{
name: "all basic fields",
format: "{scheme}://{authority}{relativeUrl}",
expected: refUrl,
},
{
name: "duplicate some fields",
format: "{scheme} {tld} {scheme} {path} {tld}",
expected: "https co.uk https /lorem/ipsum/dolor/sit.html co.uk",
},
{
name: "with partial placeholders",
format: "{{scheme}{{tld}{err{scheme}}}{{tld}}",
expected: "{https{co.uk{errhttps}}{co.uk}",
},
{
name: "with invalid placeholders",
format: "{scheme} {tld} {wrong}",
expectErr: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require := require.New(t)
if test.rawUrl == "" {
test.rawUrl = refUrl
}
result, err := Format(test.rawUrl, test.format)
if test.expectErr {
require.Error(err)
} else {
require.NoError(err)
}
require.Equal(test.expected, result)
})
}
}