Skip to content

Commit dd5d84a

Browse files
committed
Add a test that define_encode_set works inside both modules and functions
1 parent 01c0932 commit dd5d84a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/unit.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
//! Unit tests
1010
11+
#[macro_use]
1112
extern crate url;
1213

1314
use std::borrow::Cow;
@@ -342,3 +343,32 @@ fn test_set_host() {
342343
url.set_host(None).unwrap();
343344
assert_eq!(url.as_str(), "foobar:/hello");
344345
}
346+
347+
// This is testing that the macro produces buildable code when invoked
348+
// inside both a module and a function
349+
#[test]
350+
fn define_encode_set_scopes() {
351+
use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
352+
353+
define_encode_set! {
354+
/// This encode set is used in the URL parser for query strings.
355+
pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
356+
}
357+
358+
assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
359+
360+
mod m {
361+
use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
362+
363+
define_encode_set! {
364+
/// This encode set is used in the URL parser for query strings.
365+
pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
366+
}
367+
368+
pub fn test() {
369+
assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
370+
}
371+
}
372+
373+
m::test();
374+
}

0 commit comments

Comments
 (0)