Skip to content

Commit

Permalink
add more join tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Emerentius committed Jun 1, 2018
1 parent d866082 commit b2fd7da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/liballoc/tests/slice.rs
Expand Up @@ -609,6 +609,15 @@ fn test_join() {
assert_eq!(v.join(&0), [1, 0, 2, 0, 3]);
}

#[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];
Expand Down
13 changes: 13 additions & 0 deletions src/liballoc/tests/str.rs
Expand Up @@ -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)});
Expand Down

0 comments on commit b2fd7da

Please sign in to comment.