Add support for exceptions

This commit is contained in:
Omar Abdulla
2025-07-18 21:00:44 +03:00
parent c913a8222f
commit dab8ffe520
8 changed files with 425 additions and 108 deletions
+24 -1
View File
@@ -1,6 +1,10 @@
use serde::Deserialize;
use crate::{define_wrapper_type, input::Input, mode::Mode};
use crate::{
define_wrapper_type,
input::{Expected, Input},
mode::Mode,
};
#[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)]
pub struct Case {
@@ -9,6 +13,7 @@ pub struct Case {
pub modes: Option<Vec<Mode>>,
pub inputs: Vec<Input>,
pub group: Option<String>,
pub expected: Option<Expected>,
}
define_wrapper_type!(
@@ -16,3 +21,21 @@ define_wrapper_type!(
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
CaseIdx(usize);
);
impl Case {
pub fn inputs_iterator(&self) -> impl Iterator<Item = Input> {
let inputs_len = self.inputs.len();
self.inputs
.clone()
.into_iter()
.enumerate()
.map(move |(idx, mut input)| {
if idx + 1 == inputs_len {
input.expected = self.expected.clone();
input
} else {
input
}
})
}
}