Skip to content

Commit 8547d19

Browse files
mbrubeckkwantam
authored andcommitted
Add quickcheck tests
closes #13
1 parent 364d83b commit 8547d19

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ exclude = [ "target/*", "Cargo.lock", "scripts/tmp" ]
2020

2121
[features]
2222
no_std = [] # This is a no-op, preserved for backward compatibility only.
23+
24+
[dev-dependencies]
25+
quickcheck = "0.4"

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
#[macro_use]
6060
extern crate std;
6161

62+
#[cfg(test)]
63+
#[macro_use]
64+
extern crate quickcheck;
65+
6266
pub use grapheme::{Graphemes, GraphemeIndices};
6367
pub use tables::UNICODE_VERSION;
6468
pub use word::{UWordBounds, UWordBoundIndices, UnicodeWords};

src/test.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,37 @@ fn test_words() {
146146
"Reverse word indices");
147147
}
148148
}
149+
150+
quickcheck! {
151+
fn quickcheck_forward_reverse_graphemes_extended(s: String) -> bool {
152+
let a = s.graphemes(true).collect::<Vec<_>>();
153+
let mut b = s.graphemes(true).rev().collect::<Vec<_>>();
154+
b.reverse();
155+
a == b
156+
}
157+
158+
fn quickcheck_forward_reverse_graphemes_legacy(s: String) -> bool {
159+
let a = s.graphemes(false).collect::<Vec<_>>();
160+
let mut b = s.graphemes(false).rev().collect::<Vec<_>>();
161+
b.reverse();
162+
a == b
163+
}
164+
165+
fn quickcheck_join_graphemes(s: String) -> bool {
166+
let a = s.graphemes(true).collect::<String>();
167+
let b = s.graphemes(false).collect::<String>();
168+
a == s && b == s
169+
}
170+
171+
fn quickcheck_forward_reverse_words(s: String) -> bool {
172+
let a = s.split_word_bounds().collect::<Vec<_>>();
173+
let mut b = s.split_word_bounds().rev().collect::<Vec<_>>();
174+
b.reverse();
175+
a == b
176+
}
177+
178+
fn quickcheck_join_words(s: String) -> bool {
179+
let a = s.split_word_bounds().collect::<String>();
180+
a == s
181+
}
182+
}

0 commit comments

Comments
 (0)