summaryrefslogtreecommitdiff
path: root/spew/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'spew/common_test.go')
-rw-r--r--spew/common_test.go37
1 files changed, 37 insertions, 0 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)
+ }
+ }
+}