File: match_test.go

package info (click to toggle)
golang-github-zenazn-goji 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (3)
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
package web

import (
	"net/http"
	"regexp"
	"testing"
)

var rawPatterns = []PatternType{
	"/hello/:name",
	regexp.MustCompile("^/hello/(?P<name>[^/]+)$"),
	testPattern{},
}

func TestRawPattern(t *testing.T) {
	t.Parallel()

	for _, p := range rawPatterns {
		m := Match{Pattern: ParsePattern(p)}
		if rp := m.RawPattern(); rp != p {
			t.Errorf("got %#v, expected %#v", rp, p)
		}
	}
}

type httpHandlerOnly struct{}

func (httpHandlerOnly) ServeHTTP(w http.ResponseWriter, r *http.Request) {}

type handlerOnly struct{}

func (handlerOnly) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {}

var rawHandlers = []HandlerType{
	func(w http.ResponseWriter, r *http.Request) {},
	func(c C, w http.ResponseWriter, r *http.Request) {},
	httpHandlerOnly{},
	handlerOnly{},
}

func TestRawHandler(t *testing.T) {
	t.Parallel()

	for _, h := range rawHandlers {
		m := Match{Handler: parseHandler(h)}
		if rh := m.RawHandler(); !funcEqual(rh, h) {
			t.Errorf("got %#v, expected %#v", rh, h)
		}
	}
}