--------------------------------------------------------------------------- Property: ParseInt/ParseFloat/ParseBoolean agree with strconv reference --------------------------------------------------------------------------- reqproof:proptest ParseInt, ParseFloat, ParseBoolean, ParseString Verifies:
(t *testing.T)
| 244 | // reqproof:proptest ParseInt, ParseFloat, ParseBoolean, ParseString |
| 245 | // Verifies: SYS-REQ-015 [property] |
| 246 | func TestPropertyParseReferenceOracle(t *testing.T) { |
| 247 | // ParseInt vs strconv.ParseInt. Property: when BOTH accept the input, |
| 248 | // the parsed values must be equal. The parser may accept a slightly |
| 249 | // different grammar (trailing data, leading '+', etc.) so we only |
| 250 | // require agreement on the common-acceptance domain. |
| 251 | ri := func(b []byte) bool { |
| 252 | s := string(b) |
| 253 | ref, refErr := strconv.ParseInt(s, 10, 64) |
| 254 | got, err := ParseInt([]byte(s)) |
| 255 | if refErr != nil { |
| 256 | return true // reference rejected — parser's grammar may be a superset |
| 257 | } |
| 258 | if err != nil { |
| 259 | return true // parser rejected a value strconv accepted; not a logic bug per se |
| 260 | } |
| 261 | return got == ref |
| 262 | } |
| 263 | if err := quick.Check(ri, &quick.Config{MaxCount: 2000}); err != nil { |
| 264 | t.Fatalf("ParseInt diverges from strconv: %v", err) |
| 265 | } |
| 266 | |
| 267 | // ParseFloat vs strconv.ParseFloat. Same one-way agreement property. |
| 268 | rf := func(b []byte) bool { |
| 269 | s := string(b) |
| 270 | ref, refErr := strconv.ParseFloat(s, 64) |
| 271 | got, err := ParseFloat([]byte(s)) |
| 272 | if refErr != nil { |
| 273 | return true |
| 274 | } |
| 275 | if err != nil { |
| 276 | return true |
| 277 | } |
| 278 | return got == ref || closeEnough(got, ref) |
| 279 | } |
| 280 | if err := quick.Check(rf, &quick.Config{MaxCount: 2000}); err != nil { |
| 281 | t.Fatalf("ParseFloat diverges from strconv: %v", err) |
| 282 | } |
| 283 | |
| 284 | // ParseBoolean vs strconv.ParseBool. Same one-way agreement property. |
| 285 | rb := func(b []byte) bool { |
| 286 | s := string(b) |
| 287 | ref, refErr := strconv.ParseBool(s) |
| 288 | got, err := ParseBoolean([]byte(s)) |
| 289 | if refErr != nil { |
| 290 | return true |
| 291 | } |
| 292 | if err != nil { |
| 293 | return true |
| 294 | } |
| 295 | return got == ref |
| 296 | } |
| 297 | if err := quick.Check(rb, &quick.Config{MaxCount: 1000}); err != nil { |
| 298 | t.Fatalf("ParseBoolean diverges from strconv: %v", err) |
| 299 | } |
| 300 | |
| 301 | // ParseString: for any JSON-quoted string, ParseString(body) must match |
| 302 | // the value encoding/json would produce. |
| 303 | rs := func(s string) bool { |
nothing calls this directly
no test coverage detected