MCPcopy Create free account
hub / github.com/expr-lang/expr / TestBuiltin_reverse

Function TestBuiltin_reverse

builtin/builtin_test.go:579–609  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

577}
578
579func TestBuiltin_reverse(t *testing.T) {
580 env := map[string]any{
581 "ArrayOfString": []string{"foo", "bar", "baz"},
582 "ArrayOfInt": []int{2, 1, 3},
583 "ArrayOfFloat": []float64{3.0, 2.0, 1.0},
584 "ArrayOfFoo": []mock.Foo{{Value: "c"}, {Value: "a"}, {Value: "b"}},
585 }
586 tests := []struct {
587 input string
588 want any
589 }{
590 {`reverse([])`, []any{}},
591 {`reverse(ArrayOfInt)`, []any{3, 1, 2}},
592 {`reverse(ArrayOfFloat)`, []any{1.0, 2.0, 3.0}},
593 {`reverse(ArrayOfFoo)`, []any{mock.Foo{Value: "b"}, mock.Foo{Value: "a"}, mock.Foo{Value: "c"}}},
594 {`reverse([[1,2], [2,2]])`, []any{[]any{2, 2}, []any{1, 2}}},
595 {`reverse(reverse([[1,2], [2,2]]))`, []any{[]any{1, 2}, []any{2, 2}}},
596 {`reverse([{"test": true}, {id:4}, {name: "value"}])`, []any{map[string]any{"name": "value"}, map[string]any{"id": 4}, map[string]any{"test": true}}},
597 }
598
599 for _, test := range tests {
600 t.Run(test.input, func(t *testing.T) {
601 program, err := expr.Compile(test.input, expr.Env(env))
602 require.NoError(t, err)
603
604 out, err := expr.Run(program, env)
605 require.NoError(t, err)
606 assert.Equal(t, test.want, out)
607 })
608 }
609}
610
611func TestBuiltin_sort(t *testing.T) {
612 env := map[string]any{

Callers

nothing calls this directly

Calls 6

CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…