-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathurl_test.go
More file actions
72 lines (56 loc) · 2.18 KB
/
url_test.go
File metadata and controls
72 lines (56 loc) · 2.18 KB
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
package com
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSplitHostPort(t *testing.T) {
host, port := SplitHostPort(`[1:2:2:3]:9999`)
assert.Equal(t, `[1:2:2:3]`, host)
assert.Equal(t, `9999`, port)
host, port = SplitHostPort(`example.com:9999`)
assert.Equal(t, `example.com`, host)
assert.Equal(t, `9999`, port)
host, port = SplitHostPort(`127.0.0.1:9999`)
assert.Equal(t, `127.0.0.1`, host)
assert.Equal(t, `9999`, port)
}
func TestSplitHostPort2(t *testing.T) {
host, port := SplitHostPort(`[1:2:2:3]`)
assert.Equal(t, `[1:2:2:3]`, host)
assert.Equal(t, ``, port)
host, port = SplitHostPort(`example.com`)
assert.Equal(t, `example.com`, host)
assert.Equal(t, ``, port)
host, port = SplitHostPort(`127.0.0.1`)
assert.Equal(t, `127.0.0.1`, host)
assert.Equal(t, ``, port)
}
func TestRawURLEncode(t *testing.T) {
rawText := ` +Gopher`
encoded := RawURLEncode(rawText)
expected := `%20%2BGopher`
assert.Equal(t, expected, encoded)
result, _ := URLDecode(expected)
assert.Equal(t, rawText, result)
result, _ = RawURLDecode(expected)
assert.Equal(t, rawText, result)
}
func TestAbsURL(t *testing.T) {
pageURL := AbsURL(`https://www.coscms.com/system/download/index`, `../download2/index`)
assert.Equal(t, `https://www.coscms.com/system/download2/index`, pageURL)
pageURL = AbsURL(`https://www.coscms.com/system/download/index`, `../../system2/download2/index`)
assert.Equal(t, `https://www.coscms.com/system2/download2/index`, pageURL)
pageURL = AbsURL(`https://www.coscms.com/system/download/index`, `/payment/index/index`)
assert.Equal(t, `https://www.coscms.com/payment/index/index`, pageURL)
pageURL = AbsURL(`https://www.coscms.com/system/download/index`, `./payment/index/index`)
assert.Equal(t, `https://www.coscms.com/system/download/payment/index/index`, pageURL)
fmt.Println(`SelfDir:`, SelfDir())
fmt.Println(`SelfPath:`, SelfPath())
}
func TestFullURL(t *testing.T) {
pageURL := FullURL(`https://www.coscms.com/`, `/download2/index`)
assert.Equal(t, `https://www.coscms.com/download2/index`, pageURL)
pageURL = FullURL(`https://www.coscms.com`, `/download2/index`)
assert.Equal(t, `https://www.coscms.com/download2/index`, pageURL)
}