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

Function TestQuotedFields

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

Source from the content-addressed store, hash-verified

2728}
2729
2730func TestQuotedFields(t *testing.T) {
2731 testCases := []struct {
2732 expr string
2733 errorSubstr string
2734 out ref.Val
2735 }{
2736 {
2737 expr: "{'key-1': 64}.`key-1`",
2738 out: types.Int(64),
2739 },
2740 {
2741 expr: "{'key-1': 64}.`key-2`",
2742 errorSubstr: "no such key: key-2",
2743 },
2744 {
2745 expr: "has({'key-1': 64}.`key-1`)",
2746 out: types.True,
2747 },
2748 {
2749 expr: "has({'key-1': 64}.`key-2`)",
2750 out: types.False,
2751 },
2752 }
2753 for _, tc := range testCases {
2754 tc := tc
2755 t.Run(tc.expr, func(t *testing.T) {
2756 env := testEnv(t, ParserRecursionLimit(10),
2757 EnableIdentifierEscapeSyntax())
2758 out, err := interpret(t, env,
2759 tc.expr, map[string]any{})
2760
2761 if tc.errorSubstr != "" {
2762 if err == nil || !strings.Contains(err.Error(), tc.errorSubstr) {
2763 t.Fatalf("prg.Eval() wanted error containing '%s' got %v", tc.errorSubstr, err)
2764 }
2765 }
2766
2767 if tc.out != nil {
2768 if tc.out != out {
2769 t.Errorf("prg.Eval() wanted %v got %v", tc.out, out)
2770 }
2771 }
2772 })
2773
2774 }
2775}
2776
2777func TestDynamicDispatch(t *testing.T) {
2778 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