Skip to content

Commit

Permalink
Add support for boolean values
Browse files Browse the repository at this point in the history
Merge #5 a=@mre r=@nox
________________________________________________________________________
  • Loading branch information
aelita-mergebot committed Sep 22, 2016
2 parents c75cccb + f553c4e commit 87e0352
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ser/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl<'key, 'target, Target> Serializer
type StructState = ();
type StructVariantState = ();

fn serialize_bool(&mut self, _v: bool) -> Result<(), Error> {
Err(Error::unsupported_value())
fn serialize_bool(&mut self, v: bool) -> Result<(), Error> {
self.append_pair(if v { "true" } else { "false" })
}

fn serialize_isize(&mut self, v: isize) -> Result<(), Error> {
Expand Down
24 changes: 24 additions & 0 deletions tests/test_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,27 @@ fn serialize_option_map_string() {
serde_urlencoded::to_string(params),
Ok("first=hello&last=world".to_owned()));
}

#[test]
fn serialize_option_map_bool() {
let params = &[
("one", Some(true)),
("two", Some(false))
];

assert_eq!(
serde_urlencoded::to_string(params),
Ok("one=true&two=false".to_owned()));
}

#[test]
fn serialize_map_bool() {
let params = &[
("one", true),
("two", false)
];

assert_eq!(
serde_urlencoded::to_string(params),
Ok("one=true&two=false".to_owned()));
}

0 comments on commit 87e0352

Please sign in to comment.