injectUnbalancedOpen inserts unmatched '{' or '[' opens at a random position. This produces structures the grammar generator CANNOT emit: every generator-produced container is balanced by construction. The parser's blockEnd / depth-tracking code must detect the missing closer and return a clean erro
(r *rand.Rand, data []byte)
| 884 | // Targets the deep-recursion / malformed-structure detection path that |
| 885 | // balanced-only generation leaves uncovered. |
| 886 | func injectUnbalancedOpen(r *rand.Rand, data []byte) []byte { |
| 887 | const maxInserts = 8 |
| 888 | n := 1 + r.Intn(maxInserts) |
| 889 | open := byte('{') |
| 890 | if r.Intn(2) == 0 { |
| 891 | open = '[' |
| 892 | } |
| 893 | // Bias insertion point: 50% at start (forces full descent), 50% random. |
| 894 | pos := 0 |
| 895 | if r.Intn(2) == 0 { |
| 896 | pos = r.Intn(len(data) + 1) |
| 897 | } |
| 898 | out := make([]byte, 0, len(data)+n) |
| 899 | out = append(out, data[:pos]...) |
| 900 | for i := 0; i < n; i++ { |
| 901 | out = append(out, open) |
| 902 | } |
| 903 | out = append(out, data[pos:]...) |
| 904 | return out |
| 905 | } |
| 906 | |
| 907 | // injectMismatchedCloser swaps a closing '}' for ']' (or vice versa). |
| 908 | // The grammar generator always pairs '{' with '}' and '[' with ']'; this |
nothing calls this directly
no outgoing calls
no test coverage detected