| ... | ... | @@ -5,30 +5,29 @@ const expect = @import("expect").expect; |
| 5 | 5 | const nfs = @import("nfs"); |
| 6 | 6 | |
| 7 | 7 | test { |
| 8 | | _ = &git.version; |
| 9 | | _ = &git.getHEAD; |
| 10 | | _ = &git.getTags; |
| 11 | | _ = &git.revList; |
| 12 | | } |
| 13 | | |
| 14 | | test { |
| 8 | const gpa = std.testing.allocator; |
| 15 | 9 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 16 | 10 | defer arena.deinit(); |
| 17 | 11 | const alloc = arena.allocator(); |
| 18 | 12 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 19 | 13 | defer git_dir.close(); |
| 20 | | const branch_refs = try git.getBranches(alloc, git_dir); |
| 14 | var repo: git.Repository = .init(git_dir, gpa); |
| 15 | defer repo.deinit(); |
| 16 | const branch_refs = try repo.getHeads(alloc); |
| 21 | 17 | const branch_names = try extras.mapBy(alloc, branch_refs, .label); |
| 22 | 18 | try expect(branch_names).toEqualStringSlice(&.{"master"}); |
| 23 | 19 | } |
| 24 | 20 | |
| 25 | 21 | test { |
| 22 | const gpa = std.testing.allocator; |
| 26 | 23 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 27 | 24 | defer arena.deinit(); |
| 28 | 25 | const alloc = arena.allocator(); |
| 29 | 26 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 30 | 27 | defer git_dir.close(); |
| 31 | | try expect(try git.getObjectContent(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).toEqualString( |
| 28 | var repo: git.Repository = .init(git_dir, gpa); |
| 29 | defer repo.deinit(); |
| 30 | try expect(try repo.getObjectC(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).toEqualString( |
| 32 | 31 | \\tree 5403fecad0fde9120535321f222a061abc2849d9 |
| 33 | 32 | \\parent c39f57f6bb01664a7146ddbfc3debe76ec135f44 |
| 34 | 33 | \\author Meghan Denny <hello@nektro.net> 1692246864 -0700 |
| ... | ... | @@ -40,43 +39,55 @@ test { |
| 40 | 39 | } |
| 41 | 40 | |
| 42 | 41 | test { |
| 42 | const gpa = std.testing.allocator; |
| 43 | 43 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 44 | 44 | defer arena.deinit(); |
| 45 | 45 | const alloc = arena.allocator(); |
| 46 | 46 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 47 | 47 | defer git_dir.close(); |
| 48 | | try expect(try git.getObjectSize(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).toEqual(229); |
| 49 | | try expect(try git.getObjectSize(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).toEqual(45 + 47 + 55 + 58 + 0 + 18 + 6); |
| 48 | var repo: git.Repository = .init(git_dir, gpa); |
| 49 | defer repo.deinit(); |
| 50 | try expect((try repo.getObjectC(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).len).toEqual(229); |
| 51 | try expect((try repo.getObjectC(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).len).toEqual(45 + 47 + 55 + 58 + 0 + 18 + 6); |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | test { |
| 55 | const gpa = std.testing.allocator; |
| 53 | 56 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 54 | 57 | defer arena.deinit(); |
| 55 | 58 | const alloc = arena.allocator(); |
| 56 | 59 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 57 | 60 | defer git_dir.close(); |
| 58 | | try expect(try git.isType(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e", .blob)).toEqual(false); |
| 59 | | try expect(try git.isType(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e", .tree)).toEqual(false); |
| 60 | | try expect(try git.isType(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e", .commit)).toEqual(true); |
| 61 | | try expect(try git.isType(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e", .tag)).toEqual(false); |
| 61 | var repo: git.Repository = .init(git_dir, gpa); |
| 62 | defer repo.deinit(); |
| 63 | try expect((try repo.getObjectA(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).type == .blob).toEqual(false); |
| 64 | try expect((try repo.getObjectA(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).type == .tree).toEqual(false); |
| 65 | try expect((try repo.getObjectA(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).type == .commit).toEqual(true); |
| 66 | try expect((try repo.getObjectA(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).type == .tag).toEqual(false); |
| 62 | 67 | } |
| 63 | 68 | |
| 64 | 69 | test { |
| 70 | const gpa = std.testing.allocator; |
| 65 | 71 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 66 | 72 | defer arena.deinit(); |
| 67 | 73 | const alloc = arena.allocator(); |
| 68 | 74 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 69 | 75 | defer git_dir.close(); |
| 70 | | try expect(try git.getType(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).toEqual(.commit); |
| 76 | var repo: git.Repository = .init(git_dir, gpa); |
| 77 | defer repo.deinit(); |
| 78 | try expect((try repo.getObjectA(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")).type).toEqual(.commit); |
| 71 | 79 | } |
| 72 | 80 | |
| 73 | 81 | test { |
| 82 | const gpa = std.testing.allocator; |
| 74 | 83 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 75 | 84 | defer arena.deinit(); |
| 76 | 85 | const alloc = arena.allocator(); |
| 77 | 86 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 78 | 87 | defer git_dir.close(); |
| 79 | | const c = try git.parseCommit(alloc, try git.getObjectContent(alloc, git_dir, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e")); |
| 88 | var repo: git.Repository = .init(git_dir, gpa); |
| 89 | defer repo.deinit(); |
| 90 | const c = try repo.getCommitA(alloc, "a542da41f1f0c59fdd0e1527cf5ff9de3f6a0c8e"); |
| 80 | 91 | try expect(c.tree.id).toEqualString("5403fecad0fde9120535321f222a061abc2849d9"); |
| 81 | 92 | try expect(c.parents.len).toEqual(1); |
| 82 | 93 | try expect(c.parents[0].id).toEqualString("c39f57f6bb01664a7146ddbfc3debe76ec135f44"); |
| ... | ... | @@ -93,30 +104,36 @@ test { |
| 93 | 104 | } |
| 94 | 105 | |
| 95 | 106 | test { |
| 107 | const gpa = std.testing.allocator; |
| 96 | 108 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 97 | 109 | defer arena.deinit(); |
| 98 | 110 | const alloc = arena.allocator(); |
| 99 | 111 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 100 | 112 | defer git_dir.close(); |
| 101 | | try expect(try git.getObjectContent(alloc, git_dir, "5403fecad0fde9120535321f222a061abc2849d9")).toEqualString( |
| 113 | var repo: git.Repository = .init(git_dir, gpa); |
| 114 | defer repo.deinit(); |
| 115 | try expect(try repo.getObjectC(alloc, "5403fecad0fde9120535321f222a061abc2849d9")).toEqualString( |
| 102 | 116 | // zig fmt: off |
| 103 | | "100644 blob 8e8d2ceba4b327ce9db93f988492d0e21a461012\t.gitattributes\n" ++ |
| 104 | | "100644 blob bb2a57bd81d13975f2a74ae5dd0e652de07bb8a7\t.gitignore\n" ++ |
| 105 | | "100644 blob 37be0c1cfa4f097edbb1fb5c0585cd18cb08df13\tLICENSE\n" ++ |
| 106 | | "100644 blob b229eadbd5d6655c2dfbaca5a5f68f2f8f3c5454\tgit.zig\n" ++ |
| 107 | | "100644 blob bb3f1c135632cfca760bd84fb18acdab8dae8ec3\tzig.mod\n" ++ |
| 117 | "100644 .gitattributes\x00" ++ .{0x8e,0x8d,0x2c,0xeb,0xa4,0xb3,0x27,0xce,0x9d,0xb9,0x3f,0x98,0x84,0x92,0xd0,0xe2,0x1a,0x46,0x10,0x12} ++ |
| 118 | "100644 .gitignore\x00" ++ .{0xbb,0x2a,0x57,0xbd,0x81,0xd1,0x39,0x75,0xf2,0xa7,0x4a,0xe5,0xdd,0x0e,0x65,0x2d,0xe0,0x7b,0xb8,0xa7} ++ |
| 119 | "100644 LICENSE\x00" ++ .{0x37,0xbe,0x0c,0x1c,0xfa,0x4f,0x09,0x7e,0xdb,0xb1,0xfb,0x5c,0x05,0x85,0xcd,0x18,0xcb,0x08,0xdf,0x13} ++ |
| 120 | "100644 git.zig\x00" ++ .{0xb2,0x29,0xea,0xdb,0xd5,0xd6,0x65,0x5c,0x2d,0xfb,0xac,0xa5,0xa5,0xf6,0x8f,0x2f,0x8f,0x3c,0x54,0x54} ++ |
| 121 | "100644 zig.mod\x00" ++ .{0xbb,0x3f,0x1c,0x13,0x56,0x32,0xcf,0xca,0x76,0x0b,0xd8,0x4f,0xb1,0x8a,0xcd,0xab,0x8d,0xae,0x8e,0xc3} ++ |
| 108 | 122 | "" |
| 109 | 123 | // zig fmt: on |
| 110 | 124 | ); |
| 111 | 125 | } |
| 112 | 126 | |
| 113 | 127 | test { |
| 128 | const gpa = std.testing.allocator; |
| 114 | 129 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 115 | 130 | defer arena.deinit(); |
| 116 | 131 | const alloc = arena.allocator(); |
| 117 | 132 | const git_dir = try nfs.cwd().openDir(".git", .{}); |
| 118 | 133 | defer git_dir.close(); |
| 119 | | const t = try git.parseTree(alloc, try git.getObjectContent(alloc, git_dir, "5403fecad0fde9120535321f222a061abc2849d9")); |
| 134 | var repo: git.Repository = .init(git_dir, gpa); |
| 135 | defer repo.deinit(); |
| 136 | const t = try repo.getTreeA(alloc, "5403fecad0fde9120535321f222a061abc2849d9"); |
| 120 | 137 | // TODO: test fields when we upgrade to 0.14 and have decl literals |
| 121 | 138 | // try expect(try extras.mapBy(alloc, t.children, .id)).toEqualSlice(&.{ |
| 122 | 139 | // .{ .blob = .{ .id = "8e8d2ceba4b327ce9db93f988492d0e21a461012" } }, |