(t *testing.T)
| 1142 | } |
| 1143 | |
| 1144 | func TestInternalEdgeCases(t *testing.T) { |
| 1145 | t.Parallel() |
| 1146 | |
| 1147 | t.Run("setSingleImpl should error on any node not a struct, map or slice", func(t *testing.T) { |
| 1148 | var node int |
| 1149 | |
| 1150 | _, err := setSingleImpl(&node, 3, "a", jsonname.DefaultJSONNameProvider) |
| 1151 | require.Error(t, err) |
| 1152 | require.ErrorContains(t, err, `invalid token reference "a"`) |
| 1153 | }) |
| 1154 | |
| 1155 | t.Run("with simulated unsettable", func(t *testing.T) { |
| 1156 | type unsettable struct { |
| 1157 | A string `json:"a"` |
| 1158 | } |
| 1159 | doc := unsettable{ |
| 1160 | A: "a", |
| 1161 | } |
| 1162 | |
| 1163 | t.Run("setSingleImpl should error on struct field that is not settable", func(t *testing.T) { |
| 1164 | node := doc // doesn't pass a pointer: unsettable |
| 1165 | |
| 1166 | _, err := setSingleImpl(node, "new value", "a", jsonname.DefaultJSONNameProvider) |
| 1167 | require.Error(t, err) |
| 1168 | require.ErrorContains(t, err, `can't set struct field`) |
| 1169 | }) |
| 1170 | }) |
| 1171 | |
| 1172 | t.Run("assignReflectValue is a no-op when src is an untyped nil", func(t *testing.T) { |
| 1173 | target := "unchanged" |
| 1174 | dst := reflect.ValueOf(&target).Elem() |
| 1175 | |
| 1176 | assignReflectValue(dst, nil) |
| 1177 | |
| 1178 | require.Equal(t, "unchanged", target) |
| 1179 | }) |
| 1180 | } |
| 1181 | |
| 1182 | func TestSetIntermediateErrors(t *testing.T) { |
| 1183 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…