Skip to content

Commit

Permalink
Add test for csv_vectors example (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon01 committed Apr 7, 2024
1 parent 8a13b67 commit 1752872
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -44,3 +44,7 @@ axum = ["axum-framework", "futures"]

[package.metadata.docs.rs]
features = ["actix4", "warp"]

[[example]]
name = "csv_vectors"
test = true
13 changes: 12 additions & 1 deletion examples/csv_vectors.rs
Expand Up @@ -8,7 +8,7 @@ use serde::de::DeserializeOwned;

use std::default::Default;

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct Query {
#[serde(deserialize_with = "from_csv")]
r: Vec<u8>,
Expand All @@ -21,6 +21,17 @@ fn main() {
println!("{:?}", q);
}

#[test]
fn deserialize_sequence() {
let q = "s=12&r=1,2,3";
let q: Query = qs::from_str(q).unwrap();
let expected = Query {
r: vec![1, 2, 3],
s: 12,
};
assert_eq!(q, expected);
}

fn from_csv<'de, D, T>(deserializer: D) -> Result<Vec<T>, D::Error>
where
D: serde::Deserializer<'de>,
Expand Down

0 comments on commit 1752872

Please sign in to comment.