Skip to content

Commit

Permalink
Move TestSortValues to common_test.go.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davecgh committed Nov 15, 2013
1 parent de6d1a2 commit fab1d2b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
37 changes: 37 additions & 0 deletions spew/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
27 changes: 0 additions & 27 deletions spew/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down

0 comments on commit fab1d2b

Please sign in to comment.