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

Function TestExpr_error

expr_test.go:1467–1506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1465}
1466
1467func TestExpr_error(t *testing.T) {
1468 env := mock.Env{
1469 ArrayOfAny: []any{1, "2", 3, true},
1470 }
1471
1472 tests := []struct {
1473 code string
1474 want string
1475 }{
1476 {
1477 `filter(1..9, # > 9)[0]`,
1478 `reflect: slice index out of range (1:20)
1479 | filter(1..9, # > 9)[0]
1480 | ...................^`,
1481 },
1482 {
1483 `ArrayOfAny[-7]`,
1484 `index out of range: -3 (array length is 4) (1:11)
1485 | ArrayOfAny[-7]
1486 | ..........^`,
1487 },
1488 {
1489 `reduce(10..1, # + #acc)`,
1490 `reduce of empty array with no initial value (1:1)
1491 | reduce(10..1, # + #acc)
1492 | ^`,
1493 },
1494 }
1495
1496 for _, tt := range tests {
1497 t.Run(tt.code, func(t *testing.T) {
1498 program, err := expr.Compile(tt.code, expr.Env(mock.Env{}))
1499 require.NoError(t, err)
1500
1501 _, err = expr.Run(program, env)
1502 require.Error(t, err)
1503 assert.Equal(t, tt.want, err.Error())
1504 })
1505 }
1506}
1507
1508func TestExpr_optional_chaining(t *testing.T) {
1509 env := map[string]any{}

Callers

nothing calls this directly

Calls 8

CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
ErrorFunction · 0.92
EqualFunction · 0.92
RunMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…