From 4f4cd5e63573da4d6edcc7d4213afaca67c19f88 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Mon, 23 Nov 2015 15:53:48 -0800 Subject: upgrading libs --- .../src/github.com/stretchr/objx/accessors_test.go | 2 +- .../github.com/stretchr/objx/conversions_test.go | 2 +- .../src/github.com/stretchr/objx/fixture_test.go | 2 +- .../src/github.com/stretchr/objx/map_test.go | 2 +- .../src/github.com/stretchr/objx/mutations_test.go | 2 +- .../src/github.com/stretchr/objx/security_test.go | 2 +- .../stretchr/objx/simple_example_test.go | 2 +- .../src/github.com/stretchr/objx/tests_test.go | 2 +- .../stretchr/objx/type_specific_codegen_test.go | 2 +- .../src/github.com/stretchr/objx/value.go | 43 ++++++++++++++ .../src/github.com/stretchr/objx/value_test.go | 65 ++++++++++++++++++++++ 11 files changed, 117 insertions(+), 9 deletions(-) (limited to 'Godeps/_workspace/src/github.com/stretchr/objx') diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/accessors_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/accessors_test.go index ce5d8e4aa..03915399b 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/accessors_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/accessors_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/conversions_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/conversions_test.go index e9ccd2987..3f68f7061 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/conversions_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/conversions_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/fixture_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/fixture_test.go index 27f7d9049..9e8b55a75 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/fixture_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/fixture_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/map_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/map_test.go index 1f8b45c61..e1430512e 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/map_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/map_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/mutations_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/mutations_test.go index e20ee23bc..fb0fccfca 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/mutations_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/mutations_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/security_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/security_test.go index 8f0898f62..a438fa65a 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/security_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/security_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/simple_example_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/simple_example_test.go index 5408c7fd3..345c7ce54 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/simple_example_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/simple_example_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/tests_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/tests_test.go index bcc1eb03d..81ad09005 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/tests_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/tests_test.go @@ -1,7 +1,7 @@ package objx import ( - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/type_specific_codegen_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/type_specific_codegen_test.go index f7a4fceea..f76783485 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/type_specific_codegen_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/type_specific_codegen_test.go @@ -2,7 +2,7 @@ package objx import ( "fmt" - "github.com/stretchr/testify/assert" + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" "testing" ) diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/value.go b/Godeps/_workspace/src/github.com/stretchr/objx/value.go index 7aaef06b1..956a2211d 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/value.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/value.go @@ -1,5 +1,10 @@ package objx +import ( + "fmt" + "strconv" +) + // Value provides methods for extracting interface{} data in various // types. type Value struct { @@ -11,3 +16,41 @@ type Value struct { func (v *Value) Data() interface{} { return v.data } + +// String returns the value always as a string +func (v *Value) String() string { + switch { + case v.IsStr(): + return v.Str() + case v.IsBool(): + return strconv.FormatBool(v.Bool()) + case v.IsFloat32(): + return strconv.FormatFloat(float64(v.Float32()), 'f', -1, 32) + case v.IsFloat64(): + return strconv.FormatFloat(v.Float64(), 'f', -1, 64) + case v.IsInt(): + return strconv.FormatInt(int64(v.Int()), 10) + case v.IsInt(): + return strconv.FormatInt(int64(v.Int()), 10) + case v.IsInt8(): + return strconv.FormatInt(int64(v.Int8()), 10) + case v.IsInt16(): + return strconv.FormatInt(int64(v.Int16()), 10) + case v.IsInt32(): + return strconv.FormatInt(int64(v.Int32()), 10) + case v.IsInt64(): + return strconv.FormatInt(v.Int64(), 10) + case v.IsUint(): + return strconv.FormatUint(uint64(v.Uint()), 10) + case v.IsUint8(): + return strconv.FormatUint(uint64(v.Uint8()), 10) + case v.IsUint16(): + return strconv.FormatUint(uint64(v.Uint16()), 10) + case v.IsUint32(): + return strconv.FormatUint(uint64(v.Uint32()), 10) + case v.IsUint64(): + return strconv.FormatUint(v.Uint64(), 10) + } + + return fmt.Sprintf("%#v", v.Data()) +} diff --git a/Godeps/_workspace/src/github.com/stretchr/objx/value_test.go b/Godeps/_workspace/src/github.com/stretchr/objx/value_test.go index 0bc65d92c..924406010 100644 --- a/Godeps/_workspace/src/github.com/stretchr/objx/value_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/objx/value_test.go @@ -1 +1,66 @@ package objx + +import ( + "github.com/mattermost/platform/Godeps/_workspace/src/github.com/stretchr/testify/assert" + "testing" +) + +func TestStringTypeString(t *testing.T) { + m := New(map[string]interface{}{"string": "foo"}) + assert.Equal(t, "foo", m.Get("string").String()) +} + +func TestStringTypeBool(t *testing.T) { + m := New(map[string]interface{}{"bool": true}) + assert.Equal(t, "true", m.Get("bool").String()) +} + +func TestStringTypeInt(t *testing.T) { + m := New(map[string]interface{}{ + "int": int(1), + "int8": int8(8), + "int16": int16(16), + "int32": int32(32), + "int64": int64(64), + }) + + assert.Equal(t, "1", m.Get("int").String()) + assert.Equal(t, "8", m.Get("int8").String()) + assert.Equal(t, "16", m.Get("int16").String()) + assert.Equal(t, "32", m.Get("int32").String()) + assert.Equal(t, "64", m.Get("int64").String()) +} + +func TestStringTypeUint(t *testing.T) { + m := New(map[string]interface{}{ + "uint": uint(1), + "uint8": uint8(8), + "uint16": uint16(16), + "uint32": uint32(32), + "uint64": uint64(64), + }) + + assert.Equal(t, "1", m.Get("uint").String()) + assert.Equal(t, "8", m.Get("uint8").String()) + assert.Equal(t, "16", m.Get("uint16").String()) + assert.Equal(t, "32", m.Get("uint32").String()) + assert.Equal(t, "64", m.Get("uint64").String()) +} + +func TestStringTypeFloat(t *testing.T) { + m := New(map[string]interface{}{ + "float32": float32(32.32), + "float64": float64(64.64), + }) + + assert.Equal(t, "32.32", m.Get("float32").String()) + assert.Equal(t, "64.64", m.Get("float64").String()) +} + +func TestStringTypeOther(t *testing.T) { + m := New(map[string]interface{}{ + "other": []string{"foo", "bar"}, + }) + + assert.Equal(t, "[]string{\"foo\", \"bar\"}", m.Get("other").String()) +} -- cgit v1.2.3-1-g7c22