(t *testing.T)
| 31 | ) |
| 32 | |
| 33 | func TestProtos(t *testing.T) { |
| 34 | var protosTests = []struct { |
| 35 | expr string |
| 36 | }{ |
| 37 | // Positive test cases. |
| 38 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.int32_ext) == 0`}, |
| 39 | {expr: `!proto.hasExt(ExampleType{}, google.expr.proto2.test.int32_wrapper_ext)`}, |
| 40 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.int32_wrapper_ext) == null`}, |
| 41 | {expr: `!proto.hasExt(ExampleType{}, google.expr.proto2.test.nested_example)`}, |
| 42 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.nested_example) == ExampleType{}`}, |
| 43 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.ExtendedExampleType.extended_examples) == []`}, |
| 44 | {expr: `proto.getExt(ExampleType{}, google.expr.proto2.test.ExtendedExampleType.enum_ext) == GlobalEnum.GOO`}, |
| 45 | {expr: "ExampleType{`in`: 64}.`in` == 64"}, |
| 46 | // TODO(issue/1095): legal parse, but can't assign extension fields without updates to type checker and runtime |
| 47 | // ExampleType{`google.expr.proto2.test.int32_ext`: 42}.`google.expr.proto2.test.int32_ext` == 42 |
| 48 | {expr: `proto.getExt(msg, google.expr.proto2.test.int32_ext) == 42`}, |
| 49 | {expr: "msg.`google.expr.proto2.test.int32_ext` == 42"}, |
| 50 | {expr: `proto.getExt(msg, google.expr.proto2.test.int32_wrapper_ext) == 21`}, |
| 51 | {expr: "msg.`google.expr.proto2.test.int32_wrapper_ext` == 21"}, |
| 52 | {expr: `proto.hasExt(msg, google.expr.proto2.test.nested_example)`}, |
| 53 | {expr: "has(msg.`google.expr.proto2.test.nested_example`)"}, |
| 54 | {expr: `proto.getExt(msg, google.expr.proto2.test.nested_example) == ExampleType{name: 'nested'}`}, |
| 55 | {expr: "msg.`google.expr.proto2.test.nested_example` == ExampleType{name: 'nested'}"}, |
| 56 | {expr: `proto.getExt(msg, google.expr.proto2.test.ExtendedExampleType.extended_examples) == ['example1', 'example2']`}, |
| 57 | {expr: "msg.`google.expr.proto2.test.ExtendedExampleType.extended_examples` == ['example1', 'example2']"}, |
| 58 | {expr: `proto.getExt(msg, google.expr.proto2.test.ExtendedExampleType.enum_ext) == GlobalEnum.GAZ`}, |
| 59 | {expr: "msg.`google.expr.proto2.test.ExtendedExampleType.enum_ext` == GlobalEnum.GAZ"}, |
| 60 | } |
| 61 | |
| 62 | env := testProtosEnv(t) |
| 63 | for i, tst := range protosTests { |
| 64 | tc := tst |
| 65 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 66 | var asts []*cel.Ast |
| 67 | pAst, iss := env.Parse(tc.expr) |
| 68 | if iss.Err() != nil { |
| 69 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 70 | } |
| 71 | asts = append(asts, pAst) |
| 72 | cAst, iss := env.Check(pAst) |
| 73 | if iss.Err() != nil { |
| 74 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 75 | } |
| 76 | asts = append(asts, cAst) |
| 77 | |
| 78 | for _, ast := range asts { |
| 79 | prg, err := env.Program(ast) |
| 80 | if err != nil { |
| 81 | t.Fatal(err) |
| 82 | } |
| 83 | out, _, err := prg.Eval(map[string]any{"msg": msgWithExtensions()}) |
| 84 | if err != nil { |
| 85 | t.Fatal(err) |
| 86 | } |
| 87 | if out.Value() != true { |
| 88 | t.Errorf("got %v, wanted true for expr: %s", out.Value(), tc.expr) |
| 89 | } |
| 90 | } |
nothing calls this directly
no test coverage detected