diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-08-02 19:03:01 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-08-02 20:08:35 +0200 |
| commit | c5a1d8c3db171a4351712c04e6ba6a4e4636a332 (patch) | |
| tree | 2197df5eeb2fd3b44d02928bdea4dea662e41fac | |
| parent | 832e5a02cd41b3a20d1142b47867da4aa5033f03 (diff) | |
| download | rust-c5a1d8c3db171a4351712c04e6ba6a4e4636a332.tar.gz rust-c5a1d8c3db171a4351712c04e6ba6a4e4636a332.zip | |
StrSearcher: Add tests for rfind(&str)
Add tests for .rfind(&str), using the reverse searcher case for substring search.
| -rw-r--r-- | src/libcollectionstest/str.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcollectionstest/str.rs b/src/libcollectionstest/str.rs index 4cccb29b41c..ac9c7908ab8 100644 --- a/src/libcollectionstest/str.rs +++ b/src/libcollectionstest/str.rs @@ -115,6 +115,26 @@ fn test_find_str() { assert_eq!(data[43..86].find("ย中"), Some(67 - 43)); assert_eq!(data[43..86].find("iệt"), Some(77 - 43)); assert_eq!(data[43..86].find("Nam"), Some(83 - 43)); + + // find every substring -- assert that it finds it, or an earlier occurence. + let string = "Việt Namacbaabcaabaaba"; + for (i, ci) in string.char_indices() { + let ip = i + ci.len_utf8(); + for j in string[ip..].char_indices() + .map(|(i, _)| i) + .chain(Some(string.len() - ip)) + { + let pat = &string[i..ip + j]; + assert!(match string.find(pat) { + None => false, + Some(x) => x <= i, + }); + assert!(match string.rfind(pat) { + None => false, + Some(x) => x >= i, + }); + } + } } #[test] |
