Debian Codegraph @

helpers/tdutil/sort_values_test.go

raw
1 // Copyright (c) 2019-2025, Maxime Soulé
2 // All rights reserved.
3 //
4 // This source code is licensed under the BSD-style license found in the
5 // LICENSE file in the root directory of this source tree.
6
7 package tdutil_test
8
9 import (
10 "reflect"
11 "sort"
12 "testing"
13
14 "github.com/maxatome/go-testdeep/helpers/tdutil"
15 )
16
17 func TestSortableValues(t *testing.T) {
18 s := []reflect.Value{
19 reflect.ValueOf(4),
20 reflect.ValueOf(3),
21 reflect.ValueOf(1),
22 }
23 sort.Sort(tdutil.SortableValues(s))
24 if s[0].Int() != 1 || s[1].Int() != 3 || s[2].Int() != 4 {
25 t.Errorf("sort error: [ %v, %v, %v ]", s[0].Int(), s[1].Int(), s[2].Int())
26 }
27
28 s = []reflect.Value{
29 reflect.ValueOf(42),
30 }
31 sort.Sort(tdutil.SortableValues(s))
32 if s[0].Int() != 42 {
33 t.Errorf("sort error: [ %v ]", s[0].Int())
34 }
35
36 sort.Sort(tdutil.SortableValues(nil))
37 }