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

Function TestInterpreter_SetProto2PrimitiveFields

interpreter/interpreter_test.go:2208–2268  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2206}
2207
2208func TestInterpreter_SetProto2PrimitiveFields(t *testing.T) {
2209 // Test the use of proto2 primitives within object construction.
2210 src := common.NewTextSource(
2211 `input == TestAllTypes{
2212 single_int32: 1,
2213 single_int64: 2,
2214 single_uint32: 3u,
2215 single_uint64: 4u,
2216 single_float: -3.3,
2217 single_double: -2.2,
2218 single_string: "hello world",
2219 single_bool: true
2220 }`)
2221 parsed := testMustParse(t, src)
2222 cont := testContainer("google.expr.proto2.test")
2223 reg := newTestRegistry(t, types.ProtoTypeDefs(&proto2pb.TestAllTypes{}))
2224 env := newTestEnv(t, cont, reg)
2225 env.AddIdents(
2226 decls.NewVariable("input",
2227 types.NewObjectType("google.expr.proto2.test.TestAllTypes")))
2228 checked, errors := checker.Check(parsed, src, env)
2229 if len(errors.GetErrors()) != 0 {
2230 t.Error(errors.ToDisplayString())
2231 }
2232
2233 attrs := NewAttributeFactory(cont, reg, reg)
2234 i := newStandardInterpreter(t, cont, reg, reg, attrs)
2235 eval, _ := i.NewInterpretable(checked)
2236 one := int32(1)
2237 two := int64(2)
2238 three := uint32(3)
2239 four := uint64(4)
2240 five := float32(-3.3)
2241 six := float64(-2.2)
2242 str := "hello world"
2243 truth := true
2244 input := &proto2pb.TestAllTypes{
2245 SingleInt32: &one,
2246 SingleInt64: &two,
2247 SingleUint32: &three,
2248 SingleUint64: &four,
2249 SingleFloat: &five,
2250 SingleDouble: &six,
2251 SingleString: &str,
2252 SingleBool: &truth,
2253 }
2254 vars, _ := NewActivation(map[string]any{
2255 "input": reg.NativeToValue(input),
2256 })
2257 result := eval.Eval(vars)
2258 got, ok := result.Value().(bool)
2259 if !ok {
2260 t.Fatalf("Got '%v', wanted 'true'.", result)
2261 }
2262 expected := true
2263 if !reflect.DeepEqual(got, expected) {
2264 t.Errorf("Could not build object properly. Got '%v', wanted '%v'",
2265 result.Value(),

Callers

nothing calls this directly

Calls 15

EvalMethod · 0.95
NewTextSourceFunction · 0.92
ProtoTypeDefsFunction · 0.92
NewVariableFunction · 0.92
NewObjectTypeFunction · 0.92
CheckFunction · 0.92
testMustParseFunction · 0.85
testContainerFunction · 0.85
NewAttributeFactoryFunction · 0.85
newStandardInterpreterFunction · 0.85
AddIdentsMethod · 0.80
GetErrorsMethod · 0.80

Tested by

no test coverage detected