diff options
| author | Dave Collins <[email protected]> | 2013-11-14 21:44:13 -0600 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2013-11-14 21:44:13 -0600 |
| commit | fab1d2b55fe8dca5eb8ef326de8284cbdd5ac259 (patch) | |
| tree | e60235d41eae58f96eb594b5654dd4e2725cd3db | |
| parent | de6d1a24a06fb32fa945085463fcc922dfadf152 (diff) | |
Move TestSortValues to common_test.go.
This commit moves the TestSortValues function from dump_test.go to
common_test.go to mirror the new implementation location. It also
slightly formats the tests to be consistent with the rest of the package.
| -rw-r--r-- | spew/common_test.go | 37 | ||||
| -rw-r--r-- | spew/dump_test.go | 27 |
2 files changed, 37 insertions, 27 deletions
diff --git a/spew/common_test.go b/spew/common_test.go index 0743ff5..f3404e7 100644 --- a/spew/common_test.go +++ b/spew/common_test.go @@ -109,3 +109,40 @@ func testFailed(result string, wants []string) bool { } return true } + +// TestSortValues ensures the sort functionality for relect.Value based sorting +// works as intended. +func TestSortValues(t *testing.T) { + v := reflect.ValueOf + + a := v("a") + b := v("b") + c := v("c") + tests := []struct { + input []reflect.Value + expected []reflect.Value + }{ + { + []reflect.Value{v(2), v(1), v(3)}, + []reflect.Value{v(1), v(2), v(3)}, + }, + { + []reflect.Value{v(2.), v(1.), v(3.)}, + []reflect.Value{v(1.), v(2.), v(3.)}, + }, + { + []reflect.Value{v(false), v(true), v(false)}, + []reflect.Value{v(false), v(false), v(true)}, + }, + { + []reflect.Value{b, a, c}, + []reflect.Value{a, b, c}, + }, + } + for _, test := range tests { + spew.SortValues(test.input) + if !reflect.DeepEqual(test.input, test.expected) { + t.Errorf("Sort mismatch:\n %v != %v", test.input, test.expected) + } + } +} diff --git a/spew/dump_test.go b/spew/dump_test.go index 354c71c..4942fc9 100644 --- a/spew/dump_test.go +++ b/spew/dump_test.go @@ -898,33 +898,6 @@ func TestDump(t *testing.T) { } } -func TestSortValues(t *testing.T) { - v := reflect.ValueOf - - a := v("a") - b := v("b") - c := v("c") - tests := []struct { - input []reflect.Value - expected []reflect.Value - }{ - {[]reflect.Value{v(2), v(1), v(3)}, - []reflect.Value{v(1), v(2), v(3)}}, - {[]reflect.Value{v(2.), v(1.), v(3.)}, - []reflect.Value{v(1.), v(2.), v(3.)}}, - {[]reflect.Value{v(false), v(true), v(false)}, - []reflect.Value{v(false), v(false), v(true)}}, - {[]reflect.Value{b, a, c}, - []reflect.Value{a, b, c}}, - } - for _, test := range tests { - spew.SortValues(test.input) - if !reflect.DeepEqual(test.input, test.expected) { - t.Errorf("Sort mismatch:\n %v != %v", test.input, test.expected) - } - } -} - func TestDumpSortedKeys(t *testing.T) { cfg := spew.ConfigState{SortKeys: true} s := cfg.Sdump(map[int]string{1: "1", 3: "3", 2: "2"}) |
