(t *testing.T)
| 33 | ) |
| 34 | |
| 35 | func TestConfig(t *testing.T) { |
| 36 | tests := []struct { |
| 37 | name string |
| 38 | want *Config |
| 39 | }{ |
| 40 | { |
| 41 | name: "context_env.yaml", |
| 42 | want: NewConfig("context-env"). |
| 43 | SetContainer("google.expr"). |
| 44 | AddImports(NewImport("google.expr.proto3.test.TestAllTypes")). |
| 45 | SetStdLib(NewLibrarySubset(). |
| 46 | AddIncludedMacros("has"). |
| 47 | AddIncludedFunctions([]*Function{ |
| 48 | {Name: operators.Equals}, |
| 49 | {Name: operators.NotEquals}, |
| 50 | {Name: operators.LogicalNot}, |
| 51 | {Name: operators.Less}, |
| 52 | {Name: operators.LessEquals}, |
| 53 | {Name: operators.Greater}, |
| 54 | {Name: operators.GreaterEquals}, |
| 55 | }...)). |
| 56 | AddExtensions(NewExtension("optional", math.MaxUint32), NewExtension("strings", 1)). |
| 57 | SetContextVariable(NewContextVariable("google.expr.proto3.test.TestAllTypes")). |
| 58 | AddFunctions( |
| 59 | NewFunctionWithDoc("coalesce", |
| 60 | "Converts a potentially null wrapper-type to a default value.", |
| 61 | NewOverload("coalesce_wrapped_int", |
| 62 | []*TypeDesc{NewTypeDesc("google.protobuf.Int64Value"), NewTypeDesc("int")}, |
| 63 | NewTypeDesc("int"), |
| 64 | `coalesce(null, 1) // 1`, |
| 65 | `coalesce(2, 1) // 2`), |
| 66 | NewOverload("coalesce_wrapped_double", |
| 67 | []*TypeDesc{NewTypeDesc("google.protobuf.DoubleValue"), NewTypeDesc("double")}, |
| 68 | NewTypeDesc("double"), |
| 69 | `coalesce(null, 1.3) // 1.3`), |
| 70 | NewOverload("coalesce_wrapped_uint", |
| 71 | []*TypeDesc{NewTypeDesc("google.protobuf.UInt64Value"), NewTypeDesc("uint")}, |
| 72 | NewTypeDesc("uint"), |
| 73 | `coalesce(null, 14u) // 14u`), |
| 74 | ), |
| 75 | ), |
| 76 | }, |
| 77 | { |
| 78 | name: "extended_env.yaml", |
| 79 | want: NewConfig("extended-env"). |
| 80 | SetContainer("google.expr"). |
| 81 | AddExtensions( |
| 82 | NewExtension("optional", 2), |
| 83 | NewExtension("math", math.MaxUint32), |
| 84 | ).AddVariables( |
| 85 | NewVariableWithDoc("msg", |
| 86 | NewTypeDesc("google.expr.proto3.test.TestAllTypes"), |
| 87 | `msg represents all possible type permutation which CEL understands from a proto perspective`), |
| 88 | NewVariableWithDoc("opt_msg", |
| 89 | NewTypeDesc("optional_type", NewTypeDesc("google.expr.proto3.test.TestAllTypes")), |
| 90 | `opt_msg represents all possible type permutation which CEL understands from a proto perspective`), |
| 91 | ).AddFunctions( |
| 92 | NewFunctionWithDoc("isEmpty", |
nothing calls this directly
no test coverage detected