about summary refs log tree commit diff
path: root/src/liballoc/tests
diff options
context:
space:
mode:
authorEmerentius <emerentius@arcor.de>2018-05-07 17:37:13 +0200
committerEmerentius <emerentius@arcor.de>2018-06-01 17:13:25 +0200
commitb2fd7da0cf0b835a540d333b4b72426b4735c586 (patch)
treecbc62a03a0f73b7cf36bad393c78ad779b0f6df9 /src/liballoc/tests
parentd86608205069aed5c78bcc38dd26bcf4213e23a0 (diff)
downloadrust-b2fd7da0cf0b835a540d333b4b72426b4735c586.tar.gz
rust-b2fd7da0cf0b835a540d333b4b72426b4735c586.zip
add more join tests
old tests cover the new fast path of str joining already
this adds tests for joining into Strings with long separators (>4 byte) and
for joining into Vec<T>, T: Clone + !Copy. Vec<T: Copy> will be
specialised when specialisation type inference bugs are fixed.
Diffstat (limited to 'src/liballoc/tests')
-rw-r--r--src/liballoc/tests/slice.rs9
-rw-r--r--src/liballoc/tests/str.rs13
2 files changed, 22 insertions, 0 deletions
diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs
index 6fd0b33f02a..3b7eec38609 100644
--- a/src/liballoc/tests/slice.rs
+++ b/src/liballoc/tests/slice.rs
@@ -610,6 +610,15 @@ fn test_join() {
 }
 
 #[test]
+fn test_join_nocopy() {
+    let v: [String; 0] = [];
+    assert_eq!(v.join(","), "");
+    assert_eq!(["a".to_string(), "ab".into()].join(","), "a,ab");
+    assert_eq!(["a".to_string(), "ab".into(), "abc".into()].join(","), "a,ab,abc");
+    assert_eq!(["a".to_string(), "ab".into(), "".into()].join(","), "a,ab,");
+}
+
+#[test]
 fn test_insert() {
     let mut a = vec![1, 2, 4];
     a.insert(2, 3);
diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs
index d11bf5dc3e9..03d295d16e6 100644
--- a/src/liballoc/tests/str.rs
+++ b/src/liballoc/tests/str.rs
@@ -162,6 +162,19 @@ fn test_join_for_different_lengths() {
     test_join!("-a-bc", ["", "a", "bc"], "-");
 }
 
+// join has fast paths for small separators up to 4 bytes
+// this tests the slow paths.
+#[test]
+fn test_join_for_different_lengths_with_long_separator() {
+    assert_eq!("~~~~~".len(), 15);
+
+    let empty: &[&str] = &[];
+    test_join!("", empty, "~~~~~");
+    test_join!("a", ["a"], "~~~~~");
+    test_join!("a~~~~~b", ["a", "b"], "~~~~~");
+    test_join!("~~~~~a~~~~~bc", ["", "a", "bc"], "~~~~~");
+}
+
 #[test]
 fn test_unsafe_slice() {
     assert_eq!("ab", unsafe {"abc".slice_unchecked(0, 2)});