| ... | @@ -602,3 +602,22 @@ test "ensure capacity on empty list" { | ... | @@ -602,3 +602,22 @@ test "ensure capacity on empty list" { |
| 602 | try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a)); | 602 | try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a)); |
| 603 | try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b)); | 603 | try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b)); |
| 604 | } | 604 | } |
| | 605 | |
| | 606 | test "insert elements" { |
| | 607 | const ally = testing.allocator; |
| | 608 | |
| | 609 | const Foo = struct { |
| | 610 | a: u8, |
| | 611 | b: u32, |
| | 612 | }; |
| | 613 | |
| | 614 | var list = MultiArrayList(Foo){}; |
| | 615 | defer list.deinit(ally); |
| | 616 | |
| | 617 | try list.insert(ally, 0, .{ .a = 1, .b = 2 }); |
| | 618 | try list.ensureUnusedCapacity(ally, 1); |
| | 619 | list.insertAssumeCapacity(1, .{ .a = 2, .b = 3 }); |
| | 620 | |
| | 621 | try testing.expectEqualSlices(u8, &[_]u8{ 1, 2 }, list.items(.a)); |
| | 622 | try testing.expectEqualSlices(u32, &[_]u32{ 2, 3 }, list.items(.b)); |
| | 623 | } |