Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Jul 3, 2016
1 parent e5cc9ee commit 5df0663
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
42 changes: 38 additions & 4 deletions bear-tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func TestBadHandler(t *testing.T) {
t.Errorf("handlerBad should not be accepted")
}
}

func TestBadVerbOn(t *testing.T) {
mux := New()
verb := "BLUB"
Expand All @@ -198,6 +199,7 @@ func TestBadVerbOn(t *testing.T) {
t.Errorf("%s should not be accepted", verb)
}
}

func TestBadVerbServe(t *testing.T) {
var (
method = "BLUB"
Expand All @@ -217,6 +219,7 @@ func TestBadVerbServe(t *testing.T) {
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
}
}

func TestDuplicateFailure(t *testing.T) {
var (
handler HandlerFunc
Expand All @@ -235,6 +238,7 @@ func TestDuplicateFailure(t *testing.T) {
}
}
}

func TestDuplicateFailureRoot(t *testing.T) {
var (
handler HandlerFunc
Expand All @@ -253,6 +257,7 @@ func TestDuplicateFailureRoot(t *testing.T) {
}
}
}

func TestMiddleware(t *testing.T) {
var (
middlewares int = 4
Expand Down Expand Up @@ -328,6 +333,7 @@ func TestMiddleware(t *testing.T) {
run(verb)
}
}

func TestMiddlewareRejectionA(t *testing.T) {
mux := New()
one := func(http.ResponseWriter, *http.Request, *Context) {}
Expand All @@ -337,6 +343,7 @@ func TestMiddlewareRejectionA(t *testing.T) {
t.Errorf("middleware with wrong signature was accepted")
}
}

func TestMiddlewareRejectionB(t *testing.T) {
mux := New()
one := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
Expand All @@ -348,6 +355,7 @@ func TestMiddlewareRejectionB(t *testing.T) {
t.Errorf("middleware with wrong signature was accepted")
}
}

func TestMiddlewareRejectionC(t *testing.T) {
mux := New()
one := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
Expand All @@ -356,6 +364,7 @@ func TestMiddlewareRejectionC(t *testing.T) {
t.Errorf("middleware with wrong signature was accepted")
}
}

func TestMiddlewareRejectionD(t *testing.T) {
mux := New()
one := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
Expand All @@ -364,6 +373,7 @@ func TestMiddlewareRejectionD(t *testing.T) {
t.Errorf("middleware with wrong signature was accepted")
}
}

func TestMiddlewareRejectionE(t *testing.T) {
mux := New()
var (
Expand All @@ -389,6 +399,7 @@ func TestMiddlewareRejectionE(t *testing.T) {
t.Errorf("nil middleware was accepted")
}
}

func TestNoHandlers(t *testing.T) {
var (
mux *Mux = New()
Expand All @@ -406,6 +417,7 @@ func TestNoHandlers(t *testing.T) {
}
}
}

func TestNotFoundCustom(t *testing.T) {
var (
method string = "GET"
Expand Down Expand Up @@ -448,6 +460,7 @@ func TestNotFoundCustom(t *testing.T) {
method, pathLost, patternLost, res.Code, wantLost)
}
}

func TestNotFoundNoParams(t *testing.T) {
var (
path = "/foo/bar"
Expand All @@ -472,6 +485,7 @@ func TestNotFoundNoParams(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestNotFoundParams(t *testing.T) {
var (
path = "/foo/BAR/baz"
Expand All @@ -496,6 +510,7 @@ func TestNotFoundParams(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestNotFoundRoot(t *testing.T) {
var (
method string = "GET"
Expand All @@ -512,6 +527,7 @@ func TestNotFoundRoot(t *testing.T) {
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
}
}

func TestNotFoundWildA(t *testing.T) {
var (
path = "/foo"
Expand All @@ -536,6 +552,7 @@ func TestNotFoundWildA(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestNotFoundWildB(t *testing.T) {
var (
method string = "GET"
Expand All @@ -557,6 +574,7 @@ func TestNotFoundWildB(t *testing.T) {
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
}
}

func TestOKMultiRuleParams(t *testing.T) {
var (
method string = "GET"
Expand All @@ -578,6 +596,7 @@ func TestOKMultiRuleParams(t *testing.T) {
t.Errorf("%s %s got %d want %d", method, path, res.Code, want)
}
}

func TestOKNoParams(t *testing.T) {
var (
path = "/foo/bar"
Expand All @@ -599,6 +618,7 @@ func TestOKNoParams(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestOKParams(t *testing.T) {
var (
path = "/foo/BAR/baz/QUX"
Expand All @@ -621,6 +641,7 @@ func TestOKParams(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestOKParamsTrailingSlash(t *testing.T) {
var (
path = "/foo/BAR/baz/QUX/"
Expand All @@ -643,6 +664,7 @@ func TestOKParamsTrailingSlash(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestOKRoot(t *testing.T) {
var (
path = "/"
Expand All @@ -664,6 +686,7 @@ func TestOKRoot(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestOKWildRoot(t *testing.T) {
var (
path = "/"
Expand All @@ -685,6 +708,7 @@ func TestOKWildRoot(t *testing.T) {
verb, path, pattern, want)(t)
}
}

func TestSanitizePatternPrefixSuffix(t *testing.T) {
var (
method = "GET"
Expand All @@ -707,6 +731,7 @@ func TestSanitizePatternPrefixSuffix(t *testing.T) {
t.Errorf("%s %s (%s) got %s want %s", method, path, pattern, body, want)
}
}

func TestSanitizePatternDoubleSlash(t *testing.T) {
var (
method = "GET"
Expand All @@ -729,6 +754,7 @@ func TestSanitizePatternDoubleSlash(t *testing.T) {
t.Errorf("%s %s (%s) got %s want %s", method, path, pattern, body, want)
}
}

func TestUnreachableA(t *testing.T) {
mux := New()
one := func(http.ResponseWriter, *http.Request, *Context) {}
Expand All @@ -739,6 +765,7 @@ func TestUnreachableA(t *testing.T) {
t.Errorf("unreachable A")
}
}

func TestUnreachableB(t *testing.T) {
mux := New()
one := func(http.ResponseWriter, *http.Request, *Context) {}
Expand All @@ -749,6 +776,7 @@ func TestUnreachableB(t *testing.T) {
t.Errorf("unreachable B")
}
}

func TestWildcardCompeting(t *testing.T) {
var (
method string = "GET"
Expand Down Expand Up @@ -797,6 +825,7 @@ func TestWildcardCompeting(t *testing.T) {
method, pathThree, patternThree, body, wantThree)
}
}

func TestWildcardMethod(t *testing.T) {
var (
mux = New()
Expand All @@ -821,6 +850,7 @@ func TestWildcardMethod(t *testing.T) {
}
}
}

func TestWildcardMethodWarning(t *testing.T) {
var (
mux = New()
Expand All @@ -835,6 +865,7 @@ func TestWildcardMethodWarning(t *testing.T) {
t.Errorf("* %s should have registered, but with an error", pattern)
}
}

func TestWildcardNotLast(t *testing.T) {
var (
mux = New()
Expand All @@ -848,6 +879,7 @@ func TestWildcardNotLast(t *testing.T) {
pattern)
}
}

func TestWildcardParams(t *testing.T) {
var (
method = "GET"
Expand All @@ -870,6 +902,7 @@ func TestWildcardParams(t *testing.T) {
t.Errorf("%s %s (%s) got %s want %s", method, path, pattern, body, want)
}
}

func TestAlways(t *testing.T) {
var (
mux *Mux = New()
Expand Down Expand Up @@ -934,6 +967,7 @@ func TestAlwaysBeforeNotFound(t *testing.T) {
res = httptest.NewRecorder()
mux.ServeHTTP(res, req)
}

func TestAlwaysRejection(t *testing.T) {
var (
mux *Mux = New()
Expand All @@ -943,15 +977,15 @@ func TestAlwaysRejection(t *testing.T) {
four func(http.ResponseWriter, *http.Request, *Context)
)
if err := mux.Always(one); err == nil {
t.Errorf("Always requires non-nil HandlerFunc or its signature")
t.Errorf("Always requires non-nil handler")
}
if err := mux.Always(two); err == nil {
t.Errorf("Always requires non-nil HandlerFunc or its signature")
t.Errorf("Always requires non-nil handler")
}
if err := mux.Always(three); err == nil {
t.Errorf("Always requires non-nil HandlerFunc or its signature")
t.Errorf("Always requires non-nil handler")
}
if err := mux.Always(four); err == nil {
t.Errorf("Always requires non-nil HandlerFunc or its signature")
t.Errorf("Always requires non-nil handler")
}
}
10 changes: 9 additions & 1 deletion bear.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@ var (
dyn = regexp.MustCompile(`\{(\w+)\}`)
dbl = regexp.MustCompile(`[\/]{2,}`)
verbs = [8]string{
"CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "TRACE"}
"CONNECT",
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"POST",
"PUT",
"TRACE",
}
)
7 changes: 3 additions & 4 deletions handlerfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ func handlerizeLax(
unreachable := false
for _, function := range functions {
if unreachable {
err := fmt.Errorf(
"bear: %s %s has unreachable middleware",
verb, pattern)
err := fmt.Errorf("bear: %s %s has unreachable middleware", verb, pattern)
return nil, err
}
if handler, followable, err := handlerize(function); err != nil {
Expand All @@ -99,7 +97,8 @@ func handlerizeLax(
return handlers, nil
}

func handlerizeStrict(functions []interface{}) (handlers []HandlerFunc, err error) {
func handlerizeStrict(functions []interface{}) ([]HandlerFunc, error) {
var handlers []HandlerFunc
for _, function := range functions {
switch function.(type) {
case HandlerFunc:
Expand Down
8 changes: 2 additions & 6 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,8 @@ func (mux *Mux) tree(name string) (*tree, *bool) {
// New returns a pointer to a Mux instance
func New() *Mux {
mux := new(Mux)
mux.trees = [8]*tree{
{}, {}, {}, {},
{}, {}, {}, {}}
mux.wild = [8]bool{
false, false, false, false,
false, false, false, false}
mux.trees = [8]*tree{{}, {}, {}, {}, {}, {}, {}, {}}
mux.wild = [8]bool{false, false, false, false, false, false, false, false}
return mux

}

0 comments on commit 5df0663

Please sign in to comment.