Debian Codegraph @

labels_test.go

raw symbols SCIP
1 package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/
2
3 import "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
4
5 func TestCompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestCompareDomainName().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
6 s1 := "www.miek.nl."
7 s2 := "miek.nl."
8 s3 := "www.bla.nl."
9 s4 := "nl.www.bla."
10 s5 := "nl."
11 s6 := "miek.nl."
12
13 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().(s1, s2) != 2 {
14 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s with %s should be %d", s1, s2, 2)
15 }
16 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().(s1, s3) != 1 {
17 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s with %s should be %d", s1, s3, 1)
18 }
19 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().(s3, s4) != 0 {
20 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s with %s should be %d", s3, s4, 0)
21 }
22 // Non qualified tests
23 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().(s1, s5) != 1 {
24 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s with %s should be %d", s1, s5, 1)
25 }
26 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().(s1, s6) != 2 {
27 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s with %s should be %d", s1, s5, 2)
28 }
29
30 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().(s1, ".") != 0 {
31 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s with %s should be %d", s1, s5, 0)
32 }
33 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().(".", ".") != 0 {
34 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s with %s should be %d", ".", ".", 0)
35 }
36 if CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().("test.com.", "TEST.COM.") != 2 {
37 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("test.com. and TEST.COM. should be an exact match")
38 }
39 }
40
41 func TestSplitscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestSplit().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
42 splitter := map[string]int{
43 "www.miek.nl.": 3,
44 "www.miek.nl": 3,
45 "www..miek.nl": 4,
46 `www\.miek.nl.`: 2,
47 `www\\.miek.nl.`: 3,
48 `www\\\.miek.nl.`: 2,
49 ".": 0,
50 "nl.": 1,
51 "nl": 1,
52 "com.": 1,
53 ".com.": 2,
54 }
55 for s, i := range splitter {
56 if x := len(Splitscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Split().(s)); x != i {
57 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("labels should be %d, got %d: %s %v", i, x, s, Splitscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Split().(s))
58 }
59 }
60 }
61
62 func TestSplit2scip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestSplit2().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
63 splitter := map[string][]int{
64 "www.miek.nl.": {0, 4, 9},
65 "www.miek.nl": {0, 4, 9},
66 "nl": {0},
67 }
68 for s, i := range splitter {
69 x := Splitscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Split().(s)
70 switch len(i) {
71 case 1:
72 if x[0] != i[0] {
73 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("labels should be %v, got %v: %s", i, x, s)
74 }
75 default:
76 if x[0] != i[0] || x[1] != i[1] || x[2] != i[2] {
77 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("labels should be %v, got %v: %s", i, x, s)
78 }
79 }
80 }
81 }
82
83 func TestNextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestNextLabel().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
84 type next struct {
85 string
86 int
87 }
88 nexts := map[next]int{
89 {"", 1}: 0,
90 {"www.miek.nl.", 0}: 4,
91 {"www.miek.nl.", 4}: 9,
92 {"www.miek.nl.", 9}: 12,
93 }
94 for s, i := range nexts {
95 x, ok := NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(s.string, s.int)
96 if i != x {
97 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("label should be %d, got %d, %t: next %d, %s", i, x, ok, s.int, s.string)
98 }
99 }
100 }
101
102 func TestPrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestPrevLabel().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
103 type prev struct {
104 string
105 int
106 }
107 prever := map[prev]int{
108 {"", 1}: 0,
109 {"www.miek.nl.", 0}: 12,
110 {"www.miek.nl.", 1}: 9,
111 {"www.miek.nl.", 2}: 4,
112
113 {"www.miek.nl", 0}: 11,
114 {"www.miek.nl", 1}: 9,
115 {"www.miek.nl", 2}: 4,
116
117 {"www.miek.nl.", 5}: 0,
118 {"www.miek.nl", 5}: 0,
119
120 {"www.miek.nl.", 3}: 0,
121 {"www.miek.nl", 3}: 0,
122 }
123 for s, i := range prever {
124 x, ok := PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().(s.string, s.int)
125 if i != x {
126 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("label should be %d, got %d, %t: previous %d, %s", i, x, ok, s.int, s.string)
127 }
128 }
129 }
130
131 func TestCountLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestCountLabel().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
132 splitter := map[string]int{
133 "www.miek.nl.": 3,
134 "www.miek.nl": 3,
135 "nl": 1,
136 ".": 0,
137 }
138 for s, i := range splitter {
139 x := CountLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CountLabel().(s)
140 if x != i {
141 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("CountLabel should have %d, got %d", i, x)
142 }
143 }
144 }
145
146 func TestSplitDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestSplitDomainName().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
147 labels := map[string][]string{
148 "miek.nl": {"miek", "nl"},
149 ".": nil,
150 "www.miek.nl.": {"www", "miek", "nl"},
151 "www.miek.nl": {"www", "miek", "nl"},
152 "www..miek.nl": {"www", "", "miek", "nl"},
153 `www\.miek.nl`: {`www\.miek`, "nl"},
154 `www\\.miek.nl`: {`www\\`, "miek", "nl"},
155 ".www.miek.nl.": {"", "www", "miek", "nl"},
156 }
157 domainLoop:
158 for domain, splits := range labels {
159 parts := SplitDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SplitDomainName().(domain)
160 if len(parts) != len(splits) {
161 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
162 continue domainLoop
163 }
164 for i := range parts {
165 if parts[i] != splits[i] {
166 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("SplitDomainName returned %v for %s, expected %v", parts, domain, splits)
167 continue domainLoop
168 }
169 }
170 }
171 }
172
173 func TestIsDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestIsDomainName().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
174 type ret struct {
175 ok bool
176 lab int
177 }
178 names := map[string]*ret{
179 ".": {true, 1},
180 "..": {false, 0},
181 "double-dot..test": {false, 1},
182 ".leading-dot.test": {false, 0},
183 "@.": {true, 1},
184 "www.example.com": {true, 3},
185 "www.e%ample.com": {true, 3},
186 "www.example.com.": {true, 3},
187 "mi\\k.nl.": {true, 2},
188 "mi\\k.nl": {true, 2},
189 longestDomainscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/longestDomain.: {true, 4},
190 longestUnprintableDomainscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/longestUnprintableDomain.: {true, 4},
191 }
192 for d, ok := range names {
193 l, k := IsDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/IsDomainName().(d)
194 if ok.ok != k || ok.lab != l {
195 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().(" got %v %d for %s ", k, l, d)
196 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("have %v %d for %s ", ok.ok, ok.lab, d)
197 }
198 }
199 }
200
201 func TestIsFqdnEscapedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestIsFqdnEscaped().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
202 for s, expect := range map[string]bool{
203 ".": true,
204 "\\.": false,
205 "\\\\.": true,
206 "\\\\\\.": false,
207 "\\\\\\\\.": true,
208 "a.": true,
209 "a\\.": false,
210 "a\\\\.": true,
211 "a\\\\\\.": false,
212 "ab.": true,
213 "ab\\.": false,
214 "ab\\\\.": true,
215 "ab\\\\\\.": false,
216 "..": true,
217 ".\\.": false,
218 ".\\\\.": true,
219 ".\\\\\\.": false,
220 "example.org.": true,
221 "example.org\\.": false,
222 "example.org\\\\.": true,
223 "example.org\\\\\\.": false,
224 "example\\.org.": true,
225 "example\\\\.org.": true,
226 "example\\\\\\.org.": true,
227 "\\example.org.": true,
228 "\\\\example.org.": true,
229 "\\\\\\example.org.": true,
230 } {
231 if got := IsFqdnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/IsFqdn().(s); got != expect {
232 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("IsFqdn(%q) = %t, expected %t", s, got, expect)
233 }
234 }
235 }
236
237 func TestCanonicalNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestCanonicalName().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
238 for s, expect := range map[string]string{
239 "": ".",
240 ".": ".",
241 "tld": "tld.",
242 "tld.": "tld.",
243 "example.test": "example.test.",
244 "Lower.CASE.test.": "lower.case.test.",
245 "*.Test": "*.test.",
246 "ÉxamplE.com": "Éxample.com.",
247 "É.com": "É.com.",
248 } {
249 if got := CanonicalNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CanonicalName().(s); got != expect {
250 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("CanonicalName(%q) = %q, expected %q", s, got, expect)
251 }
252 }
253 }
254
255 func BenchmarkSplitLabelsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkSplitLabels().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
256 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
257 Splitscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Split().("www.example.com.")
258 }
259 }
260
261 func BenchmarkLenLabelsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkLenLabels().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
262 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
263 CountLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CountLabel().("www.example.com.")
264 }
265 }
266
267 func BenchmarkCompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkCompareDomainName().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
268 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
269 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
270 CompareDomainNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CompareDomainName().("www.example.com.", "aa.example.com.")
271 }
272 }
273
274 func BenchmarkIsSubDomainscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkIsSubDomain().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
275 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
276 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
277 IsSubDomainscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/IsSubDomain().("www.example.com.", "aa.example.com.")
278 IsSubDomainscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/IsSubDomain().("example.com.", "aa.example.com.")
279 IsSubDomainscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/IsSubDomain().("miek.nl.", "aa.example.com.")
280 }
281 }
282
283 func BenchmarkNextLabelSimplescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkNextLabelSimple().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
284 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
285 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
286 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().("www.example.com", 0)
287 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().("www.example.com", 5)
288 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().("www.example.com", 12)
289 }
290 }
291
292 func BenchmarkPrevLabelSimplescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkPrevLabelSimple().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
293 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
294 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
295 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().("www.example.com", 0)
296 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().("www.example.com", 5)
297 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().("www.example.com", 12)
298 }
299 }
300
301 func BenchmarkNextLabelComplexscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkNextLabelComplex().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
302 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
303 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
304 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(`www\.example.com`, 0)
305 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(`www\\.example.com`, 0)
306 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(`www\\\.example.com`, 0)
307 }
308 }
309
310 func BenchmarkPrevLabelComplexscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkPrevLabelComplex().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
311 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
312 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
313 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().(`www\.example.com`, 10)
314 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().(`www\\.example.com`, 10)
315 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().(`www\\\.example.com`, 10)
316 }
317 }
318
319 func BenchmarkNextLabelMixedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkNextLabelMixed().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
320 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
321 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
322 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().("www.example.com", 0)
323 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(`www\.example.com`, 0)
324 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().("www.example.com", 5)
325 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(`www\\.example.com`, 0)
326 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().("www.example.com", 12)
327 NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(`www\\\.example.com`, 0)
328 }
329 }
330
331 func BenchmarkPrevLabelMixedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkPrevLabelMixed().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
332 b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().()
333 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; i++ {
334 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().("www.example.com", 0)
335 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().(`www\.example.com`, 10)
336 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().("www.example.com", 5)
337 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().(`www\\.example.com`, 10)
338 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().("www.example.com", 12)
339 PrevLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PrevLabel().(`www\\\.example.com`, 10)
340 }
341 }