--------------------------------------------------------------------------- Property: typed accessors agree with encoding/json on typed leaves --------------------------------------------------------------------------- reqproof:proptest GetString, GetInt, GetFloat, GetBoolean, GetUnsafeString Verif
(t *testing.T)
| 194 | // reqproof:proptest GetString, GetInt, GetFloat, GetBoolean, GetUnsafeString |
| 195 | // Verifies: SYS-REQ-002 [property] |
| 196 | func TestPropertyTypedAccessorsRoundTrip(t *testing.T) { |
| 197 | r := newRNG(jsonSeed + 1) |
| 198 | const iterations = 2000 |
| 199 | for i := 0; i < iterations; i++ { |
| 200 | raw, obj := randomObjectJSONBytes(r, 2) |
| 201 | for k, v := range obj { |
| 202 | switch val := v.(type) { |
| 203 | case string: |
| 204 | got, err := GetString(raw, k) |
| 205 | if err == nil && got != val { |
| 206 | t.Fatalf("GetString mismatch on key=%q input=%q: got=%q want=%q", k, raw, got, val) |
| 207 | } |
| 208 | // GetUnsafeString does NOT process escapes; only compare on the |
| 209 | // no-escape case where unsafe and safe paths must agree. |
| 210 | if !strings.ContainsAny(val, "\\\"\n\t\r") { |
| 211 | if u, err := GetUnsafeString(raw, k); err == nil { |
| 212 | if u != val { |
| 213 | t.Fatalf("GetUnsafeString mismatch on key=%q input=%q: got=%q want=%q", k, raw, u, val) |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | case float64: |
| 218 | // encoding/json marshals all numbers as float64. Try int first |
| 219 | // when the value is integral, then float. |
| 220 | if val == float64(int64(val)) { |
| 221 | if got, err := GetInt(raw, k); err == nil && got != int64(val) { |
| 222 | t.Fatalf("GetInt mismatch on key=%q input=%q: got=%d want=%d", k, raw, got, int64(val)) |
| 223 | } |
| 224 | } |
| 225 | if got, err := GetFloat(raw, k); err == nil { |
| 226 | if got != val { |
| 227 | t.Fatalf("GetFloat mismatch on key=%q input=%q: got=%g want=%g", k, raw, got, val) |
| 228 | } |
| 229 | } |
| 230 | case bool: |
| 231 | got, err := GetBoolean(raw, k) |
| 232 | if err == nil && got != val { |
| 233 | t.Fatalf("GetBoolean mismatch on key=%q input=%q: got=%v want=%v", k, raw, got, val) |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // --------------------------------------------------------------------------- |
| 241 | // Property: ParseInt/ParseFloat/ParseBoolean agree with strconv reference |
nothing calls this directly
no test coverage detected