@@ -5,23 +5,48 @@ use fancy_regex::Regex;
5
5
6
6
#[ test]
7
7
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 " ) ;
15
15
}
16
16
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
+ }
17
42
18
- fn assert_matches ( re : & str , text : & str ) {
43
+ fn match_text ( re : & str , text : & str ) -> bool {
19
44
let parse_result = Regex :: new ( re) ;
20
45
assert ! ( parse_result. is_ok( ) ,
21
46
"Expected regex '{}' to be compiled successfully, got {:?}" , re, parse_result. err( ) ) ;
22
47
23
48
let regex = parse_result. unwrap ( ) ;
24
49
let match_result = regex. is_match ( text) ;
25
50
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 ( )
27
52
}
0 commit comments