Skip to content

Instantly share code, notes, and snippets.

@kuy
Created January 12, 2020 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuy/bb8b528dca478cf7ae301ba4012aeb6c to your computer and use it in GitHub Desktop.
Save kuy/bb8b528dca478cf7ae301ba4012aeb6c to your computer and use it in GitHub Desktop.
actix-web + serde_urlencoded
---- deserialize_option stdout ----
thread 'deserialize_option' panicked at 'assertion failed: `(left == right)`
left: `Ok([("last", Some(42))])`,
right: `Ok([("first", None), ("last", Some(42))])`', tests/test_deserialize.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'deserialize_option' panicked at 'assertion failed: `(left == right)`
left: `Err(Error { err: "cannot parse integer from empty string" })`,
right: `Ok([("first", None), ("last", Some(42))])`', tests/test_deserialize.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
#[test]
fn deserialize_option() {
// Original
let result = vec![
("first".to_owned(), Some(23)),
("last".to_owned(), Some(42)),
];
assert_eq!(serde_urlencoded::from_str("first=23&last=42"), Ok(result));
// Added by me
let result =
vec![("first".to_owned(), None), ("last".to_owned(), Some(42))];
assert_eq!(serde_urlencoded::from_str("last=42"), Ok(result));
}
#[test]
fn deserialize_option() {
// Original
let result = vec![
("first".to_owned(), Some(23)),
("last".to_owned(), Some(42)),
];
assert_eq!(serde_urlencoded::from_str("first=23&last=42"), Ok(result));
// Added by me
let result =
vec![("first".to_owned(), None), ("last".to_owned(), Some(42))];
assert_eq!(serde_urlencoded::from_str("first=&last=42"), Ok(result));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment