| 256 | } |
| 257 | |
| 258 | String fuzzString(UInt64 min_length, UInt64 max_length, pcg64 & rnd, const String & source, std::function<char(pcg64 &)> charGen) |
| 259 | { |
| 260 | String result; |
| 261 | result.reserve(max_length); |
| 262 | |
| 263 | using FA = FuzzAction; |
| 264 | auto get_action = [&]() -> FuzzAction |
| 265 | { |
| 266 | static constexpr std::array<FuzzAction, 4> actions{FA::Skip, FA::Edit, FA::Add, FA::Delete}; |
| 267 | return actions[uniform(0, 3)(rnd)]; |
| 268 | }; |
| 269 | |
| 270 | size_t i = 0; |
| 271 | while (i < source.size() && result.size() < max_length) |
| 272 | { |
| 273 | auto action = get_action(); |
| 274 | switch (action) |
| 275 | { |
| 276 | case FA::Skip: { |
| 277 | result.push_back(source[i++]); |
| 278 | } |
| 279 | break; |
| 280 | case FA::Edit: { |
| 281 | result.push_back(charGen(rnd)); |
| 282 | ++i; |
| 283 | } |
| 284 | break; |
| 285 | case FA::Add: { |
| 286 | result.push_back(charGen(rnd)); |
| 287 | } |
| 288 | break; |
| 289 | default: |
| 290 | ++i; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | while (result.size() < min_length) |
| 295 | result.push_back(charGen(rnd)); |
| 296 | |
| 297 | return result; |
| 298 | } |
| 299 | |
| 300 | String fuzzJSONKey(const StorageFuzzJSON::Configuration & config, pcg64 & rnd, const String & key) |
| 301 | { |
no test coverage detected