Skip to content

Add a test that define_encode_set works inside both modules and funct… #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

//! Unit tests

#[macro_use]
extern crate url;

use std::borrow::Cow;
Expand Down Expand Up @@ -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();
}