From dd5d84a5bea9bc867d9ed5c960486a80727ee194 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 4 May 2017 15:08:13 -0700 Subject: [PATCH] Add a test that define_encode_set works inside both modules and functions --- tests/unit.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/unit.rs b/tests/unit.rs index 6739956fe..2d13340b8 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -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::(), "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::(), "foo%20bar"); + } + } + + m::test(); +}