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

Function TestSetKindCase

common/ast/expr_test.go:27–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestSetKindCase(t *testing.T) {
28 fac := ast.NewExprFactory()
29 tests := []ast.Expr{
30 fac.NewUnspecifiedExpr(1),
31 fac.NewCall(1, "_==_", fac.NewLiteral(2, types.True), fac.NewLiteral(3, types.False)),
32 fac.NewMemberCall(1, overloads.Size, fac.NewLiteral(2, types.String("hello"))),
33 fac.NewComprehension(12,
34 fac.NewList(1, []ast.Expr{}, []int32{}),
35 "i",
36 "__result__",
37 fac.NewLiteral(5, types.False),
38 fac.NewCall(8, "@not_strictly_false", fac.NewCall(7, "!_", fac.NewAccuIdent(6))),
39 fac.NewCall(10, "_||_", fac.NewAccuIdent(9), fac.NewIdent(4, "i")),
40 fac.NewAccuIdent(11),
41 ),
42 fac.NewIdent(1, "a"),
43 fac.NewLiteral(1, types.Bytes("hello")),
44 fac.NewList(1, []ast.Expr{fac.NewIdent(2, "a"), fac.NewIdent(3, "b")}, []int32{}),
45 fac.NewMap(1, []ast.EntryExpr{
46 fac.NewMapEntry(2,
47 fac.NewLiteral(3, types.String("string")),
48 fac.NewCall(6, "_?._", fac.NewIdent(4, "a"), fac.NewLiteral(5, types.String("b"))),
49 true),
50 }),
51 fac.NewSelect(2, fac.NewIdent(1, "a"), "b"),
52 fac.NewStruct(1,
53 "custom.StructType",
54 []ast.EntryExpr{
55 fac.NewStructField(2,
56 "uint_field",
57 fac.NewLiteral(3, types.Uint(42)),
58 false),
59 }),
60 }
61 expr := nilTestExpr(t)
62 for i, tst := range tests {
63 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
64 expr.SetKindCase(tst)
65 switch expr.Kind() {
66 case ast.CallKind:
67 if !reflect.DeepEqual(expr.AsCall(), tst.AsCall()) {
68 t.Errorf("got %v, wanted %v", expr.AsCall(), tst.AsCall())
69 }
70 case ast.ComprehensionKind:
71 if !reflect.DeepEqual(expr.AsComprehension(), tst.AsComprehension()) {
72 t.Errorf("got %v, wanted %v", expr.AsComprehension(), tst.AsComprehension())
73 }
74 case ast.IdentKind:
75 if !reflect.DeepEqual(expr.AsIdent(), tst.AsIdent()) {
76 t.Errorf("got %v, wanted %v", expr.AsIdent(), tst.AsIdent())
77 }
78 case ast.LiteralKind:
79 if !reflect.DeepEqual(expr.AsLiteral(), tst.AsLiteral()) {
80 t.Errorf("got %v, wanted %v", expr.AsLiteral(), tst.AsLiteral())
81 }
82 case ast.ListKind:
83 if !reflect.DeepEqual(expr.AsList(), tst.AsList()) {
84 t.Errorf("got %v, wanted %v", expr.AsList(), tst.AsList())

Callers

nothing calls this directly

Calls 15

NewUnspecifiedExprMethod · 0.95
NewCallMethod · 0.95
NewLiteralMethod · 0.95
NewMemberCallMethod · 0.95
NewComprehensionMethod · 0.95
NewListMethod · 0.95
NewAccuIdentMethod · 0.95
NewIdentMethod · 0.95
NewMapMethod · 0.95
NewMapEntryMethod · 0.95
NewSelectMethod · 0.95
NewStructMethod · 0.95

Tested by

no test coverage detected