lighthouse/tests/ef_tests/src/cases.rs

42 lines
970 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-21 00:32:14 +00:00
mod bls_aggregate_pubkeys;
mod bls_aggregate_sigs;
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-21 00:32:14 +00:00
pub use bls_aggregate_pubkeys::*;
pub use bls_aggregate_sigs::*;
2019-05-14 01:13:28 +00:00
#[derive(Debug)]
2019-05-15 01:17:32 +00:00
pub struct Cases<T> {
2019-05-14 01:13:28 +00:00
pub test_cases: Vec<T>,
}
2019-05-14 05:08:42 +00:00
2019-05-15 01:17:32 +00:00
impl<T: YamlDecode> YamlDecode for Cases<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 {
// `is_badvalue` indicates when we have reached the end of the YAML list.
2019-05-14 05:08:42 +00:00
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 })
}
}