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

Function TestEval_nil_in_maps

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

Source from the content-addressed store, hash-verified

2156}
2157
2158func TestEval_nil_in_maps(t *testing.T) {
2159 env := map[string]any{
2160 "m": map[any]any{nil: "bar"},
2161 "empty": map[any]any{},
2162 }
2163 t.Run("nil key exists", func(t *testing.T) {
2164 p, err := expr.Compile(`m[nil]`, expr.Env(env))
2165 assert.NoError(t, err)
2166
2167 out, err := expr.Run(p, env)
2168 assert.NoError(t, err)
2169 assert.Equal(t, "bar", out)
2170 })
2171 t.Run("no nil key", func(t *testing.T) {
2172 p, err := expr.Compile(`empty[nil]`, expr.Env(env))
2173 assert.NoError(t, err)
2174
2175 out, err := expr.Run(p, env)
2176 assert.NoError(t, err)
2177 assert.Equal(t, nil, out)
2178 })
2179 t.Run("nil in m", func(t *testing.T) {
2180 p, err := expr.Compile(`nil in m`, expr.Env(env))
2181 assert.NoError(t, err)
2182
2183 out, err := expr.Run(p, env)
2184 assert.NoError(t, err)
2185 assert.Equal(t, true, out)
2186 })
2187 t.Run("nil in empty", func(t *testing.T) {
2188 p, err := expr.Compile(`nil in empty`, expr.Env(env))
2189 assert.NoError(t, err)
2190
2191 out, err := expr.Run(p, env)
2192 assert.NoError(t, err)
2193 assert.Equal(t, false, out)
2194 })
2195}
2196
2197// Test the use of env keyword. Forms env[] and env[”] are valid.
2198// The enclosed identifier must be in the expression env.

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…