Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Commit df1c75a

Browse files
committed
Revert "Revert tests for string and vec"
This reverts commit 0ab2663.
1 parent 710ba7d commit df1c75a

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

tests/string.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
use alloc_wg::{borrow::Cow, collections::CollectionAllocErr::*, string::String, vec, vec::Vec};
1+
use alloc_wg::{
2+
alloc::Global,
3+
borrow::Cow,
4+
collections::CollectionAllocErr::*,
5+
string::String,
6+
vec,
7+
vec::Vec,
8+
};
29
use core::{isize, mem::size_of, usize};
310

411
pub trait IntoCow<'a, B: ?Sized>
@@ -576,7 +583,7 @@ fn test_try_reserve() {
576583

577584
{
578585
// Note: basic stuff is checked by test_reserve
579-
let mut empty_string = String::new();
586+
let mut empty_string = String::new_in(Global);
580587

581588
// Check isize::MAX doesn't count as an overflow
582589
if let Err(CapacityOverflow) = empty_string.try_reserve(MAX_CAP) {
@@ -616,7 +623,10 @@ fn test_try_reserve() {
616623

617624
{
618625
// Same basic idea, but with non-zero len
619-
let mut ten_bytes = String::from("0123456789");
626+
let mut ten_bytes = String::new_in(Global);
627+
ten_bytes
628+
.try_push_str("0123456789")
629+
.expect("Could not create string with 10 bytes");
620630

621631
if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 10) {
622632
panic!("isize::MAX shouldn't trigger an overflow!");
@@ -655,7 +665,7 @@ fn test_try_reserve_exact() {
655665
let guards_against_isize = size_of::<usize>() < 8;
656666

657667
{
658-
let mut empty_string = String::new();
668+
let mut empty_string = String::new_in(Global);
659669

660670
if let Err(CapacityOverflow) = empty_string.try_reserve_exact(MAX_CAP) {
661671
panic!("isize::MAX shouldn't trigger an overflow!");
@@ -688,7 +698,10 @@ fn test_try_reserve_exact() {
688698
}
689699

690700
{
691-
let mut ten_bytes = String::from("0123456789");
701+
let mut ten_bytes = String::new_in(Global);
702+
ten_bytes
703+
.try_push_str("0123456789")
704+
.expect("Could not create string with 10 bytes");
692705

693706
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_CAP - 10) {
694707
panic!("isize::MAX shouldn't trigger an overflow!");

tests/vec.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc_wg::{
2+
alloc::Global,
23
boxed::Box,
34
collections::CollectionAllocErr::*,
45
vec,
@@ -1125,7 +1126,7 @@ fn test_try_reserve() {
11251126

11261127
{
11271128
// Note: basic stuff is checked by test_reserve
1128-
let mut empty_bytes: Vec<u8, _> = Vec::new();
1129+
let mut empty_bytes: Vec<u8, _> = Vec::new_in(Global);
11291130

11301131
// Check isize::MAX doesn't count as an overflow
11311132
if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_CAP) {
@@ -1163,7 +1164,8 @@ fn test_try_reserve() {
11631164

11641165
{
11651166
// Same basic idea, but with non-zero len
1166-
let mut ten_bytes: Vec<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1167+
let mut ten_bytes: Vec<u8, _> = vec![try in Global; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1168+
.expect("Unable to allocate ten bytes");
11671169

11681170
if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 10) {
11691171
panic!("isize::MAX shouldn't trigger an overflow!");
@@ -1188,7 +1190,8 @@ fn test_try_reserve() {
11881190

11891191
{
11901192
// Same basic idea, but with interesting type size
1191-
let mut ten_u32s: Vec<u32> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1193+
let mut ten_u32s: Vec<u32, _> = vec![try in Global; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1194+
.expect("Unable to allocate 40 bytes");
11921195

11931196
if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 10) {
11941197
panic!("isize::MAX shouldn't trigger an overflow!");
@@ -1225,7 +1228,7 @@ fn test_try_reserve_exact() {
12251228
let guards_against_isize = size_of::<usize>() < 8;
12261229

12271230
{
1228-
let mut empty_bytes: Vec<u8> = Vec::new();
1231+
let mut empty_bytes: Vec<u8, _> = Vec::new_in(Global);
12291232

12301233
if let Err(CapacityOverflow) = empty_bytes.try_reserve_exact(MAX_CAP) {
12311234
panic!("isize::MAX shouldn't trigger an overflow!");
@@ -1256,7 +1259,8 @@ fn test_try_reserve_exact() {
12561259
}
12571260

12581261
{
1259-
let mut ten_bytes: Vec<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1262+
let mut ten_bytes: Vec<u8, _> = vec![try in Global; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1263+
.expect("Unable to allocate ten bytes");
12601264

12611265
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_CAP - 10) {
12621266
panic!("isize::MAX shouldn't trigger an overflow!");
@@ -1279,7 +1283,8 @@ fn test_try_reserve_exact() {
12791283
}
12801284

12811285
{
1282-
let mut ten_u32s: Vec<u32> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1286+
let mut ten_u32s: Vec<u32, _> = vec![try in Global; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1287+
.expect("Unable to allocate 40 bytes");
12831288

12841289
if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 10) {
12851290
panic!("isize::MAX shouldn't trigger an overflow!");

0 commit comments

Comments
 (0)