diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/consistent.rs | 5 | ||||
-rw-r--r-- | tests/crazy.rs | 5 | ||||
-rw-r--r-- | tests/macros_bytes.rs | 1 | ||||
-rw-r--r-- | tests/macros_str.rs | 1 | ||||
-rw-r--r-- | tests/replace.rs | 98 | ||||
-rw-r--r-- | tests/test_default.rs | 42 |
6 files changed, 143 insertions, 9 deletions
diff --git a/tests/consistent.rs b/tests/consistent.rs index 0f9ea53..722f2a5 100644 --- a/tests/consistent.rs +++ b/tests/consistent.rs @@ -157,10 +157,7 @@ macro_rules! checker { } impl quickcheck::Testable for RegexEqualityTest { - fn result<G: quickcheck::Gen>( - &self, - gen: &mut G, - ) -> TestResult { + fn result(&self, gen: &mut quickcheck::Gen) -> TestResult { let input = $mk_input(gen); let input = &input; diff --git a/tests/crazy.rs b/tests/crazy.rs index 56f6cad..293ac1a 100644 --- a/tests/crazy.rs +++ b/tests/crazy.rs @@ -137,9 +137,10 @@ matiter!(match_empty23, r"a(?:)|b", "abc", (0, 1), (1, 2)); #[test] fn dfa_handles_pathological_case() { fn ones_and_zeroes(count: usize) -> String { - use rand::{thread_rng, Rng}; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; - let mut rng = thread_rng(); + let mut rng = SmallRng::from_entropy(); let mut s = String::new(); for _ in 0..count { if rng.gen() { diff --git a/tests/macros_bytes.rs b/tests/macros_bytes.rs index 03c370d..3d6c8c3 100644 --- a/tests/macros_bytes.rs +++ b/tests/macros_bytes.rs @@ -4,7 +4,6 @@ macro_rules! t { ($re:expr) => { text!($re) } } macro_rules! match_text { ($text:expr) => { $text.as_bytes() } } macro_rules! use_ { ($($path: tt)*) => { use regex::bytes::$($path)*; } } macro_rules! empty_vec { () => { <Vec<&[u8]>>::new() } } - macro_rules! bytes { ($text:expr) => { $text } } macro_rules! no_expand { diff --git a/tests/macros_str.rs b/tests/macros_str.rs index 9b996b3..7b7eb11 100644 --- a/tests/macros_str.rs +++ b/tests/macros_str.rs @@ -4,6 +4,7 @@ macro_rules! t { ($text:expr) => { text!($text) } } macro_rules! match_text { ($text:expr) => { $text.as_str() } } macro_rules! use_ { ($($path: tt)*) => { use regex::$($path)*; } } macro_rules! empty_vec { () => { <Vec<&str>>::new() } } +macro_rules! bytes { ($text:expr) => { std::str::from_utf8($text.as_ref()).unwrap() } } macro_rules! no_expand { ($text:expr) => {{ diff --git a/tests/replace.rs b/tests/replace.rs index c156a39..700aff2 100644 --- a/tests/replace.rs +++ b/tests/replace.rs @@ -130,3 +130,101 @@ replace!( t!("${1}a $1a"), "ba " ); + +replace!( + impl_string, + replace, + r"[0-9]", + "age: 26", + t!("Z".to_string()), + "age: Z6" +); +replace!( + impl_string_ref, + replace, + r"[0-9]", + "age: 26", + t!(&"Z".to_string()), + "age: Z6" +); +replace!( + impl_cow_str_borrowed, + replace, + r"[0-9]", + "age: 26", + t!(std::borrow::Cow::<'_, str>::Borrowed("Z")), + "age: Z6" +); +replace!( + impl_cow_str_borrowed_ref, + replace, + r"[0-9]", + "age: 26", + t!(&std::borrow::Cow::<'_, str>::Borrowed("Z")), + "age: Z6" +); +replace!( + impl_cow_str_owned, + replace, + r"[0-9]", + "age: 26", + t!(std::borrow::Cow::<'_, str>::Owned("Z".to_string())), + "age: Z6" +); +replace!( + impl_cow_str_owned_ref, + replace, + r"[0-9]", + "age: 26", + t!(&std::borrow::Cow::<'_, str>::Owned("Z".to_string())), + "age: Z6" +); + +replace!( + impl_vec_u8, + replace, + r"[0-9]", + "age: 26", + bytes!(vec![b'Z']), + "age: Z6" +); +replace!( + impl_vec_u8_ref, + replace, + r"[0-9]", + "age: 26", + bytes!(&vec![b'Z']), + "age: Z6" +); +replace!( + impl_cow_slice_borrowed, + replace, + r"[0-9]", + "age: 26", + bytes!(std::borrow::Cow::<'_, [u8]>::Borrowed(&[b'Z'])), + "age: Z6" +); +replace!( + impl_cow_slice_borrowed_ref, + replace, + r"[0-9]", + "age: 26", + bytes!(&std::borrow::Cow::<'_, [u8]>::Borrowed(&[b'Z'])), + "age: Z6" +); +replace!( + impl_cow_slice_owned, + replace, + r"[0-9]", + "age: 26", + bytes!(std::borrow::Cow::<'_, [u8]>::Owned(vec![b'Z'])), + "age: Z6" +); +replace!( + impl_cow_slice_owned_ref, + replace, + r"[0-9]", + "age: 26", + bytes!(&std::borrow::Cow::<'_, [u8]>::Owned(vec![b'Z'])), + "age: Z6" +); diff --git a/tests/test_default.rs b/tests/test_default.rs index 241e580..af634a0 100644 --- a/tests/test_default.rs +++ b/tests/test_default.rs @@ -83,26 +83,49 @@ fn allow_octal() { #[test] fn oibits() { use regex::bytes; - use regex::{Regex, RegexBuilder}; - use std::panic::UnwindSafe; + use regex::{Regex, RegexBuilder, RegexSet, RegexSetBuilder}; + use std::panic::{RefUnwindSafe, UnwindSafe}; fn assert_send<T: Send>() {} fn assert_sync<T: Sync>() {} fn assert_unwind_safe<T: UnwindSafe>() {} + fn assert_ref_unwind_safe<T: RefUnwindSafe>() {} assert_send::<Regex>(); assert_sync::<Regex>(); assert_unwind_safe::<Regex>(); + assert_ref_unwind_safe::<Regex>(); assert_send::<RegexBuilder>(); assert_sync::<RegexBuilder>(); assert_unwind_safe::<RegexBuilder>(); + assert_ref_unwind_safe::<RegexBuilder>(); assert_send::<bytes::Regex>(); assert_sync::<bytes::Regex>(); assert_unwind_safe::<bytes::Regex>(); + assert_ref_unwind_safe::<bytes::Regex>(); assert_send::<bytes::RegexBuilder>(); assert_sync::<bytes::RegexBuilder>(); assert_unwind_safe::<bytes::RegexBuilder>(); + assert_ref_unwind_safe::<bytes::RegexBuilder>(); + + assert_send::<RegexSet>(); + assert_sync::<RegexSet>(); + assert_unwind_safe::<RegexSet>(); + assert_ref_unwind_safe::<RegexSet>(); + assert_send::<RegexSetBuilder>(); + assert_sync::<RegexSetBuilder>(); + assert_unwind_safe::<RegexSetBuilder>(); + assert_ref_unwind_safe::<RegexSetBuilder>(); + + assert_send::<bytes::RegexSet>(); + assert_sync::<bytes::RegexSet>(); + assert_unwind_safe::<bytes::RegexSet>(); + assert_ref_unwind_safe::<bytes::RegexSet>(); + assert_send::<bytes::RegexSetBuilder>(); + assert_sync::<bytes::RegexSetBuilder>(); + assert_unwind_safe::<bytes::RegexSetBuilder>(); + assert_ref_unwind_safe::<bytes::RegexSetBuilder>(); } // See: https://github.com/rust-lang/regex/issues/568 @@ -113,3 +136,18 @@ fn oibits_regression() { let _ = panic::catch_unwind(|| Regex::new("a").unwrap()); } + +// See: https://github.com/rust-lang/regex/issues/750 +#[test] +#[cfg(target_pointer_width = "64")] +fn regex_is_reasonably_small() { + use std::mem::size_of; + + use regex::bytes; + use regex::{Regex, RegexSet}; + + assert_eq!(16, size_of::<Regex>()); + assert_eq!(16, size_of::<RegexSet>()); + assert_eq!(16, size_of::<bytes::Regex>()); + assert_eq!(16, size_of::<bytes::RegexSet>()); +} |