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

Function TestExpr_nil_op_str

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

Source from the content-addressed store, hash-verified

2720}
2721
2722func TestExpr_nil_op_str(t *testing.T) {
2723 // Let's test operators, which do `.(string)` in VM, also check for nil.
2724
2725 var str *string = nil
2726 env := map[string]any{
2727 "nilString": str,
2728 }
2729
2730 tests := []struct{ code string }{
2731 {`nilString == "str"`},
2732 {`nilString contains "str"`},
2733 {`nilString matches "str"`},
2734 {`nilString startsWith "str"`},
2735 {`nilString endsWith "str"`},
2736
2737 {`"str" == nilString`},
2738 {`"str" contains nilString`},
2739 {`"str" matches nilString`},
2740 {`"str" startsWith nilString`},
2741 {`"str" endsWith nilString`},
2742 }
2743
2744 for _, tt := range tests {
2745 t.Run(tt.code, func(t *testing.T) {
2746 program, err := expr.Compile(tt.code)
2747 require.NoError(t, err)
2748
2749 output, err := expr.Run(program, env)
2750 require.NoError(t, err)
2751 require.Equal(t, false, output)
2752 })
2753 }
2754}
2755
2756func TestExpr_env_types_map(t *testing.T) {
2757 envTypes := types.Map{

Callers

nothing calls this directly

Calls 5

CompileFunction · 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…