Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions echo-core-zig/src/data/arraylist.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,40 @@ test "ArrayList get out of bounds" {
try std.testing.expectEqual(@as(?*const i32, null), list.get(1));
try std.testing.expectEqual(@as(?*const i32, null), list.get(100));
}

test "ArrayList pop complex types" {
var list = ArrayList([]const u8).init(std.testing.allocator);
defer list.deinit();

try list.append("hello");
try list.append("world");

try std.testing.expectEqual(list.len, 2);

const pop1 = list.pop();
try std.testing.expectEqualStrings("world", pop1.?);
try std.testing.expectEqual(list.len, 1);

const pop2 = list.pop();
try std.testing.expectEqualStrings("hello", pop2.?);
try std.testing.expectEqual(list.len, 0);

try std.testing.expectEqual(@as(?[]const u8, null), list.pop());
}

test "ArrayList get after pop returns null" {
var list = ArrayList(i32).init(std.testing.allocator);
defer list.deinit();

try list.append(42);
try std.testing.expectEqual(list.len, 1);

// Element is accessible before pop
const val_ptr = list.get(0);
try std.testing.expectEqual(@as(i32, 42), val_ptr.?.*);

_ = list.pop();

// Element is out of bounds after pop
try std.testing.expectEqual(@as(?*const i32, null), list.get(0));
}