Ver código fonte

Add a test that define_encode_set works inside both modules and functions

Brian Anderson 9 anos atrás
pai
commit
dd5d84a5be
1 arquivos alterados com 30 adições e 0 exclusões
  1. 30 0
      tests/unit.rs

+ 30 - 0
tests/unit.rs

@@ -8,6 +8,7 @@
 
 
 //! Unit tests
 //! Unit tests
 
 
+#[macro_use]
 extern crate url;
 extern crate url;
 
 
 use std::borrow::Cow;
 use std::borrow::Cow;
@@ -342,3 +343,32 @@ fn test_set_host() {
     url.set_host(None).unwrap();
     url.set_host(None).unwrap();
     assert_eq!(url.as_str(), "foobar:/hello");
     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();
+}