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

Function TestConfig

common/env/env_test.go:35–321  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33)
34
35func 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",

Callers

nothing calls this directly

Calls 15

MultilineDescriptionFunction · 0.92
NewConfigFunction · 0.85
NewLibrarySubsetFunction · 0.85
NewContextVariableFunction · 0.85
NewTypeDescFunction · 0.85
NewMemberOverloadFunction · 0.85
NewTypeParamFunction · 0.85
NewFeatureFunction · 0.85
NewLimitFunction · 0.85
NewValidatorFunction · 0.85
unmarshalYAMLFunction · 0.85
SetContextVariableMethod · 0.80

Tested by

no test coverage detected