-
Notifications
You must be signed in to change notification settings - Fork 5
/
pack_test.go
146 lines (140 loc) · 3.15 KB
/
pack_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package hostutils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPack(t *testing.T) {
testPack(t, nil, nil)
testPack(t, []string{}, []string{})
testPack(t,
[]string{},
[]string{
"#example101c.com",
"#example103c.com",
"#example104c.com",
})
testPack(t,
[]string{"example[101-103]c.com"},
[]string{"example101c.com example102c.com\nexample103c.com"})
testPack(t, []string{"www.example.com"}, []string{"www.example.com"})
testPack(t,
[]string{"example[101-105]c.com"},
[]string{
"example101c.com",
"example102c.com",
"example105c.com",
"example104c.com",
"example103c.com",
"example103c.com",
})
testPack(t,
[]string{"example-100-[101-105]c.com"},
[]string{
"example-100-101c.com",
"example-100-102c.com",
"example-100-105c.com",
"example-100-104c.com",
"example-100-103c.com",
"example-100-103c.com",
})
testPack(t,
[]string{"example[01-03]c.com"},
[]string{
"example01c.com",
"example03c.com",
"example02c.com",
})
testPack(t,
[]string{"example[101-103,201]c.com"},
[]string{
"example101c.com",
"example102c.com",
"example103c.com",
"example201c.com",
})
testPack(t,
[]string{"example[101,103-105,201]c.com"},
[]string{
"example101c.com",
"example103c.com",
"example104c.com",
"example105c.com",
"example201c.com",
})
testPack(t,
[]string{"example[101,103-105,201]c.com", "test[101-102]z.com"},
[]string{
"example101c.com",
"example103c.com",
"example104c.com",
"example105c.com",
"example201c.com",
"test101z.com",
"test102z.com",
})
testPack(t,
[]string{"example[101,103,105,201]c.com", "test[101-102]z.com"},
[]string{
"example101c.com",
"example103c.com",
"#example104c.com",
"example105c.com",
"example201c.com",
"test101z.com",
"test102z.com",
})
testPack(t,
[]string{"example[01-02,102,0003]c.com"},
[]string{
"example01c.com",
"example02c.com",
"example102c.com",
"example0003c.com",
})
testPack(t,
[]string{"example[101-102]c.grp1.com"},
[]string{
"example101c.grp1.com",
"example102c.grp1.com",
})
testPack(t,
[]string{"example[101-102]"},
[]string{
"example101",
"example102",
})
}
func TestPackString(t *testing.T) {
testPackString(t, []string{}, "")
testPackString(t, []string{}, `#example101c.com
#example102c.com
#example103c.com`,
)
testPackString(t, []string{"example[101-103]c.com"}, "example101c.com example102c.com\nexample103c.com")
testPackString(t, []string{"www.example.com"}, "www.example.com")
testPackString(t,
[]string{"example[101-105]c.com"}, `
example101c.com
example102c.com
example105c.com
example104c.com
example103c.com
example103c.com`,
)
testPackString(t, []string{"example-100-[101-105]c.com"}, `
example-100-101c.com
example-100-102c.com
example-100-105c.com
example-100-104c.com
example-100-103c.com
example-100-103c.com`,
)
}
func testPack(t *testing.T, expected []string, input []string) {
t.Helper()
assert.Equal(t, expected, Pack(input))
}
func testPackString(t *testing.T, expected []string, input string) {
t.Helper()
assert.Equal(t, expected, PackString(input))
}