diff options
| author | Christian Cleberg <[email protected]> | 2026-03-18 19:28:42 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-03-18 19:28:42 -0500 |
| commit | bb8fae4d1145266de4f5117a3b8c48f2ccacb0be (patch) | |
| tree | 2b4ce5b2a114c5df60aa20db07ad1d38f426e59d /HutchTests/GitObjectTests.swift | |
| parent | e07b4a28d6ac6086e5b652f72b9089e4d06f7e80 (diff) | |
| download | hutch-bb8fae4d1145266de4f5117a3b8c48f2ccacb0be.tar.gz hutch-bb8fae4d1145266de4f5117a3b8c48f2ccacb0be.tar.bz2 hutch-bb8fae4d1145266de4f5117a3b8c48f2ccacb0be.zip | |
lazily load file blobs from repository tree views
Diffstat (limited to 'HutchTests/GitObjectTests.swift')
| -rw-r--r-- | HutchTests/GitObjectTests.swift | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/HutchTests/GitObjectTests.swift b/HutchTests/GitObjectTests.swift new file mode 100644 index 0000000..547c6f3 --- /dev/null +++ b/HutchTests/GitObjectTests.swift @@ -0,0 +1,40 @@ +import Foundation +import Testing +@testable import Hutch + +struct GitObjectTests { + + @Test + @MainActor + func decodesMetadataOnlyTextBlobUsingTypename() throws { + let data = Data(#"{"type":"BLOB","__typename":"TextBlob","id":"blob123","shortId":"blob123","size":42}"#.utf8) + + let blob = try JSONDecoder().decode(GitObject.self, from: data) + + guard case .textBlob(let textBlob) = blob else { + Issue.record("Expected metadata-only blob to decode as text blob.") + return + } + + #expect(textBlob.id == "blob123") + #expect(textBlob.size == 42) + #expect(textBlob.text == nil) + } + + @Test + @MainActor + func decodesMetadataOnlyBinaryBlobUsingTypename() throws { + let data = Data(#"{"type":"BLOB","__typename":"BinaryBlob","id":"blob456","shortId":"blob456","size":64}"#.utf8) + + let blob = try JSONDecoder().decode(GitObject.self, from: data) + + guard case .binaryBlob(let binaryBlob) = blob else { + Issue.record("Expected metadata-only blob to decode as binary blob.") + return + } + + #expect(binaryBlob.id == "blob456") + #expect(binaryBlob.size == 64) + #expect(binaryBlob.content == nil) + } +} |
