generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add standard means to load test vector (#201)
- Loading branch information
Diane Huxley
authored
May 13, 2024
1 parent
b0791f1
commit 268cc8c
Showing
5 changed files
with
55 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "test-helpers" | ||
version = "0.1.0" | ||
edition = "2021" | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license-file.workspace = true | ||
|
||
[dependencies] | ||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
serde_with = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::{fs, path::PathBuf}; | ||
|
||
use serde::de::DeserializeOwned; | ||
|
||
#[derive(Debug, serde::Deserialize)] | ||
pub struct TestVector<I, O> { | ||
pub description: String, | ||
pub input: I, | ||
pub output: O, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize)] | ||
pub struct TestVectorFile<I, O> { | ||
pub description: String, | ||
pub vectors: Vec<TestVector<I, O>>, | ||
} | ||
|
||
impl<I, O> TestVectorFile<I, O> { | ||
pub fn load_from_path(file_path: &str) -> TestVectorFile<I, O> | ||
where | ||
I: DeserializeOwned, | ||
O: DeserializeOwned, | ||
{ | ||
let mut vector_path = PathBuf::from("../../web5-spec/test-vectors/"); | ||
vector_path.push(file_path); | ||
let data = fs::read_to_string(vector_path).unwrap(); | ||
serde_json::from_str(&data).unwrap() | ||
} | ||
} |