iris/macro/handler/handler_test.go
Gerasimos (Makis) Maropoulos 3945fa68d1 obey the vote of @1370 (77-111 at this point) - add import suffix on iris repository
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c.


Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
2019-10-25 01:27:02 +03:00

42 lines
1023 B
Go

package handler
import (
"testing"
"github.com/kataras/iris/v12/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)
}
}
}
}