Skip to content

Commit 0806d95

Browse files
committed
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.
1 parent 8925973 commit 0806d95

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/liballoc/tests/slice.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,15 @@ fn test_join() {
609609
assert_eq!(v.join(&0), [1, 0, 2, 0, 3]);
610610
}
611611

612+
#[test]
613+
fn test_join_nocopy() {
614+
let v: [String; 0] = [];
615+
assert_eq!(v.join(","), "");
616+
assert_eq!(["a".to_string(), "ab".into()].join(","), "a,ab");
617+
assert_eq!(["a".to_string(), "ab".into(), "abc".into()].join(","), "a,ab,abc");
618+
assert_eq!(["a".to_string(), "ab".into(), "".into()].join(","), "a,ab,");
619+
}
620+
612621
#[test]
613622
fn test_insert() {
614623
let mut a = vec![1, 2, 4];

src/liballoc/tests/str.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ fn test_join_for_different_lengths() {
162162
test_join!("-a-bc", ["", "a", "bc"], "-");
163163
}
164164

165+
// join has fast paths for small separators up to 4 bytes
166+
// this tests the slow paths.
167+
#[test]
168+
fn test_join_for_different_lengths_with_long_separator() {
169+
assert_eq!("~~~~~".len(), 15);
170+
171+
let empty: &[&str] = &[];
172+
test_join!("", empty, "~~~~~");
173+
test_join!("a", ["a"], "~~~~~");
174+
test_join!("a~~~~~b", ["a", "b"], "~~~~~");
175+
test_join!("~~~~~a~~~~~bc", ["", "a", "bc"], "~~~~~");
176+
}
177+
165178
#[test]
166179
fn test_unsafe_slice() {
167180
assert_eq!("ab", unsafe {"abc".slice_unchecked(0, 2)});

0 commit comments

Comments
 (0)