From 778d3311fd785aeeaa120577acb8dc266afcef0d Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Wed, 30 Jul 2014 21:10:26 +0300 Subject: [PATCH] strucuture: rename IsValid to IsZero --- README.md | 2 +- structure.go | 6 +++--- structure_example_test.go | 6 +++--- structure_test.go | 22 +++++++++++----------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a4fb33e..bc2d06e 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ f := structure.Fields(s) n := structure.Name(s) // Check if the fields of a struct is initialized or not. -if structure.IsValid(s) { +if structure.IsZero(s) { fmt.Println("s is initialized") } diff --git a/structure.go b/structure.go index b1eaa6a..c4fbd3e 100644 --- a/structure.go +++ b/structure.go @@ -79,7 +79,7 @@ func Values(s interface{}) []interface{} { } -// IsValid returns true if all fields in a struct are initialized (non zero +// IsZero returns true if all fields in a struct are initialized (non zero // value). A struct tag with the content of "-" ignores the checking of that // particular field. Example: // @@ -88,13 +88,13 @@ func Values(s interface{}) []interface{} { // // Note that only exported fields of a struct can be accessed, non exported // fields will be neglected. It panics if s's kind is not struct. -func IsValid(s interface{}) bool { +func IsZero(s interface{}) bool { v, fields := strctInfo(s) for i := range fields { val := v.Field(i) if val.Kind() == reflect.Struct { - ok := IsValid(val.Interface()) + ok := IsZero(val.Interface()) if !ok { return false } diff --git a/structure_example_test.go b/structure_example_test.go index f9089ca..def690d 100644 --- a/structure_example_test.go +++ b/structure_example_test.go @@ -96,7 +96,7 @@ func ExampleFields() { // Fields: [Name LastAccessed Number] } -func ExampleIsValid() { +func ExampleIsZero() { // Let's define an Access struct. Note that the "Enabled" field is not // going to be checked because we added the "structure" tag to the field. type Access struct { @@ -110,7 +110,7 @@ func ExampleIsValid() { a := &Access{ LastAccessed: time.Now(), } - validA := IsValid(a) + validA := IsZero(a) // Name and Number is initialized. b := &Access{ @@ -118,7 +118,7 @@ func ExampleIsValid() { LastAccessed: time.Now(), Number: 12345, } - validB := IsValid(b) + validB := IsZero(b) fmt.Printf("%#v\n", validA) fmt.Printf("%#v\n", validB) diff --git a/structure_test.go b/structure_test.go index 6e69df9..5535613 100644 --- a/structure_test.go +++ b/structure_test.go @@ -345,7 +345,7 @@ func TestFields_Anonymous(t *testing.T) { } } -func TestIsValid(t *testing.T) { +func TestIsZero(t *testing.T) { var T = struct { A string B int @@ -356,9 +356,9 @@ func TestIsValid(t *testing.T) { B: 2, } - ok := IsValid(T) + ok := IsZero(T) if ok { - t.Error("IsValid should return false because D is not initialized") + t.Error("IsZero should return false because D is not initialized") } var X = struct { @@ -368,13 +368,13 @@ func TestIsValid(t *testing.T) { A: "a-value", } - ok = IsValid(X) + ok = IsZero(X) if ok { - t.Error("IsValid should return false because F is not initialized") + t.Error("IsZero should return false because F is not initialized") } } -func TestIsValid_Nested(t *testing.T) { +func TestIsZero_Nested(t *testing.T) { type A struct { Name string D string @@ -387,13 +387,13 @@ func TestIsValid_Nested(t *testing.T) { } b := &B{A: a, C: 123} - ok := IsValid(b) + ok := IsZero(b) if ok { - t.Error("IsValid should return false because D is not initialized") + t.Error("IsZero should return false because D is not initialized") } } -func TestIsValid_Anonymous(t *testing.T) { +func TestIsZero_Anonymous(t *testing.T) { type A struct { Name string D string @@ -407,9 +407,9 @@ func TestIsValid_Anonymous(t *testing.T) { b := &B{C: 123} b.A = a - ok := IsValid(b) + ok := IsZero(b) if ok { - t.Error("IsValid should return false because D is not initialized") + t.Error("IsZero should return false because D is not initialized") } }