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.
This commit is contained in:
parent
d866082050
commit
b2fd7da0cf
2 changed files with 22 additions and 0 deletions
|
@ -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];
|
||||
|
|
|
@ -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)});
|
||||
|
|
Loading…
Reference in a new issue