]> gitweb.ps.run Git - ziggit/blobdiff - git.zig
add arena allocator to tests
[ziggit] / git.zig
diff --git a/git.zig b/git.zig
index 22bdf5daab0420333bd0fd461f9bb527b35f3883..80e9aace87a0e8b0b28a05593101251170723ded 100644 (file)
--- a/git.zig
+++ b/git.zig
@@ -410,7 +410,10 @@ const Repo = struct {
 };
 
 test "print HEAD" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -420,7 +423,10 @@ test "print HEAD" {
 }
 
 test "parse idx" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -431,7 +437,10 @@ test "parse idx" {
 }
 
 test "get object" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -445,7 +454,10 @@ test "get object" {
 }
 
 test "parse commit" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -464,7 +476,10 @@ test "parse commit" {
 }
 
 test "get tree" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -476,7 +491,10 @@ test "get tree" {
 }
 
 test "parse tree" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -496,7 +514,10 @@ test "parse tree" {
 }
 
 test "list commits" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -520,7 +541,10 @@ test "list commits" {
 }
 
 test "list blobs" {
-    const alloc = std.testing.allocator;
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
     var repo = try Repo.open(alloc, "../imgui/.git");
     defer repo.close();
 
@@ -546,3 +570,30 @@ test "list blobs" {
         }
     }
 }
+
+test "basic frontend" {
+    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+    defer arena.deinit();
+    const alloc = arena.allocator();
+
+    var repo = try Repo.open(alloc, "../imgui/.git");
+    defer repo.close();
+
+    const head = try repo.getHead();
+
+    var id = head;
+
+    for (0..3) |_| {
+        if (try repo.getObject(id)) |o| {
+            defer alloc.free(o.data);
+
+            switch (try o.parse(alloc)) {
+                .c => |c| {
+                    std.debug.print("commit {x}:\n  tree: {x}\n  parent: {x}\n  author: {s}\n  committer: {s}\n  message: {s}\n", .{ id, c.tree, c.parent, c.author, c.committer, c.message });
+                    id = c.parent;
+                },
+                else => {},
+            }
+        }
+    }
+}