(t *testing.T)
| 67 | } |
| 68 | |
| 69 | func TestNewDecoderCaseSensitivity(t *testing.T) { |
| 70 | type Target struct { |
| 71 | Field string `json:"field"` |
| 72 | TaggedField string `json:"custom_tag"` |
| 73 | } |
| 74 | |
| 75 | tests := []struct { |
| 76 | name string |
| 77 | json string |
| 78 | want Target |
| 79 | }{ |
| 80 | { |
| 81 | name: "exact match", |
| 82 | json: `{"field": "value", "custom_tag": "tagged"}`, |
| 83 | want: Target{Field: "value", TaggedField: "tagged"}, |
| 84 | }, |
| 85 | { |
| 86 | name: "case mismatch", |
| 87 | json: `{"Field": "value", "Custom_tag": "tagged"}`, |
| 88 | want: Target{}, |
| 89 | }, |
| 90 | } |
| 91 | |
| 92 | for _, tt := range tests { |
| 93 | t.Run(tt.name, func(t *testing.T) { |
| 94 | var got Target |
| 95 | dec := NewDecoder(strings.NewReader(tt.json)) |
| 96 | if err := dec.Decode(&got); err != nil { |
| 97 | t.Fatalf("Decode failed: %v", err) |
| 98 | } |
| 99 | if diff := cmp.Diff(tt.want, got); diff != "" { |
| 100 | t.Errorf("Decode mismatch (-want +got):\n%s", diff) |
| 101 | } |
| 102 | }) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | func TestUnmarshalNullCharacter(t *testing.T) { |
| 107 | type Target struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…