-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreverse_test.go
56 lines (42 loc) · 1.05 KB
/
reverse_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
package reverse
import (
"fmt"
"testing"
)
func TestReverse(t *testing.T) {
showError := func(info string) {
t.Error(fmt.Sprintf("Error: %s. urlStore: %s", info, Urls))
}
if Urls.MustAdd("firstUrl", "/first") != "/first" {
showError("0")
}
if Urls.MustAdd("helloUrl", "/hello/:p1:p2", "1", "2") != "/hello/:p1:p2" {
showError("0-1")
}
Urls.MustAdd("secondUrl", "/second/:param/:param2", ":param", ":param2")
// re := regexp.MustCompile("^/comment/(?P<id>\d+)$")
Urls.MustAdd("thirdUrl", "/comment/:p1", ":p1")
if Urls.getParam("helloUrl", 1) != "2" {
showError("1")
}
if Urls.Get("helloUrl") != "/hello/:p1:p2" {
showError("2")
}
if Urls.getParam("secondUrl", 0) != ":param" {
showError("3")
}
if Urls.MustReverse("firstUrl") != "/first" {
showError("4")
}
if Urls.MustReverse("secondUrl", "123", "ABC") != "/second/123/ABC" {
showError("5")
}
if Urls.MustReverse("thirdUrl", "123") != "/comment/123" {
t.Error(Urls.Reverse("thirdUrl", "123"))
showError("6")
}
Clear()
if len(Urls.store) != 0 {
showError("7")
}
}