MCPcopy Index your code
hub / github.com/expr-lang/expr / TestSortValues

Function TestSortValues

internal/spew/common_test.go:159–229  ·  view source on GitHub ↗

TestSortValues ensures the sort functionality for reflect.Value based sorting works as intended.

(t *testing.T)

Source from the content-addressed store, hash-verified

157// TestSortValues ensures the sort functionality for reflect.Value based sorting
158// works as intended.
159func TestSortValues(t *testing.T) {
160 v := reflect.ValueOf
161
162 a := v("a")
163 b := v("b")
164 c := v("c")
165 embedA := v(embed{"a"})
166 embedB := v(embed{"b"})
167 embedC := v(embed{"c"})
168 tests := []sortTestCase{
169 // No values.
170 {
171 []reflect.Value{},
172 []reflect.Value{},
173 },
174 // Bools.
175 {
176 []reflect.Value{v(false), v(true), v(false)},
177 []reflect.Value{v(false), v(false), v(true)},
178 },
179 // Ints.
180 {
181 []reflect.Value{v(2), v(1), v(3)},
182 []reflect.Value{v(1), v(2), v(3)},
183 },
184 // Uints.
185 {
186 []reflect.Value{v(uint8(2)), v(uint8(1)), v(uint8(3))},
187 []reflect.Value{v(uint8(1)), v(uint8(2)), v(uint8(3))},
188 },
189 // Floats.
190 {
191 []reflect.Value{v(2.0), v(1.0), v(3.0)},
192 []reflect.Value{v(1.0), v(2.0), v(3.0)},
193 },
194 // Strings.
195 {
196 []reflect.Value{b, a, c},
197 []reflect.Value{a, b, c},
198 },
199 // Array
200 {
201 []reflect.Value{v([3]int{3, 2, 1}), v([3]int{1, 3, 2}), v([3]int{1, 2, 3})},
202 []reflect.Value{v([3]int{1, 2, 3}), v([3]int{1, 3, 2}), v([3]int{3, 2, 1})},
203 },
204 // Uintptrs.
205 {
206 []reflect.Value{v(uintptr(2)), v(uintptr(1)), v(uintptr(3))},
207 []reflect.Value{v(uintptr(1)), v(uintptr(2)), v(uintptr(3))},
208 },
209 // SortableStructs.
210 {
211 // Note: not sorted - DisableMethods is set.
212 []reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
213 []reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
214 },
215 // UnsortableStructs.
216 {

Callers

nothing calls this directly

Calls 1

helpTestSortValuesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…