Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Commit f7b3c83

Browse files
committed
Update regex to get character class nesting & intersections
See release notes: https://github.com/rust-lang/regex/releases/tag/0.2.2
1 parent af9f249 commit f7b3c83

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ description = "An implementation of regexes, supporting a relatively rich set of
77
repository = "https://github.com/google/fancy-regex"
88

99
[dependencies]
10-
regex = "0.2.1"
10+
regex = "0.2.2"
1111
bit-set = "0.4"
1212
memchr = "1.0.1"

tests/matching.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,48 @@ use fancy_regex::Regex;
55

66
#[test]
77
fn control_character_escapes() {
8-
assert_matches(r"\a", "\x07");
9-
assert_matches(r"\e", "\x1B");
10-
assert_matches(r"\f", "\x0C");
11-
assert_matches(r"\n", "\x0A");
12-
assert_matches(r"\r", "\x0D");
13-
assert_matches(r"\t", "\x09");
14-
assert_matches(r"\v", "\x0B");
8+
assert_match(r"\a", "\x07");
9+
assert_match(r"\e", "\x1B");
10+
assert_match(r"\f", "\x0C");
11+
assert_match(r"\n", "\x0A");
12+
assert_match(r"\r", "\x0D");
13+
assert_match(r"\t", "\x09");
14+
assert_match(r"\v", "\x0B");
1515
}
1616

17+
#[test]
18+
fn character_class_nested() {
19+
assert_match(r"[[a][bc]]", "c");
20+
assert_match(r"[a[^b]]", "c");
21+
}
22+
23+
#[test]
24+
fn character_class_intersection() {
25+
assert_match(r"[\w&&a-c]", "c");
26+
assert_no_match(r"[\w&&a-c]", "d");
27+
28+
assert_match(r"[[0-9]&&[^4]]", "1");
29+
assert_no_match(r"[[0-9]&&[^4]]", "4");
30+
}
31+
32+
33+
fn assert_match(re: &str, text: &str) {
34+
let result = match_text(re, text);
35+
assert_eq!(result, true, "Expected regex '{}' to match text '{}'", re, text);
36+
}
37+
38+
fn assert_no_match(re: &str, text: &str) {
39+
let result = match_text(re, text);
40+
assert_eq!(result, false, "Expected regex '{}' to not match text '{}'", re, text);
41+
}
1742

18-
fn assert_matches(re: &str, text: &str) {
43+
fn match_text(re: &str, text: &str) -> bool {
1944
let parse_result = Regex::new(re);
2045
assert!(parse_result.is_ok(),
2146
"Expected regex '{}' to be compiled successfully, got {:?}", re, parse_result.err());
2247

2348
let regex = parse_result.unwrap();
2449
let match_result = regex.is_match(text);
2550
assert!(match_result.is_ok(), "Expected match to succeed, but was {:?}", match_result);
26-
assert_eq!(match_result.ok(), Some(true), "Expected regex '{}' to match text '{}'", re, text);
51+
match_result.unwrap()
2752
}

0 commit comments

Comments
 (0)