diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2023-12-10 14:22:48 +0100 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2023-12-10 14:22:48 +0100 |
| commit | 5315ea932697da4bf6fa814576e1823233063a95 (patch) | |
| tree | 56239489c19ee3d6ae731fe08559521f86605354 /crates/wasm-testsuite/lib.rs | |
| parent | 52bebfac2e6a2dc934273e38230d3986e68a3fe3 (diff) | |
docs: improve rustdoc
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/wasm-testsuite/lib.rs')
| -rw-r--r-- | crates/wasm-testsuite/lib.rs | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/crates/wasm-testsuite/lib.rs b/crates/wasm-testsuite/lib.rs index 102389a..5590f35 100644 --- a/crates/wasm-testsuite/lib.rs +++ b/crates/wasm-testsuite/lib.rs @@ -2,7 +2,7 @@ //! //! The testsuite is included as a git submodule and embedded into the binary. //! -//! Generated from https://github.com/WebAssembly/testsuite +//! Generated from <https://github.com/WebAssembly/testsuite> #![forbid(unsafe_code)] #![doc(test( @@ -22,18 +22,21 @@ use std::borrow::Cow; #[include = "*.wast"] struct Asset; -/// List of all proposals. -/// This list is generated from the `proposals` folder in https://github.com/WebAssembly/testsuite +/// List of all proposals. Used to filter tests. +/// +/// Includes all proposals from <https://github.com/WebAssembly/testsuite/tree/master/proposals> #[rustfmt::skip] pub const PROPOSALS: &[&str] = &["annotations", "exception-handling", "memory64", "function-references", "multi-memory", "relaxed-simd", "tail-call", "threads", "extended-const", "gc"]; /// Get all test file names and their contents. -/// -/// Proposals can be filtered by passing a list of proposal names. -/// Valid proposal names are listed in [`PROPOSALS`]. -/// Returns an iterator over tuples of the form `(test_name, test_data)`. -/// test_name is the name of the test file and the proposal name (if any), e.g. `annotations/br.wast`. -pub fn get_tests(include_proposals: &[String]) -> impl Iterator<Item = (String, Cow<'static, [u8]>)> { +pub fn get_tests_wast(include_proposals: &[String]) -> impl Iterator<Item = (String, Cow<'static, [u8]>)> { + get_tests(&include_proposals) + .filter_map(|name| Some((name.clone(), get_test_wast(&name)?))) + .map(|(name, data)| (name, Cow::Owned(data.to_vec()))) +} + +/// Get all test file names. +pub fn get_tests(include_proposals: &[String]) -> impl Iterator<Item = String> { let include_proposals = include_proposals.to_vec(); Asset::iter().filter_map(move |x| { @@ -45,27 +48,19 @@ pub fn get_tests(include_proposals: &[String]) -> impl Iterator<Item = (String, if proposal.map_or(false, |p| include_proposals.contains(&p.to_string())) { let full_path = format!("{}/{}", proposal.unwrap_or_default(), test_name); - let data = Asset::get(&x).unwrap().data; - Some((full_path, data)) + Some(full_path) } else { None } } - Some(test_name) => { - let data = Asset::get(&x).unwrap().data; - Some((test_name.to_owned(), data)) - } + Some(test_name) => Some(test_name.to_owned()), None => None, } }) } /// Get the WAST file as a byte slice. -/// -/// # Examples -/// proposals: {proposal}/{test_name}.wast -/// tests: {test_name}.wast -pub fn get_wast(name: &str) -> Option<Cow<'_, [u8]>> { +pub fn get_test_wast(name: &str) -> Option<Cow<'static, [u8]>> { if !name.ends_with(".wast") { panic!("Expected .wast file. Got: {}", name); } @@ -94,19 +89,7 @@ mod tests { let proposal = proposal.split('/').nth(1).unwrap(); unique_proposals.insert(proposal.to_owned()); - // assert!(PROPOSALS.contains(&proposal)); + assert!(PROPOSALS.contains(&proposal)); } - println!("{:?}", unique_proposals); - } - - #[test] - fn test_get_tests() { - let tests = get_tests(&["annotations".to_owned()]); - let tests: Vec<_> = tests.collect(); - println!("{:?}", tests.iter().map(|(name, _)| name).collect::<Vec<_>>()); - - // for (name, data) in tests { - // println!("{}: {}", name, data.len()); - // } } } |
