|
|
@@ -8,6 +8,7 @@
|
|
|
|
|
|
//! Unit tests
|
|
|
|
|
|
+#[macro_use]
|
|
|
extern crate url;
|
|
|
|
|
|
use std::borrow::Cow;
|
|
|
@@ -342,3 +343,32 @@ fn test_set_host() {
|
|
|
url.set_host(None).unwrap();
|
|
|
assert_eq!(url.as_str(), "foobar:/hello");
|
|
|
}
|
|
|
+
|
|
|
+// This is testing that the macro produces buildable code when invoked
|
|
|
+// inside both a module and a function
|
|
|
+#[test]
|
|
|
+fn define_encode_set_scopes() {
|
|
|
+ use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
|
|
|
+
|
|
|
+ define_encode_set! {
|
|
|
+ /// This encode set is used in the URL parser for query strings.
|
|
|
+ pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
|
|
|
+ }
|
|
|
+
|
|
|
+ assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
|
|
|
+
|
|
|
+ mod m {
|
|
|
+ use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
|
|
|
+
|
|
|
+ define_encode_set! {
|
|
|
+ /// This encode set is used in the URL parser for query strings.
|
|
|
+ pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn test() {
|
|
|
+ assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ m::test();
|
|
|
+}
|