Skip to content

macros: Make bindings work as expected. #127

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion procedural-masquerade/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
//! ## For users
//!
//! Users of `libfoo` don’t need to worry about any of these implementation details.
//! They can use the `foo_stringify` macro as if it were a simle `macro_rules` macro:
//! They can use the `foo_stringify` macro as if it were a simple `macro_rules` macro:
//!
//! ```rust
//! #[macro_use] extern crate libfoo;
Expand Down
14 changes: 10 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ macro_rules! match_ignore_ascii_case {
}

{
let __input = $input;

// MAX_LENGTH is generated by cssparser_internal__assert_ascii_lowercase__max_len
cssparser_internal__to_lowercase!($input, MAX_LENGTH => lowercase);
// "A" is a short string that we know is different for every string pattern,
// since we’ve verified that none of them include ASCII upper case letters.
match lowercase.unwrap_or("A") {
cssparser_internal__to_lowercase!(__input, MAX_LENGTH => lowercase);

// We know __input will never match if it reaches the
// `unwrap_or`, but this is needed to make pattern bindings work
// as expected, see:
//
// https://github.com/servo/rust-cssparser/issues/126
match lowercase.unwrap_or(__input) {
$( $match_body )*
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,21 @@ fn procedural_masquerade_whitespace() {
_ => panic!("4"),
}
}

#[test]
fn known_not_matching() {
match_ignore_ascii_case! { "fo",
"bar" => {},
value => assert_eq!(value, "fo"),
}

match_ignore_ascii_case! { "foo",
"bar" => {},
value => assert_eq!(value, "foo"),
}

match_ignore_ascii_case! { "fooo",
"bar" => {},
value => assert_eq!(value, "fooo"),
}
}