lighthouse/tests/ef_tests/src/test_doc_cases.rs

37 lines
795 B
Rust
Raw Normal View History

2019-05-14 01:13:28 +00:00
use super::*;
2019-05-15 01:12:49 +00:00
use crate::yaml_decode::*;
2019-05-14 05:08:42 +00:00
use yaml_rust::YamlLoader;
2019-05-14 01:13:28 +00:00
mod ssz_generic;
2019-05-14 05:08:42 +00:00
mod ssz_static;
2019-05-14 01:13:28 +00:00
pub use ssz_generic::*;
2019-05-14 05:08:42 +00:00
pub use ssz_static::*;
2019-05-14 01:13:28 +00:00
#[derive(Debug, Deserialize)]
pub struct TestDocCases<T> {
pub test_cases: Vec<T>,
}
2019-05-14 05:08:42 +00:00
2019-05-15 01:12:49 +00:00
impl<T: YamlDecode> YamlDecode for TestDocCases<T> {
2019-05-14 05:08:42 +00:00
/// Decodes a YAML list of test cases
2019-05-15 01:12:49 +00:00
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
2019-05-14 05:08:42 +00:00
let doc = &YamlLoader::load_from_str(yaml).unwrap()[0];
let mut test_cases: Vec<T> = vec![];
let mut i = 0;
loop {
if doc[i].is_badvalue() {
break;
} else {
2019-05-15 01:12:49 +00:00
test_cases.push(T::yaml_decode(&yaml_to_string(&doc[i])).unwrap())
2019-05-14 05:08:42 +00:00
}
i += 1;
}
Ok(Self { test_cases })
}
}