1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

add '{date}' dynamic path parameter type

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-04-21 02:17:09 +03:00
parent 94447a2435
commit 90750d089d
7 changed files with 232 additions and 63 deletions

View File

@@ -4,6 +4,7 @@ import (
"reflect"
"strconv"
"testing"
"time"
)
// Most important tests to look:
@@ -484,6 +485,35 @@ func TestEmailEvaluatorRaw(t *testing.T) {
}
}
func TestDateEvaluatorRaw(t *testing.T) {
tests := []struct {
pass bool
input string
timeStringValue string
}{
{true, "2022/04/21", "2022-04-21 00:00:00 +0000 UTC"}, // 0
{true, "2022/12/05", "2022-12-05 00:00:00 +0000 UTC"}, // 1
{false, "2022/4", ""}, // 2
{false, "1/4/1", ""}, // 3
{false, "2022/4/", ""}, // 4
{false, "2022/4/21/0", ""}, // 5
{false, "1993", ""}, // 6
}
for i, tt := range tests {
testEvaluatorRaw(t, Date, tt.input, reflect.TypeOf(time.Time{}).Kind(), tt.pass, i)
if v, ok := Date.Evaluator(tt.input); ok {
if value, ok := v.(time.Time); ok {
if expected, got := tt.timeStringValue, value.String(); expected != got {
t.Fatalf("[%d] expected: %s but got: %s", i, expected, got)
}
} else {
t.Fatalf("[%d] expected to be able to cast as time.Time directly", i)
}
}
}
}
func TestConvertBuilderFunc(t *testing.T) {
fn := func(min uint64, slice []string) func(string) bool {
return func(paramValue string) bool {