Skip to content

Commit

Permalink
Auto merge of servo#306 - brson:encodeset, r=SimonSapin
Browse files Browse the repository at this point in the history
Add a test that define_encode_set works inside both modules and funct…

[Guidelines](https://github.com/brson/rust-api-guidelines#macros) say to ensure item macros work in both positions, and I couldn't tell, so I added a test.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/306)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored May 9, 2017
2 parents a46c4e9 + dd5d84a commit 356de6c
Showing 1 changed file with 30 additions and 0 deletions.
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();
}

0 comments on commit 356de6c

Please sign in to comment.