// This file is part of Deja-Vu. // // Deja-Vu is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Deja-Vu is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Deja-Vu. If not, see . use std::collections::HashMap; use tracing::warn; #[derive(Debug)] pub struct Groups { items: HashMap, order: Vec, } impl Groups { pub fn new() -> Self { Groups { items: HashMap::new(), order: Vec::new(), } } pub fn current_group(&self) -> String { match self.order.last() { Some(label) => label.clone(), None => String::from("No current group"), } } pub fn get(&self) -> Vec<&Line> { let mut lines = Vec::new(); self.order.iter().for_each(|key| { if let Some(line) = self.items.get(key) { lines.push(line); } }); lines } pub fn reset(&mut self) { self.items.clear(); self.order.clear(); } pub fn start(&mut self, title: String) { self.order.push(title.clone()); self.items.insert( title.clone(), Line { title, passed: true, info: Vec::new(), }, ); } pub fn update(&mut self, title: String, passed: bool, info: String) { if let Some(line) = self.items.get_mut(&title) { line.update(passed, info); } else { warn!("WARNING/DELETEME - This shouldn't happen?!"); self.start(title); } } } #[derive(Clone, Debug)] pub struct Line { pub title: String, pub passed: bool, pub info: Vec, } impl Line { pub fn update(&mut self, passed: bool, info: String) { self.passed &= passed; // We fail if any tests in this group fail self.info.push(info); } }