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

Function TestJSONFieldNames

cel/cel_test.go:4240–4376  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4238}
4239
4240func TestJSONFieldNames(t *testing.T) {
4241 tests := []struct {
4242 name string
4243 expr string
4244 jsonFieldNames bool
4245 }{
4246 {
4247 name: "proto simple field",
4248 expr: `msg.single_int32 == 1`,
4249 },
4250 {
4251 name: "proto map field",
4252 expr: `msg.map_string_string['key'] == 'value'`,
4253 },
4254 {
4255 name: "json simple field",
4256 expr: `msg.singleInt32 == 1`,
4257 jsonFieldNames: true,
4258 },
4259 {
4260 name: "json repeated field",
4261 expr: `msg.mapStringString['key'] == 'value'`,
4262 jsonFieldNames: true,
4263 },
4264 {
4265 name: "message with json field",
4266 expr: `TestAllTypes{singleInt32: 1} != msg`,
4267 jsonFieldNames: true,
4268 },
4269 {
4270 name: "message with json field and proto fallback",
4271 expr: `dyn(TestAllTypes{singleInt32: 2}).single_int32 == 2`,
4272 jsonFieldNames: true,
4273 },
4274 {
4275 name: "json with proto fallback",
4276 expr: `dyn(msg).single_int32 == dyn(msg).singleInt32`,
4277 jsonFieldNames: true,
4278 },
4279 {
4280 name: "proto with extensions",
4281 expr: `google.expr.proto2.test.ExampleType{fooBar: 'value'}.fooBar == 'value'`,
4282 jsonFieldNames: true,
4283 },
4284 {
4285 name: "json opt fields",
4286 expr: "jsonOptMsg.int32_snake_case_json_name == 1 && " +
4287 "jsonOptMsg.int64CamelCaseJsonName == 2 && " +
4288 "jsonOptMsg.uint32DefaultJsonName == 3u && " +
4289 "jsonOptMsg.`uint64-custom-json-name` == 4u && " +
4290 "jsonOptMsg.single_string == 'shadows' && " +
4291 "jsonOptMsg.singleString == 'shadowed'",
4292 jsonFieldNames: true,
4293 },
4294 {
4295 name: "json opt fields fallback",
4296 expr: "dyn(jsonOptMsg).int32_snake_case_json_name == 1 && " +
4297 "dyn(jsonOptMsg).`uint64-custom-json-name` == 4u && " +

Callers

nothing calls this directly

Calls 14

ProtoReflectMethod · 0.95
ProtoReflectMethod · 0.95
CompileMethod · 0.95
ProgramMethod · 0.95
ExtendMethod · 0.95
ErrMethod · 0.80
NewEnvFunction · 0.70
JSONFieldNamesFunction · 0.70
TypesFunction · 0.70
ContainerFunction · 0.70
VariableFunction · 0.70

Tested by

no test coverage detected