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

Function TestJSONFieldNames

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

Source from the content-addressed store, hash-verified

4180}
4181
4182func TestJSONFieldNames(t *testing.T) {
4183 tests := []struct {
4184 name string
4185 expr string
4186 jsonFieldNames bool
4187 }{
4188 {
4189 name: "proto simple field",
4190 expr: `msg.single_int32 == 1`,
4191 },
4192 {
4193 name: "proto map field",
4194 expr: `msg.map_string_string['key'] == 'value'`,
4195 },
4196 {
4197 name: "json simple field",
4198 expr: `msg.singleInt32 == 1`,
4199 jsonFieldNames: true,
4200 },
4201 {
4202 name: "json repeated field",
4203 expr: `msg.mapStringString['key'] == 'value'`,
4204 jsonFieldNames: true,
4205 },
4206 {
4207 name: "message with json field",
4208 expr: `TestAllTypes{singleInt32: 1} != msg`,
4209 jsonFieldNames: true,
4210 },
4211 {
4212 name: "message with json field and proto fallback",
4213 expr: `dyn(TestAllTypes{singleInt32: 2}).single_int32 == 2`,
4214 jsonFieldNames: true,
4215 },
4216 {
4217 name: "json with proto fallback",
4218 expr: `dyn(msg).single_int32 == dyn(msg).singleInt32`,
4219 jsonFieldNames: true,
4220 },
4221 {
4222 name: "proto with extensions",
4223 expr: `google.expr.proto2.test.ExampleType{fooBar: 'value'}.fooBar == 'value'`,
4224 jsonFieldNames: true,
4225 },
4226 {
4227 name: "json opt fields",
4228 expr: "jsonOptMsg.int32_snake_case_json_name == 1 && " +
4229 "jsonOptMsg.int64CamelCaseJsonName == 2 && " +
4230 "jsonOptMsg.uint32DefaultJsonName == 3u && " +
4231 "jsonOptMsg.`uint64-custom-json-name` == 4u && " +
4232 "jsonOptMsg.single_string == 'shadows' && " +
4233 "jsonOptMsg.singleString == 'shadowed'",
4234 jsonFieldNames: true,
4235 },
4236 {
4237 name: "json opt fields fallback",
4238 expr: "dyn(jsonOptMsg).int32_snake_case_json_name == 1 && " +
4239 "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