| 296 | } |
| 297 | |
| 298 | pub fn parse_mutation_string(mutation_strings: &Vec<String>) -> Vec<Mutation> { |
| 299 | let mut mutations: Vec<Mutation> = vec![]; |
| 300 | |
| 301 | for mutation_string in mutation_strings { |
| 302 | let mut mutation_split: Vec<&str> = mutation_string |
| 303 | .split(':') |
| 304 | // .into_iter() |
| 305 | .map(|x| x.trim()) |
| 306 | .collect(); |
| 307 | let mut mutation_action = mutation_split[0]; |
| 308 | let mut mutation_runtimes: usize = 1; |
| 309 | let mut mutation_options: &str = ""; |
| 310 | |
| 311 | if mutation_action.contains(' ') { |
| 312 | let mutation_action_split: Vec<&str> = mutation_action.split(' ').collect(); |
| 313 | if mutation_action_split.len() > 1 { |
| 314 | mutation_action = mutation_action_split.last().unwrap(); |
| 315 | match mutation_action_split[0].parse() { |
| 316 | Ok(f) => mutation_runtimes = f, |
| 317 | Err(_) => mutation_options = mutation_action_split[0], |
| 318 | } |
| 319 | } |
| 320 | if mutation_action_split.len() > 2 { |
| 321 | mutation_options = mutation_action_split[1]; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | mutation_split.remove(0); |
| 326 | |
| 327 | match Action::from_string(mutation_action, mutation_split, mutation_options) { |
| 328 | Ok(m) => mutations.push(Mutation { |
| 329 | action: m, |
| 330 | times: mutation_runtimes, |
| 331 | keep_original: mutation_options.contains('k'), |
| 332 | }), |
| 333 | Err(e) => { |
| 334 | crate::logging::warning(&format!( |
| 335 | "couldn't build mutation {} ({:?})", |
| 336 | mutation_action, e |
| 337 | )); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | mutations |
| 343 | } |
| 344 | |
| 345 | #[cfg(test)] |
| 346 | mod tests { |