Skip to content

Commit 0ce9323

Browse files
committed
Add a test for the unsafe conversion
1 parent 20c84cd commit 0ce9323

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcollectionstest/string.rs

+16
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,22 @@ fn test_into_boxed_str() {
392392
assert_eq!(&*ys, "hello my name is bob");
393393
}
394394

395+
#[test]
396+
fn test_string_from_vec_char() {
397+
let str1 = String::from(vec!['a', 'b', '😃', 'a', 'b']);
398+
let str2 = String::from(vec!['a', 'ą', 'あ', '🞎']);
399+
let str3 = String::from(vec!['🞎', 'あ', 'ą', 'a']);
400+
assert_eq!("ab😃ab", str1);
401+
assert_eq!(str1.len(), 8);
402+
assert!(str1.capacity() >= 20);
403+
assert_eq!("aąあ🞎", str2);
404+
assert_eq!(str2.len(), 10);
405+
assert!(str2.capacity() >= 16);
406+
assert_eq!("🞎あąa", str3);
407+
assert_eq!(str3.len(), 10);
408+
assert!(str3.capacity() >= 16);
409+
}
410+
395411
#[bench]
396412
fn bench_with_capacity(b: &mut Bencher) {
397413
b.iter(|| String::with_capacity(100));

0 commit comments

Comments
 (0)