From 9572fb5782d4fc53425eab33f2790ea5ba79a6fb Mon Sep 17 00:00:00 2001 From: Andrei Merlescu Date: Wed, 23 Apr 2025 12:06:00 -0400 Subject: [PATCH] Added NewFlesh() and updated validateAll to include non-pointers as initial values when using RuleNoFlags --- VERSION | 2 +- flesh.go | 4 ++++ flesh_test.go | 8 ++++++++ validators.go | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 8a5b818..c2f6de9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.4 +v2.0.5 diff --git a/flesh.go b/flesh.go index c50de02..7d35c64 100644 --- a/flesh.go +++ b/flesh.go @@ -7,6 +7,10 @@ import ( "time" ) +func NewFlesh(thing interface{}) Flesh { + return &figFlesh{Flesh: thing} +} + func (flesh *figFlesh) ToString() string { f, _ := toString(flesh.Flesh) return f diff --git a/flesh_test.go b/flesh_test.go index b39c052..9643ee5 100644 --- a/flesh_test.go +++ b/flesh_test.go @@ -7,6 +7,14 @@ import ( "github.com/stretchr/testify/assert" ) +func TestNewFlesh(t *testing.T) { + assert.NotNil(t, NewFlesh(t.Name())) + assert.Equal(t, t.Name(), NewFlesh(t.Name()).ToString()) + assert.Equal(t, 0, NewFlesh(t.Name()).ToInt()) + assert.Equal(t, map[string]string{}, NewFlesh(t.Name()).ToMap()) + assert.Equal(t, []string{t.Name()}, NewFlesh(t.Name()).ToList()) +} + func TestFleshInterface(t *testing.T) { t.Run("Is", func(t *testing.T) { t.Run("Map", func(t *testing.T) { diff --git a/validators.go b/validators.go index 42dcf49..7fcc8a8 100644 --- a/validators.go +++ b/validators.go @@ -65,20 +65,36 @@ func (tree *figTree) validateAll() error { if fruit != nil && validator != nil { var val interface{} switch v := fruit.Flesh.Flesh.(type) { + case int: + val = v case *int: val = *v + case int64: + val = v case *int64: val = *v + case float64: + val = v case *float64: val = *v + case string: + val = v case *string: val = *v + case bool: + val = v case *bool: val = *v + case time.Duration: + val = v case *time.Duration: val = *v + case ListFlag: + val = v.values case *ListFlag: val = *v.values + case MapFlag: + val = v.values case *MapFlag: val = *v.values }