From 9997dad4adaa96b3dfa5192f1f9546f6cbac6783 Mon Sep 17 00:00:00 2001 From: Daniel Fireman Date: Wed, 13 Sep 2017 18:34:04 -0300 Subject: [PATCH] Removing Headers() method from Schema. Updating example to deal with Schema fields. #16 --- examples/validate/main.go | 7 +++++-- schema/schema.go | 10 ---------- schema/schema_test.go | 14 -------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/examples/validate/main.go b/examples/validate/main.go index df4b8bc..a69b9fa 100644 --- a/examples/validate/main.go +++ b/examples/validate/main.go @@ -19,8 +19,11 @@ func main() { log.Fatal(err) } - // Printing headers. - log.Printf("Headers: %v\n", capitalSchema.Headers()) + // Printing schema fields names. + log.Println("Fields:") + for i, f := range capitalSchema.Fields { + log.Printf("%d - %s\n", i, f.Name) + } // Working with schema fields. if capitalSchema.HasField("Capital") { diff --git a/schema/schema.go b/schema/schema.go index 5d8db8b..c5be725 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -101,16 +101,6 @@ type Schema struct { MissingValues []string `json:"missingValues,omitempty"` } -// Headers returns the headers of the tabular data described -// by the schema. -func (s *Schema) Headers() []string { - var h []string - for i := range s.Fields { - h = append(h, s.Fields[i].Name) - } - return h -} - // GetField fetches the index and field referenced by the name argument. func (s *Schema) GetField(name string) (*Field, int) { for i := range s.Fields { diff --git a/schema/schema_test.go b/schema/schema_test.go index 8a23737..4255612 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -227,20 +227,6 @@ func TestRead_Error(t *testing.T) { } } -func TestHeaders(t *testing.T) { - // Empty schema, empty headers. - s := Schema{} - if len(s.Headers()) > 0 { - t.Errorf("want:0 got:%d", len(s.Headers())) - } - - s1 := Schema{Fields: []Field{{Name: "f1"}, {Name: "f2"}}} - expected := []string{"f1", "f2"} - if !reflect.DeepEqual(s1.Headers(), expected) { - t.Errorf("want:%v got:%v", expected, s1.Headers()) - } -} - func TestSchema_Decode(t *testing.T) { t.Run("NoImplicitCast", func(t *testing.T) { t1 := struct {