From 9419e9265950a16f873dbed49c715fd7ea4e08e7 Mon Sep 17 00:00:00 2001 From: nham Date: Tue, 19 Aug 2014 15:20:51 -0400 Subject: Fix TwoWaySearcher to work when used with periodic needles. There is a check in TwoWaySearcher::new to determine whether the needle is periodic. This is needed because during searching when a match fails, we cannot advance the position by the entire length of the needle when it is periodic, but can only advance by the length of the period. The reason "bananas".contains("nana") (and similar searches) were returning false was because the periodicity check was wrong. Closes #16589 --- src/libcoretest/str.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libcoretest') diff --git a/src/libcoretest/str.rs b/src/libcoretest/str.rs index bac8d509b13..be2275dcd4a 100644 --- a/src/libcoretest/str.rs +++ b/src/libcoretest/str.rs @@ -8,7 +8,27 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn check_contains_all_substrings(s: &str) { + assert!(s.contains("")); + for i in range(0, s.len()) { + for j in range(i+1, s.len() + 1) { + assert!(s.contains(s.slice(i, j))); + } + } +} + #[test] fn strslice_issue_16589() { assert!("bananas".contains("nana")); + + // prior to the fix for #16589, x.contains("abcdabcd") returned false + // test all substrings for good measure + check_contains_all_substrings("012345678901234567890123456789bcdabcdabcd"); +} + + +#[test] +fn test_strslice_contains() { + let x = "There are moments, Jeeves, when one asks oneself, 'Do trousers matter?'"; + check_contains_all_substrings(x); } -- cgit 1.4.1-3-g733a5