Skip to content

Commit

Permalink
Add more ToString test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed May 23, 2024
1 parent 1be0ee7 commit 724280c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

use std::fmt::{Debug, Display, Formatter};

use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
use percent_encoding::{AsciiSet, CONTROLS, utf8_percent_encode};

/// https://url.spec.whatwg.org/#fragment-percent-encode-set
const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
Expand Down Expand Up @@ -255,24 +255,25 @@ mod tests {
fn test_simple() {
let qs = QueryString::new()
.with_value("q", "apple???")
.with_value("category", "fruits and vegetables");
.with_value("category", "fruits and vegetables")
.with_value("tasty", true)
.with_value("weight", 99.9);
assert_eq!(
qs.to_string(),
"?q=apple???&category=fruits%20and%20vegetables"
"?q=apple???&category=fruits%20and%20vegetables&tasty=true&weight=99.9"
);
assert_eq!(qs.len(), 2);
assert_eq!(qs.len(), 4);
assert!(!qs.is_empty());
}

#[test]
fn test_encoding() {
let qs = QueryString::new()
.with_value("q", "Grünkohl")
.with_value("category", "Gemüse")
.with_value("answer", 42);
.with_value("category", "Gemüse");
assert_eq!(
qs.to_string(),
"?q=Gr%C3%BCnkohl&category=Gem%C3%BCse&answer=42"
"?q=Gr%C3%BCnkohl&category=Gem%C3%BCse"
);
}

Expand All @@ -292,12 +293,14 @@ mod tests {
let qs = QueryString::new()
.with_value("q", "celery")
.with_opt_value("taste", None::<String>)
.with_opt_value("category", Some("fruits and vegetables"));
.with_opt_value("category", Some("fruits and vegetables"))
.with_opt_value("tasty", Some(true))
.with_opt_value("weight", Some(99.9));
assert_eq!(
qs.to_string(),
"?q=celery&category=fruits%20and%20vegetables"
"?q=celery&category=fruits%20and%20vegetables&tasty=true&weight=99.9"
);
assert_eq!(qs.len(), 2); // not three!
assert_eq!(qs.len(), 4); // not five!
}

#[test]
Expand Down

0 comments on commit 724280c

Please sign in to comment.