Skip to content
Merged
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
5 changes: 5 additions & 0 deletions regex_macros/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

use regex::{Regex, NoExpand};

#[test]
fn eq() {
assert_eq!(regex!(r"[a-z]+"), Regex::new("[a-z]+").unwrap());
}

#[test]
fn splitn() {
let re = regex!(r"\d+");
Expand Down
11 changes: 11 additions & 0 deletions src/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ impl fmt::Debug for Regex {
}
}

/// Equality comparison is based on the original string. It is possible that different regular
/// expressions have the same matching behavior, but are still compared unequal. For example,
/// `\d+` and `\d\d*` match the same set of strings, but are not considered equal.
impl PartialEq for Regex {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yorhel Could you please put a doc comment on this impl explaining the definition of equality used? (Something like what you said in your initial comment is just fine.)

fn eq(&self, other: &Regex) -> bool {
self.as_str() == other.as_str()
}
}

impl Eq for Regex {}

impl FromStr for Regex {
type Err = parse::Error;

Expand Down