mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
Version 11 released. Read https://github.com/kataras/iris/blob/master/HISTORY.md#su-21-october-2018--v1100
Former-commit-id: fe6305deed00e170bf4d39a12c0644fe686e0a24
This commit is contained in:
41
macro/handler/handler_test.go
Normal file
41
macro/handler/handler_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/macro"
|
||||
)
|
||||
|
||||
func TestCanMakeHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
src string
|
||||
needsHandler bool
|
||||
}{
|
||||
{"/static/static", false},
|
||||
{"/{myparam}", false},
|
||||
{"/{myparam min(1)}", true},
|
||||
{"/{myparam else 500}", true},
|
||||
{"/{myparam else 404}", false},
|
||||
{"/{myparam:string}/static", false},
|
||||
{"/{myparam:int}", true},
|
||||
{"/static/{myparam:int}/static", true},
|
||||
{"/{myparam:path}", false},
|
||||
{"/{myparam:path min(1) else 404}", true},
|
||||
}
|
||||
|
||||
availableMacros := *macro.Defaults
|
||||
for i, tt := range tests {
|
||||
tmpl, err := macro.Parse(tt.src, availableMacros)
|
||||
if err != nil {
|
||||
t.Fatalf("[%d] '%s' failed to be parsed: %v", i, tt.src, err)
|
||||
}
|
||||
|
||||
if got := CanMakeHandler(tmpl); got != tt.needsHandler {
|
||||
if tt.needsHandler {
|
||||
t.Fatalf("[%d] '%s' expected to be able to generate an evaluator handler instead of a nil one", i, tt.src)
|
||||
} else {
|
||||
t.Fatalf("[%d] '%s' should not need an evaluator handler", i, tt.src)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user