Skip to content

Commit 21299dc

Browse files
committed
Add extra test for capacity tracking
1 parent 28a8969 commit 21299dc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cpp11test/src/test-r_vector.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,26 @@ context("r_vector-C++") {
273273
expect_true(before == 0);
274274
expect_true(after - before == 1);
275275
}
276+
277+
test_that("writable vector copy constructor correctly tracks the `capacity_`") {
278+
cpp11::writable::integers x(2);
279+
x[0] = 1;
280+
x[1] = 2;
281+
282+
// Doubles the capacity from 2 to 4
283+
x.push_back(3);
284+
285+
// Calls writable copy constructor.
286+
// Should duplicate without truncations and retain same capacity.
287+
cpp11::writable::integers y(x);
288+
289+
// In the past, we truncated (i.e. to size 3) but retained the same capacity of 4,
290+
// so this could try to push without first resizing.
291+
y.push_back(4);
292+
293+
expect_true(y[0] == 1);
294+
expect_true(y[1] == 2);
295+
expect_true(y[2] == 3);
296+
expect_true(y[3] == 4);
297+
}
276298
}

0 commit comments

Comments
 (0)