MCPcopy
hub / github.com/expr-lang/expr / TestVM_SortBy_NonStringOrder

Function TestVM_SortBy_NonStringOrder

vm/vm_test.go:518–534  ·  view source on GitHub ↗

TestVM_SortBy_NonStringOrder tests that sortBy with non-string order returns a proper error instead of panicking (regression test for OSS-Fuzz #477658245).

(t *testing.T)

Source from the content-addressed store, hash-verified

516// TestVM_SortBy_NonStringOrder tests that sortBy with non-string order
517// returns a proper error instead of panicking (regression test for OSS-Fuzz #477658245).
518func TestVM_SortBy_NonStringOrder(t *testing.T) {
519 env := map[string]any{}
520 fn := expr.Function("fn", func(params ...any) (any, error) {
521 return fmt.Sprintf("fn(%v)", params), nil
522 })
523
524 // This expression passes a function result as the order argument to sortBy.
525 // The function returns a string that is not "asc" or "desc", which should
526 // produce a proper error rather than a panic.
527 program, err := expr.Compile(`sortBy([1, 2, 3], #, fn($env))`, expr.Env(env), fn)
528 require.NoError(t, err)
529
530 testVM := &vm.VM{}
531 _, err = testVM.Run(program, env)
532 require.Error(t, err)
533 require.Contains(t, err.Error(), "unknown order")
534}
535
536// TestVM_ProfileOperations tests the profiling opcodes
537func TestVM_ProfileOperations(t *testing.T) {

Callers

nothing calls this directly

Calls 9

RunMethod · 0.95
FunctionFunction · 0.92
CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
ErrorFunction · 0.92
ContainsFunction · 0.92
SprintfMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…