From a7ff5a3e715923497f3f13ffa421ef2ad0bb2c28 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 11 Apr 2026 04:59:37 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[Testing=20Improvement]=20Add=20?= =?UTF-8?q?Tests=20for=20ArrayList=20pop=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎯 **What:** Added tests to cover the `ArrayList.pop` functionality to ensure it safely handles empty lists (specifically when `clear()` is called beforehand) and complex types like `[]const u8` (string slices). 📊 **Coverage:** The new test cases explicitly verify that calling `pop()` on a cleared list safely returns `null` rather than causing undefined behavior. They also verify correctly popping off slice elements without pointer errors. ✨ **Result:** Enhanced test coverage for the core `ArrayList` data structure, catching potential bugs associated with popping empty lists or complex data types. Co-authored-by: ulac000000 <132948319+ulac000000@users.noreply.github.com> --- echo-core-zig/src/data/arraylist.zig | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/echo-core-zig/src/data/arraylist.zig b/echo-core-zig/src/data/arraylist.zig index 80a3f42..084a8bd 100644 --- a/echo-core-zig/src/data/arraylist.zig +++ b/echo-core-zig/src/data/arraylist.zig @@ -109,3 +109,32 @@ 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 clear and pop" { + var list = ArrayList(i32).init(std.testing.allocator); + defer list.deinit(); + + try list.append(10); + try list.append(20); + try list.append(30); + + list.clear(); + try std.testing.expectEqual(@as(usize, 0), list.len); + try std.testing.expectEqual(@as(?i32, null), list.pop()); +} + +test "ArrayList pop string slices" { + var list = ArrayList([]const u8).init(std.testing.allocator); + defer list.deinit(); + + try list.append("hello"); + try list.append("world"); + + const popped_world = list.pop().?; + try std.testing.expectEqualStrings("world", popped_world); + + const popped_hello = list.pop().?; + try std.testing.expectEqualStrings("hello", popped_hello); + + try std.testing.expectEqual(@as(?[]const u8, null), list.pop()); +}