Skip to content

Commit 25ba655

Browse files
anakrishCopilot
andcommitted
test(value/array): cover overflow + remove Vec-backend assertions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ebc5165 commit 25ba655

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/value/tests.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,12 @@ fn array_constructors_equality_and_ordering() {
576576
assert!(empty.is_empty());
577577
assert_eq!(empty.len(), 0);
578578

579+
let zero_capacity = Array::with_capacity(0).expect("zero capacity should reserve");
580+
assert!(zero_capacity.is_empty());
581+
582+
let kilobyte_capacity = Array::with_capacity(1024).expect("capacity should reserve");
583+
assert!(kilobyte_capacity.is_empty());
584+
579585
let mut with_capacity = Array::with_capacity(2).expect("capacity should reserve");
580586
with_capacity.push(val(1)).expect("push should fit");
581587
with_capacity.push(val(2)).expect("push should fit");
@@ -587,6 +593,17 @@ fn array_constructors_equality_and_ordering() {
587593
assert!(Array::from(vec![val(1), val(2)]) < Array::from(vec![val(1), val(3)]));
588594
}
589595

596+
#[test]
597+
fn with_capacity_overflow_is_safe() {
598+
let over_isize_max = usize::try_from(isize::MAX)
599+
.expect("isize::MAX should fit in usize")
600+
.checked_add(1)
601+
.expect("usize should represent isize::MAX + 1");
602+
603+
assert!(Array::with_capacity(usize::MAX).is_none());
604+
assert!(Array::with_capacity(over_isize_max).is_none());
605+
}
606+
590607
#[test]
591608
fn array_mutators_and_accessors() {
592609
let mut array = Array::new();
@@ -703,15 +720,13 @@ fn array_sort_dedup_and_reverse() {
703720
#[test]
704721
fn array_conversions_to_value() {
705722
let array = Array::from_iter([val(1), val(2), val(3)]);
706-
let expected = Value::Array(crate::Rc::new(vec![val(1), val(2), val(3)]));
723+
let expected = Value::from(Array::from_iter([val(1), val(2), val(3)]));
724+
707725
let value_from_impl = Value::from(array.clone());
708726
assert_eq!(value_from_impl, expected);
709727

710728
let value_from_method = array.into_value();
711-
assert_eq!(
712-
value_from_method,
713-
Value::Array(crate::Rc::new(vec![val(1), val(2), val(3)]))
714-
);
729+
assert_eq!(value_from_method, expected);
715730
}
716731

717732
#[test]

0 commit comments

Comments
 (0)