代码拉取完成,页面将自动刷新
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")
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。