Skip to content

Commit 7fd7e8a

Browse files
Merge pull request #4 from andreimerlescu/hotfix/validate-all
Added NewFlesh()
2 parents 1f8fa96 + 9572fb5 commit 7fd7e8a

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.0.4
1+
v2.0.5

flesh.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
"time"
88
)
99

10+
func NewFlesh(thing interface{}) Flesh {
11+
return &figFlesh{Flesh: thing}
12+
}
13+
1014
func (flesh *figFlesh) ToString() string {
1115
f, _ := toString(flesh.Flesh)
1216
return f

flesh_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import (
77
"github.com/stretchr/testify/assert"
88
)
99

10+
func TestNewFlesh(t *testing.T) {
11+
assert.NotNil(t, NewFlesh(t.Name()))
12+
assert.Equal(t, t.Name(), NewFlesh(t.Name()).ToString())
13+
assert.Equal(t, 0, NewFlesh(t.Name()).ToInt())
14+
assert.Equal(t, map[string]string{}, NewFlesh(t.Name()).ToMap())
15+
assert.Equal(t, []string{t.Name()}, NewFlesh(t.Name()).ToList())
16+
}
17+
1018
func TestFleshInterface(t *testing.T) {
1119
t.Run("Is", func(t *testing.T) {
1220
t.Run("Map", func(t *testing.T) {

validators.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,36 @@ func (tree *figTree) validateAll() error {
6565
if fruit != nil && validator != nil {
6666
var val interface{}
6767
switch v := fruit.Flesh.Flesh.(type) {
68+
case int:
69+
val = v
6870
case *int:
6971
val = *v
72+
case int64:
73+
val = v
7074
case *int64:
7175
val = *v
76+
case float64:
77+
val = v
7278
case *float64:
7379
val = *v
80+
case string:
81+
val = v
7482
case *string:
7583
val = *v
84+
case bool:
85+
val = v
7686
case *bool:
7787
val = *v
88+
case time.Duration:
89+
val = v
7890
case *time.Duration:
7991
val = *v
92+
case ListFlag:
93+
val = v.values
8094
case *ListFlag:
8195
val = *v.values
96+
case MapFlag:
97+
val = v.values
8298
case *MapFlag:
8399
val = *v.values
84100
}

0 commit comments

Comments
 (0)