From d06e0a67e61a83e552496df95738707d63283ccd Mon Sep 17 00:00:00 2001 From: shockerli Date: Wed, 24 Mar 2021 17:05:16 +0800 Subject: [PATCH] remove ColumnsIntE/ColumnsInt64E/ColumnsFloat64E/ColumnsStringE --- cvte.go | 68 ----------------------- cvte_test.go | 153 --------------------------------------------------- 2 files changed, 221 deletions(-) diff --git a/cvte.go b/cvte.go index 60adfe7..2c2506c 100644 --- a/cvte.go +++ b/cvte.go @@ -555,74 +555,6 @@ func ColumnsE(val interface{}, field interface{}) (sl []interface{}, err error) return nil, fmt.Errorf("unsupported type: %s", rt.Name()) } -func ColumnsIntE(val interface{}, field interface{}) (sl []int, err error) { - list, err := ColumnsE(val, field) - if err != nil { - return - } - - for _, v := range list { - vv, err := IntE(v) - if err != nil { - return nil, err - } - sl = append(sl, vv) - } - - return -} - -func ColumnsInt64E(val interface{}, field interface{}) (sl []int64, err error) { - list, err := ColumnsE(val, field) - if err != nil { - return - } - - for _, v := range list { - vv, err := Int64E(v) - if err != nil { - return nil, err - } - sl = append(sl, vv) - } - - return -} - -func ColumnsFloat64E(val interface{}, field interface{}) (sl []float64, err error) { - list, err := ColumnsE(val, field) - if err != nil { - return - } - - for _, v := range list { - vv, err := Float64E(v) - if err != nil { - return nil, err - } - sl = append(sl, vv) - } - - return -} - -func ColumnsStringE(val interface{}, field interface{}) (sl []string, err error) { - list, err := ColumnsE(val, field) - if err != nil { - return - } - - for _, v := range list { - vv, err := StringE(v) - if err != nil { - return nil, err - } - sl = append(sl, vv) - } - - return -} - // KeysE return the keys of map, sorted by asc func KeysE(val interface{}) (sl []interface{}, err error) { if val == nil { diff --git a/cvte_test.go b/cvte_test.go index 4348896..f8c5915 100644 --- a/cvte_test.go +++ b/cvte_test.go @@ -1631,159 +1631,6 @@ func TestTimeE(t *testing.T) { } } -func TestColumnsIntE(t *testing.T) { - tests := []struct { - input interface{} - field interface{} - expect []int - isErr bool - }{ - {[]interface{}{TestStructE{D1: 1, DD: &TestStructD{D1: 2}}}, "D1", []int{1}, false}, - - {[]TestStructE{{D1: 1}, {D1: 2}}, "D1", []int{1, 2}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "321"}}, "DDD", []int{123, 321}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "321"}, {"DDD": nil}}, "DDD", []int{123, 321, 0}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 123}, 2: {"2": 222, "DDD": "321"}, 3: {"DDD": nil}}, "DDD", []int{123, 321, 0}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 123}, 2: {"2": 222, "DDD": "321"}}, "DDD", []int{123, 321}, false}, - {map[int]TestStructD{1: {11}, 2: {22}}, "D1", []int{11, 22}, false}, - - // errors - {"Name", "xxx", nil, true}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": func() {}}}, "DDD", nil, true}, - } - - for i, tt := range tests { - msg := fmt.Sprintf( - "i = %d, input[%+v], field[%+v], expect[%+v], isErr[%v]", - i, tt.input, tt.field, tt.expect, tt.isErr, - ) - - v, err := cvt.ColumnsIntE(tt.input, tt.field) - if tt.isErr { - assert.Error(t, err, msg) - continue - } - - assert.NoError(t, err, msg) - assert.Equal(t, tt.expect, v, msg) - } -} - -func TestColumnsInt64E(t *testing.T) { - tests := []struct { - input interface{} - field interface{} - expect []int64 - isErr bool - }{ - {[]interface{}{TestStructE{D1: 1, DD: &TestStructD{D1: 2}}}, "D1", []int64{1}, false}, - - {[]TestStructE{{D1: 1}, {D1: 2}}, "D1", []int64{1, 2}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "321"}}, "DDD", []int64{123, 321}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "321"}, {"DDD": nil}}, "DDD", []int64{123, 321, 0}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 123}, 2: {"2": 222, "DDD": "321"}, 3: {"DDD": nil}}, "DDD", []int64{123, 321, 0}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 123}, 2: {"2": 222, "DDD": "321"}}, "DDD", []int64{123, 321}, false}, - {map[int]TestStructD{1: {11}, 2: {22}}, "D1", []int64{11, 22}, false}, - - // errors - {"Name", "xxx", nil, true}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": func() {}}}, "DDD", nil, true}, - } - - for i, tt := range tests { - msg := fmt.Sprintf( - "i = %d, input[%+v], field[%+v], expect[%+v], isErr[%v]", - i, tt.input, tt.field, tt.expect, tt.isErr, - ) - - v, err := cvt.ColumnsInt64E(tt.input, tt.field) - if tt.isErr { - assert.Error(t, err, msg) - continue - } - - assert.NoError(t, err, msg) - assert.Equal(t, tt.expect, v, msg) - } -} - -func TestColumnsStringE(t *testing.T) { - tests := []struct { - input interface{} - field interface{} - expect []string - isErr bool - }{ - {[]interface{}{TestStructE{D1: 1, DD: &TestStructD{D1: 2}}}, "D1", []string{"1"}, false}, - - {[]TestStructE{{D1: 1}, {D1: 2}}, "D1", []string{"1", "2"}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "321"}}, "DDD", []string{"123", "321"}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "321"}, {"DDD": nil}}, "DDD", []string{"123", "321", ""}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 123}, 2: {"2": 222, "DDD": "321"}, 3: {"DDD": nil}}, "DDD", []string{"123", "321", ""}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 12.3}, 2: {"2": 222, "DDD": 32.1}}, "DDD", []string{"12.3", "32.1"}, false}, - {map[int]TestStructD{1: {11}, 2: {22}}, "D1", []string{"11", "22"}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": TestStructC{C1: "XXX"}}}, "DDD", []string{"XXX"}, false}, - - // errors - {"Name", "xxx", nil, true}, - {[]map[string]interface{}{{"2": 222, "DDD": func() {}}}, "DDD", nil, true}, - } - - for i, tt := range tests { - msg := fmt.Sprintf( - "i = %d, input[%+v], field[%+v], expect[%+v], isErr[%v]", - i, tt.input, tt.field, tt.expect, tt.isErr, - ) - - v, err := cvt.ColumnsStringE(tt.input, tt.field) - if tt.isErr { - assert.Error(t, err, msg) - continue - } - - assert.NoError(t, err, msg) - assert.Equal(t, tt.expect, v, msg) - } -} - -func TestColumnsFloat64E(t *testing.T) { - tests := []struct { - input interface{} - field interface{} - expect []float64 - isErr bool - }{ - {[]interface{}{TestStructE{D1: 1, DD: &TestStructD{D1: 2}}}, "D1", []float64{1}, false}, - {[]TestStructE{{D1: 1}, {D1: 2}}, "D1", []float64{1, 2}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "32.1"}}, "DDD", []float64{123, 32.1}, false}, - {[]map[string]interface{}{{"1": 111, "DDD": "123"}, {"2": 222, "DDD": "32.1"}, {"DDD": nil}}, "DDD", []float64{123, 32.1, 0}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 12.3}, 2: {"2": 222, "DDD": "321"}, 3: {"DDD": nil}}, "DDD", []float64{12.3, 321, 0}, false}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": 12.3}, 2: {"2": 222, "DDD": 32.1}}, "DDD", []float64{12.3, 32.1}, false}, - {map[int]TestStructD{1: {11}, 2: {22}}, "D1", []float64{11, 22}, false}, - - // errors - {"Name", "xxx", nil, true}, - {map[int]map[string]interface{}{1: {"1": 111, "DDD": TestStructC{C1: "XXX"}}}, "DDD", nil, true}, - {[]map[string]interface{}{{"2": 222, "DDD": func() {}}}, "DDD", nil, true}, - } - - for i, tt := range tests { - msg := fmt.Sprintf( - "i = %d, input[%+v], field[%+v], expect[%+v], isErr[%v]", - i, tt.input, tt.field, tt.expect, tt.isErr, - ) - - v, err := cvt.ColumnsFloat64E(tt.input, tt.field) - if tt.isErr { - assert.Error(t, err, msg) - continue - } - - assert.NoError(t, err, msg) - assert.Equal(t, tt.expect, v, msg) - } -} - func TestKeysE(t *testing.T) { tests := []struct { input interface{}