MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestQuotedFields

Function TestQuotedFields

cel/cel_test.go:2945–2990  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2943}
2944
2945func TestQuotedFields(t *testing.T) {
2946 testCases := []struct {
2947 expr string
2948 errorSubstr string
2949 out ref.Val
2950 }{
2951 {
2952 expr: "{'key-1': 64}.`key-1`",
2953 out: types.Int(64),
2954 },
2955 {
2956 expr: "{'key-1': 64}.`key-2`",
2957 errorSubstr: "no such key: key-2",
2958 },
2959 {
2960 expr: "has({'key-1': 64}.`key-1`)",
2961 out: types.True,
2962 },
2963 {
2964 expr: "has({'key-1': 64}.`key-2`)",
2965 out: types.False,
2966 },
2967 }
2968 for _, tc := range testCases {
2969 tc := tc
2970 t.Run(tc.expr, func(t *testing.T) {
2971 env := testEnv(t, ParserRecursionLimit(10),
2972 EnableIdentifierEscapeSyntax())
2973 out, err := interpret(t, env,
2974 tc.expr, map[string]any{})
2975
2976 if tc.errorSubstr != "" {
2977 if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) {
2978 t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err)
2979 }
2980 }
2981
2982 if tc.out != nil {
2983 if tc.out != out {
2984 t.Errorf("prg.Eval() wanted %v got %v", tc.out, out)
2985 }
2986 }
2987 })
2988
2989 }
2990}
2991
2992func TestDynamicDispatch(t *testing.T) {
2993 env := testEnv(t,

Callers

nothing calls this directly

Calls 7

IntTypeAlias · 0.92
ParserRecursionLimitFunction · 0.85
interpretFunction · 0.85
testEnvFunction · 0.70
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected