-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlua_test.go
68 lines (63 loc) · 1.79 KB
/
lua_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
package moontpl
import (
"testing"
)
func TestGetPathParams(t *testing.T) {
type entry struct {
filename string
params pathParams
}
for _, entry := range []entry{
{"/test[x=1].html", pathParams{"x": "1"}},
{"/test[aa=bb,cc=dddd].html", pathParams{"aa": "bb", "cc": "dddd"}},
{"/test[key = value , a = 123].html", pathParams{"key": "value", "a": "123"}},
{"/test[].html", pathParams{}},
{"/test.html", pathParams{}},
} {
params := getPathParams(entry.filename)
if len(params) != len(entry.params) {
t.Errorf("expected: %v, got %v", entry.params, params)
t.Fail()
}
for k, v := range entry.params {
if params[k] != v {
t.Errorf("expected: %v, got %v", entry.params, params)
t.Fail()
}
}
}
}
func TestSetPathParams(t *testing.T) {
type entry struct {
input string
params pathParams
expected string
}
for _, entry := range []entry{
{"", pathParams{}, ""},
{"/test[x=1].html", pathParams{"x": "2"}, "/test[x=2].html"},
{"/test[x=1]", pathParams{"x": "2"}, "/test[x=2]"},
{"/test", pathParams{"x": "2"}, "/test[x=2]"},
{"/test", pathParams{}, "/test"},
{"/test[x=1,y=2].html", pathParams{"x": "3"}, "/test[x=3,y=2].html"},
} {
filename := setPathParams(entry.input, entry.params, false)
if filename != entry.expected {
t.Errorf("expected: %v, got %v", entry.expected, filename)
}
}
}
func TestRelativePath(t *testing.T) {
for _, entry := range [][]string{
{"/a.png", "/dir1/index.html", "../a.png"},
{"/dir2/a.png", "/dir1/index.html", "../dir2/a.png"},
{"/dir1/a.png", "/dir1/index.html", "a.png"},
{"/dir1/dir3/a.png", "/dir1/index.html", "dir3/a.png"},
{"a.png", "/dir1/index.html", "a.png"},
} {
actual := relativeFrom(entry[0], entry[1])
if actual != entry[2] {
t.Errorf("expected: %v, got %v", entry[2], actual)
}
}
}