Add tests for hyphenated variable names
This commit is contained in:
90
mux_test.go
90
mux_test.go
@@ -144,6 +144,33 @@ func TestHost(t *testing.T) {
|
|||||||
path: "",
|
path: "",
|
||||||
shouldMatch: false,
|
shouldMatch: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Host route with hyphenated name and pattern, match",
|
||||||
|
route: new(Route).Host("aaa.{v-1:[a-z]{3}}.ccc"),
|
||||||
|
request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
|
||||||
|
vars: map[string]string{"v-1": "bbb"},
|
||||||
|
host: "aaa.bbb.ccc",
|
||||||
|
path: "",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Host route with hyphenated name and pattern, additional capturing group, match",
|
||||||
|
route: new(Route).Host("aaa.{v-1:[a-z]{2}(b|c)}.ccc"),
|
||||||
|
request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
|
||||||
|
vars: map[string]string{"v-1": "bbb"},
|
||||||
|
host: "aaa.bbb.ccc",
|
||||||
|
path: "",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Host route with multiple hyphenated names and patterns, match",
|
||||||
|
route: new(Route).Host("{v-1:[a-z]{3}}.{v-2:[a-z]{3}}.{v-3:[a-z]{3}}"),
|
||||||
|
request: newRequest("GET", "http://aaa.bbb.ccc/111/222/333"),
|
||||||
|
vars: map[string]string{"v-1": "aaa", "v-2": "bbb", "v-3": "ccc"},
|
||||||
|
host: "aaa.bbb.ccc",
|
||||||
|
path: "",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Path route with single pattern with pipe, match",
|
title: "Path route with single pattern with pipe, match",
|
||||||
route: new(Route).Path("/{category:a|b/c}"),
|
route: new(Route).Path("/{category:a|b/c}"),
|
||||||
@@ -278,6 +305,33 @@ func TestPath(t *testing.T) {
|
|||||||
path: "/a/product_name/1",
|
path: "/a/product_name/1",
|
||||||
shouldMatch: true,
|
shouldMatch: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Path route with hyphenated name and pattern, match",
|
||||||
|
route: new(Route).Path("/111/{v-1:[0-9]{3}}/333"),
|
||||||
|
request: newRequest("GET", "http://localhost/111/222/333"),
|
||||||
|
vars: map[string]string{"v-1": "222"},
|
||||||
|
host: "",
|
||||||
|
path: "/111/222/333",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Path route with multiple hyphenated names and patterns, match",
|
||||||
|
route: new(Route).Path("/{v-1:[0-9]{3}}/{v-2:[0-9]{3}}/{v-3:[0-9]{3}}"),
|
||||||
|
request: newRequest("GET", "http://localhost/111/222/333"),
|
||||||
|
vars: map[string]string{"v-1": "111", "v-2": "222", "v-3": "333"},
|
||||||
|
host: "",
|
||||||
|
path: "/111/222/333",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Path route with multiple hyphenated names and patterns with pipe, match",
|
||||||
|
route: new(Route).Path("/{product-category:a|(b/c)}/{product-name}/{product-id:[0-9]+}"),
|
||||||
|
request: newRequest("GET", "http://localhost/a/product_name/1"),
|
||||||
|
vars: map[string]string{"product-category": "a", "product-name": "product_name", "product-id": "1"},
|
||||||
|
host: "",
|
||||||
|
path: "/a/product_name/1",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -633,6 +687,42 @@ func TestQueries(t *testing.T) {
|
|||||||
path: "",
|
path: "",
|
||||||
shouldMatch: false,
|
shouldMatch: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Queries route with hyphenated name, match",
|
||||||
|
route: new(Route).Queries("foo", "{v-1}"),
|
||||||
|
request: newRequest("GET", "http://localhost?foo=bar"),
|
||||||
|
vars: map[string]string{"v-1": "bar"},
|
||||||
|
host: "",
|
||||||
|
path: "",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Queries route with multiple hyphenated names, match",
|
||||||
|
route: new(Route).Queries("foo", "{v-1}", "baz", "{v-2}"),
|
||||||
|
request: newRequest("GET", "http://localhost?foo=bar&baz=ding"),
|
||||||
|
vars: map[string]string{"v-1": "bar", "v-2": "ding"},
|
||||||
|
host: "",
|
||||||
|
path: "",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Queries route with hyphenate name and pattern, match",
|
||||||
|
route: new(Route).Queries("foo", "{v-1:[0-9]+}"),
|
||||||
|
request: newRequest("GET", "http://localhost?foo=10"),
|
||||||
|
vars: map[string]string{"v-1": "10"},
|
||||||
|
host: "",
|
||||||
|
path: "",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Queries route with hyphenated name and pattern with quantifier, additional capturing group",
|
||||||
|
route: new(Route).Queries("foo", "{v-1:[0-9]{1}(a|b)}"),
|
||||||
|
request: newRequest("GET", "http://localhost?foo=1a"),
|
||||||
|
vars: map[string]string{"v-1": "1a"},
|
||||||
|
host: "",
|
||||||
|
path: "",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Queries route with empty value, should match",
|
title: "Queries route with empty value, should match",
|
||||||
route: new(Route).Queries("foo", ""),
|
route: new(Route).Queries("foo", ""),
|
||||||
|
|||||||
Reference in New Issue
Block a user