(t *testing.T)
| 3783 | } |
| 3784 | |
| 3785 | func TestJSONFieldNames(t *testing.T) { |
| 3786 | tests := []struct { |
| 3787 | name string |
| 3788 | expr string |
| 3789 | jsonFieldNames bool |
| 3790 | }{ |
| 3791 | { |
| 3792 | name: "proto simple field", |
| 3793 | expr: `msg.single_int32 == 1`, |
| 3794 | }, |
| 3795 | { |
| 3796 | name: "proto map field", |
| 3797 | expr: `msg.map_string_string['key'] == 'value'`, |
| 3798 | }, |
| 3799 | { |
| 3800 | name: "json simple field", |
| 3801 | expr: `msg.singleInt32 == 1`, |
| 3802 | jsonFieldNames: true, |
| 3803 | }, |
| 3804 | { |
| 3805 | name: "json repeated field", |
| 3806 | expr: `msg.mapStringString['key'] == 'value'`, |
| 3807 | jsonFieldNames: true, |
| 3808 | }, |
| 3809 | { |
| 3810 | name: "message with json field", |
| 3811 | expr: `TestAllTypes{singleInt32: 1} != msg`, |
| 3812 | jsonFieldNames: true, |
| 3813 | }, |
| 3814 | { |
| 3815 | name: "message with json field and proto fallback", |
| 3816 | expr: `dyn(TestAllTypes{singleInt32: 2}).single_int32 == 2`, |
| 3817 | jsonFieldNames: true, |
| 3818 | }, |
| 3819 | { |
| 3820 | name: "json with proto fallback", |
| 3821 | expr: `dyn(msg).single_int32 == dyn(msg).singleInt32`, |
| 3822 | jsonFieldNames: true, |
| 3823 | }, |
| 3824 | { |
| 3825 | name: "proto with extensions", |
| 3826 | expr: `google.expr.proto2.test.ExampleType{fooBar: 'value'}.fooBar == 'value'`, |
| 3827 | jsonFieldNames: true, |
| 3828 | }, |
| 3829 | { |
| 3830 | name: "json opt fields", |
| 3831 | expr: "jsonOptMsg.int32_snake_case_json_name == 1 && " + |
| 3832 | "jsonOptMsg.int64CamelCaseJsonName == 2 && " + |
| 3833 | "jsonOptMsg.uint32DefaultJsonName == 3u && " + |
| 3834 | "jsonOptMsg.`uint64-custom-json-name` == 4u && " + |
| 3835 | "jsonOptMsg.single_string == 'shadows' && " + |
| 3836 | "jsonOptMsg.singleString == 'shadowed'", |
| 3837 | jsonFieldNames: true, |
| 3838 | }, |
| 3839 | { |
| 3840 | name: "json opt fields fallback", |
| 3841 | expr: "dyn(jsonOptMsg).int32_snake_case_json_name == 1 && " + |
| 3842 | "dyn(jsonOptMsg).`uint64-custom-json-name` == 4u && " + |
nothing calls this directly
no test coverage detected