File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -273,4 +273,26 @@ context("r_vector-C++") {
273
273
expect_true (before == 0 );
274
274
expect_true (after - before == 1 );
275
275
}
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
+ }
276
298
}
You can’t perform that action at this time.
0 commit comments