3 Star 3 Fork 0

Gitee 极速下载 / go-restful

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/emicklei/go-restful
克隆/下载
path_expression_test.go 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
package restful
import (
"reflect"
"testing"
)
var tempregexs = []struct {
template, regex string
names []string
literalCount, varCount int
}{
{"", "^(/.*)?$", nil, 0, 0},
{"/a/{b}/c/", "^/a/([^/]+?)/c(/.*)?$", []string{"b"}, 2, 1},
{"/{a}/{b}/{c-d-e}/", "^/([^/]+?)/([^/]+?)/([^/]+?)(/.*)?$", []string{"a", "b", "c-d-e"}, 0, 3},
{"/{p}/abcde", "^/([^/]+?)/abcde(/.*)?$", []string{"p"}, 5, 1},
{"/a/{b:*}", "^/a/(.*)(/.*)?$", []string{"b"}, 1, 1},
{"/a/{b:[a-z]+}", "^/a/([a-z]+)(/.*)?$", []string{"b"}, 1, 1},
}
func TestTemplateToRegularExpression(t *testing.T) {
ok := true
for i, fixture := range tempregexs {
actual, lCount, varNames, vCount, _ := templateToRegularExpression(fixture.template)
if actual != fixture.regex {
t.Logf("regex mismatch, expected:%v , actual:%v, line:%v\n", fixture.regex, actual, i) // 11 = where the data starts
ok = false
}
if lCount != fixture.literalCount {
t.Logf("literal count mismatch, expected:%v , actual:%v, line:%v\n", fixture.literalCount, lCount, i)
ok = false
}
if vCount != fixture.varCount {
t.Logf("variable count mismatch, expected:%v , actual:%v, line:%v\n", fixture.varCount, vCount, i)
ok = false
}
if !reflect.DeepEqual(fixture.names, varNames) {
t.Logf("variable name mismatch, expected:%v , actual:%v, line:%v\n", fixture.names, varNames, i)
ok = false
}
}
if !ok {
t.Fatal("one or more expression did not match")
}
}
Go
1
https://gitee.com/mirrors/go-restful.git
git@gitee.com:mirrors/go-restful.git
mirrors
go-restful
go-restful
v3

搜索帮助