reqproof:proptest ParseBoolean Verifies: SYS-REQ-012 [property]
(t *testing.T)
| 875 | // reqproof:proptest ParseBoolean |
| 876 | // Verifies: SYS-REQ-012 [property] |
| 877 | func TestOracleParseBoolean(t *testing.T) { |
| 878 | // The valid JSON booleans are exactly "true" and "false" (RFC 8259). |
| 879 | // jsonparser correctly accepts only those. Assert exact value match |
| 880 | // on the strict-JSON subset (the only inputs both parsers should accept |
| 881 | // under JSON semantics — see divergence D2 in the file header). |
| 882 | for _, tc := range []struct { |
| 883 | tok string |
| 884 | val bool |
| 885 | }{ |
| 886 | {"true", true}, |
| 887 | {"false", false}, |
| 888 | } { |
| 889 | got, err := ParseBoolean([]byte(tc.tok)) |
| 890 | if err != nil { |
| 891 | t.Fatalf("ParseBoolean rejected %q: %v", tc.tok, err) |
| 892 | } |
| 893 | if got != tc.val { |
| 894 | t.Fatalf("ParseBoolean(%q) = %v, want %v", tc.tok, got, tc.val) |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | // Adversarial inputs: assert agreement on the common-acceptance domain. |
| 899 | // jsonparser follows strict JSON; strconv accepts Go-idiomatic forms |
| 900 | // (t/f/T/F/1/0/TRUE/FALSE). When both accept, values must match. |
| 901 | rb := func(b []byte) bool { |
| 902 | s := string(b) |
| 903 | _, refErr := strconv.ParseBool(s) |
| 904 | _, err := ParseBoolean([]byte(s)) |
| 905 | // If strconv rejects, jsonparser may also reject — that's fine. |
| 906 | if refErr != nil { |
| 907 | return true |
| 908 | } |
| 909 | // strconv accepted. jsonparser may reject (narrower JSON grammar) |
| 910 | // — that's a documented divergence, not a bug. But if jsonparser |
| 911 | // ALSO accepts, the value must match. |
| 912 | if err != nil { |
| 913 | return true |
| 914 | } |
| 915 | // Re-fetch both for comparison. |
| 916 | ref, _ := strconv.ParseBool(s) |
| 917 | got, _ := ParseBoolean([]byte(s)) |
| 918 | return got == ref |
| 919 | } |
| 920 | if err := quick.Check(rb, &quick.Config{MaxCount: 5000}); err != nil { |
| 921 | t.Fatalf("ParseBoolean diverges from strconv on commonly-accepted input: %v", err) |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | // closeEnoughFloat reports whether two float64 values agree to within a |
| 926 | // relative tolerance of ~4 ULP — used only for adversarial inputs where |
nothing calls this directly
no test coverage detected