diff --git a/Cargo.toml b/Cargo.toml index aee86b3..5ffa4c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,6 @@ exclude = [ "target/*", "Cargo.lock", "scripts/tmp" ] [features] no_std = [] # This is a no-op, preserved for backward compatibility only. + +[dev-dependencies] +quickcheck = "0.4" diff --git a/src/lib.rs b/src/lib.rs index d895163..32e467c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,6 +59,10 @@ #[macro_use] extern crate std; +#[cfg(test)] +#[macro_use] +extern crate quickcheck; + pub use grapheme::{Graphemes, GraphemeIndices}; pub use tables::UNICODE_VERSION; pub use word::{UWordBounds, UWordBoundIndices, UnicodeWords}; diff --git a/src/test.rs b/src/test.rs index 42cb205..71efd62 100644 --- a/src/test.rs +++ b/src/test.rs @@ -146,3 +146,37 @@ fn test_words() { "Reverse word indices"); } } + +quickcheck! { + fn quickcheck_forward_reverse_graphemes_extended(s: String) -> bool { + let a = s.graphemes(true).collect::>(); + let mut b = s.graphemes(true).rev().collect::>(); + b.reverse(); + a == b + } + + fn quickcheck_forward_reverse_graphemes_legacy(s: String) -> bool { + let a = s.graphemes(false).collect::>(); + let mut b = s.graphemes(false).rev().collect::>(); + b.reverse(); + a == b + } + + fn quickcheck_join_graphemes(s: String) -> bool { + let a = s.graphemes(true).collect::(); + let b = s.graphemes(false).collect::(); + a == s && b == s + } + + fn quickcheck_forward_reverse_words(s: String) -> bool { + let a = s.split_word_bounds().collect::>(); + let mut b = s.split_word_bounds().rev().collect::>(); + b.reverse(); + a == b + } + + fn quickcheck_join_words(s: String) -> bool { + let a = s.split_word_bounds().collect::(); + a == s + } +}