about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-01-08 14:32:25 +0000
committerbors <bors@rust-lang.org>2018-01-08 14:32:25 +0000
commitb5392f54503fdaf04df4b9578510b2baa944f4af (patch)
tree12adb29130d21b3bd5fc09d45e9c8d9c5301247d /src/libcore/tests
parent1b193de98af5b8c6e2b50908ea64323b9095a1a4 (diff)
parent9066219f43d6ea8fac8e683620a80f70c9a4d4f3 (diff)
Auto merge of #47208 - Manishearth:double-ended-searcher, r=pnkfelix
Make double ended searchers use dependent fingers

(fixes #47175)

r? @burntsushi @alexcrichton

needs uplift to beta
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/pattern.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libcore/tests/pattern.rs b/src/libcore/tests/pattern.rs
index d0fd15263b2..cfa3b7ee664 100644
--- a/src/libcore/tests/pattern.rs
+++ b/src/libcore/tests/pattern.rs
@@ -262,3 +262,41 @@ fn test_reverse_search_shared_bytes() {
         [InRange(37, 40), Rejects(34, 37), InRange(10, 13), Rejects(8, 10), Done]
     );
 }
+
+#[test]
+fn double_ended_regression_test() {
+    // https://github.com/rust-lang/rust/issues/47175
+    // Ensures that double ended searching comes to a convergence
+    search_asserts!("abcdeabcdeabcde", 'a', "alternating double ended search",
+        [next_match,    next_match_back,    next_match,      next_match_back],
+        [InRange(0, 1), InRange(10, 11), InRange(5, 6), Done]
+    );
+    search_asserts!("abcdeabcdeabcde", 'a', "triple double ended search for a",
+        [next_match,    next_match_back,    next_match_back,      next_match_back],
+        [InRange(0, 1), InRange(10, 11), InRange(5, 6), Done]
+    );
+    search_asserts!("abcdeabcdeabcde", 'd', "triple double ended search for d",
+        [next_match,    next_match_back,    next_match_back,      next_match_back],
+        [InRange(3, 4), InRange(13, 14), InRange(8, 9), Done]
+    );
+    search_asserts!(STRESS, 'Á', "Double ended search for two-byte Latin character",
+        [next_match,    next_match_back,     next_match,      next_match_back],
+        [InRange(0, 2), InRange(32, 34), InRange(8, 10), Done]
+    );
+    search_asserts!(STRESS, '각', "Reverse double ended search for three-byte Hangul character",
+        [next_match_back, next_back,       next_match,      next,            next_match_back, next_match],
+        [InRange(34, 37), Rejects(32, 34), InRange(19, 22), Rejects(22, 25), InRange(28, 31), Done]
+    );
+    search_asserts!(STRESS, 'āļ', "Double ended search for three-byte Thai character",
+        [next_match,      next_back,       next,            next_match_back, next_match],
+        [InRange(22, 25), Rejects(47, 48), Rejects(25, 28), InRange(40, 43), Done]
+    );
+    search_asserts!(STRESS, '😁', "Double ended search for four-byte emoji",
+        [next_match_back, next,          next_match,      next_back,       next_match],
+        [InRange(43, 47), Rejects(0, 2), InRange(15, 19), Rejects(40, 43), Done]
+    );
+    search_asserts!(STRESS, 'ꁁ', "Double ended search for three-byte Yi character with repeated bytes",
+        [next_match,      next,            next_match_back, next_back,       next_match],
+        [InRange(10, 13), Rejects(13, 14), InRange(37, 40), Rejects(34, 37), Done]
+    );
+}