Skip to content

Commit f493d7d

Browse files
committed
Add test for handling missing property
Fixes #854
1 parent 775fc3a commit f493d7d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/issues/854/issue_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/expr-lang/expr"
7+
"github.com/expr-lang/expr/internal/testify/require"
8+
"github.com/expr-lang/expr/types"
9+
)
10+
11+
func TestIssue854(t *testing.T) {
12+
envType := types.Map{
13+
"user": types.Map{
14+
// If we do not specify `Profile` here,
15+
// this is a correct behavior to throw
16+
// on a missing property.
17+
},
18+
}
19+
20+
code := `user.Profile?.Address ?? "Unknown address"`
21+
22+
_, err := expr.Compile(code, expr.Env(envType))
23+
require.Error(t, err)
24+
}

0 commit comments

Comments
 (0)