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

Function TestJSONFieldNames

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

Source from the content-addressed store, hash-verified

5003}
5004
5005func TestJSONFieldNames(t *testing.T) {
5006 tests := []struct {
5007 name string
5008 expr string
5009 jsonFieldNames bool
5010 }{
5011 {
5012 name: "proto simple field",
5013 expr: `msg.single_int32 == 1`,
5014 },
5015 {
5016 name: "proto map field",
5017 expr: `msg.map_string_string['key'] == 'value'`,
5018 },
5019 {
5020 name: "json simple field",
5021 expr: `msg.singleInt32 == 1`,
5022 jsonFieldNames: true,
5023 },
5024 {
5025 name: "json repeated field",
5026 expr: `msg.mapStringString['key'] == 'value'`,
5027 jsonFieldNames: true,
5028 },
5029 {
5030 name: "message with json field",
5031 expr: `TestAllTypes{singleInt32: 1} != msg`,
5032 jsonFieldNames: true,
5033 },
5034 {
5035 name: "message with json field and proto fallback",
5036 expr: `dyn(TestAllTypes{singleInt32: 2}).single_int32 == 2`,
5037 jsonFieldNames: true,
5038 },
5039 {
5040 name: "json with proto fallback",
5041 expr: `dyn(msg).single_int32 == dyn(msg).singleInt32`,
5042 jsonFieldNames: true,
5043 },
5044 {
5045 name: "proto with extensions",
5046 expr: `google.expr.proto2.test.ExampleType{fooBar: 'value'}.fooBar == 'value'`,
5047 jsonFieldNames: true,
5048 },
5049 {
5050 name: "json opt fields",
5051 expr: "jsonOptMsg.int32_snake_case_json_name == 1 && " +
5052 "jsonOptMsg.int64CamelCaseJsonName == 2 && " +
5053 "jsonOptMsg.uint32DefaultJsonName == 3u && " +
5054 "jsonOptMsg.`uint64-custom-json-name` == 4u && " +
5055 "jsonOptMsg.single_string == 'shadows' && " +
5056 "jsonOptMsg.singleString == 'shadowed'",
5057 jsonFieldNames: true,
5058 },
5059 {
5060 name: "json opt fields fallback",
5061 expr: "dyn(jsonOptMsg).int32_snake_case_json_name == 1 && " +
5062 "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