-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhelper_test.go
66 lines (55 loc) · 2.48 KB
/
helper_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
package echo
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func testHandlerFunc(ctx Context) error {
return nil
}
type testHandler struct {
}
func (t *testHandler) Handle(ctx Context) error {
return nil
}
func TestHandlerPath(t *testing.T) {
ppath := HandlerPath(testHandlerFunc)
assert.Equal(t, "github.com/webx-top/echo.testHandlerFunc", ppath)
ppath = HandlerPath(HandlerFunc(testHandlerFunc))
assert.Equal(t, "github.com/webx-top/echo.testHandlerFunc", ppath)
ppath = HandlerPath(&testHandler{})
assert.Equal(t, "github.com/webx-top/echo.testHandler", ppath)
ppath = HandlerTmpl(`github.com/webx-top/echo.(*TestHandler).Index-fm`)
assert.Equal(t, "/echo/test_handler/index", ppath)
}
func TestLogIf(t *testing.T) {
LogIf(errors.New(`test`), `debug`)
}
func TestURLEncode(t *testing.T) {
raw := `1 2?a=b`
encoded := URLEncode(raw)
assert.Equal(t, "1+2%3Fa%3Db", encoded)
content, _ := URLDecode(encoded)
assert.Equal(t, raw, content)
encoded = URLEncode(raw, true)
assert.Equal(t, "1%202%3Fa%3Db", encoded)
content, _ = URLDecode(encoded, true)
assert.Equal(t, raw, content)
}
func TestInSliceFold(t *testing.T) {
assert.True(t, InSliceFold(`post`, []string{`POST`}))
}
func TestParseTemplateError(t *testing.T) {
content := `template: /Users/hank/go/src/github.com/admpub/nging/template/backend/manager/role_edit_perm_page.html:7:831: executing "/Users/hank/go/src/github.com/admpub/nging/template/backend/manager/role_edit_perm_page.html" at <call>: wrong number of args for call: want at least 1 got 0`
matches := regErrorTemplateFile.FindAllStringSubmatch(content, -1)
assert.Equal(t, `template: /Users/hank/go/src/github.com/admpub/nging/template/backend/manager/role_edit_perm_page.html:7:831: `, matches[0][0])
assert.Equal(t, `/Users/hank/go/src/github.com/admpub/nging/template/backend/manager/role_edit_perm_page.html`, matches[0][1])
assert.Equal(t, `7`, matches[0][2])
assert.Equal(t, `831`, matches[0][3])
//panic(Dump(matches, false))
content = `template: /Users/hank/go/src/github.com/webx-top/echo/middleware/render/standard/test/template/test.html:6: function "Now2" not defined`
matches = regErrorTemplateFile.FindAllStringSubmatch(content, -1)
assert.Equal(t, `template: /Users/hank/go/src/github.com/webx-top/echo/middleware/render/standard/test/template/test.html:6: `, matches[0][0])
assert.Equal(t, `/Users/hank/go/src/github.com/webx-top/echo/middleware/render/standard/test/template/test.html`, matches[0][1])
assert.Equal(t, `6`, matches[0][2])
}