forked from 0xERR0R/blocky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit_test.go
46 lines (38 loc) · 1.12 KB
/
split_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
package trie
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("SpltTLD", func() {
It("should split a tld", func() {
key, rest := SplitTLD("www.example.com")
Expect(key).Should(Equal("com"))
Expect(rest).Should(Equal("www.example"))
})
It("should not split a plain string", func() {
key, rest := SplitTLD("example")
Expect(key).Should(Equal("example"))
Expect(rest).Should(Equal(""))
})
It("should not crash with an empty string", func() {
key, rest := SplitTLD("")
Expect(key).Should(Equal(""))
Expect(rest).Should(Equal(""))
})
It("should ignore trailing dots", func() {
key, rest := SplitTLD("www.example.com.")
Expect(key).Should(Equal("com"))
Expect(rest).Should(Equal("www.example"))
key, rest = SplitTLD(rest)
Expect(key).Should(Equal("example"))
Expect(rest).Should(Equal("www"))
})
It("should skip empty parts", func() {
key, rest := SplitTLD("www.example..com")
Expect(key).Should(Equal("com"))
Expect(rest).Should(Equal("www.example."))
key, rest = SplitTLD(rest)
Expect(key).Should(Equal("example"))
Expect(rest).Should(Equal("www"))
})
})