Skip to content

Commit

Permalink
Merge pull request #81 from yorhel/master
Browse files Browse the repository at this point in the history
Implement Eq for Regex
  • Loading branch information
BurntSushi committed Apr 23, 2015
2 parents 45b6739 + 4c60549 commit 0709ef1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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 {
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

0 comments on commit 0709ef1

Please sign in to comment.