Skip to content

Commit 2101df3

Browse files
committed
refactor
1 parent a849da8 commit 2101df3

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

gix-object/tests/encode/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,26 @@ mod blob {
9595
// It doesn't matter which data we use - it's not interpreted.
9696
round_trip!(gix_object::Blob, gix_object::BlobRef, "tree/everything.tree");
9797
}
98+
99+
mod loose_header {
100+
use bstr::ByteSlice;
101+
use gix_object::{decode, encode, Kind};
102+
103+
#[test]
104+
fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
105+
for (kind, size, expected) in &[
106+
(Kind::Tree, 1234, "tree 1234\0".as_bytes()),
107+
(Kind::Blob, 0, b"blob 0\0"),
108+
(Kind::Commit, 24241, b"commit 24241\0"),
109+
(Kind::Tag, 9999999999, b"tag 9999999999\0"),
110+
] {
111+
let buf = encode::loose_header(*kind, *size);
112+
assert_eq!(buf.as_bstr(), expected.as_bstr());
113+
let (actual_kind, actual_size, actual_read) = decode::loose_header(&buf)?;
114+
assert_eq!(actual_kind, *kind);
115+
assert_eq!(actual_size, *size);
116+
assert_eq!(actual_read, buf.len());
117+
}
118+
Ok(())
119+
}
120+
}

gix-object/tests/loose/mod.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

gix-object/tests/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gix_hash::ObjectId;
44

55
mod encode;
66
mod immutable;
7-
mod loose;
7+
mod object_ref;
88

99
#[test]
1010
fn compute_hash() {

gix-object/tests/object_ref/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mod from_loose {
2+
use gix_object::ObjectRef;
3+
4+
#[test]
5+
fn shorter_than_advertised() {
6+
assert_eq!(
7+
ObjectRef::from_loose(b"tree 1000\x00").unwrap_err().to_string(),
8+
"object data was shorter than its size declared in the header"
9+
);
10+
}
11+
}

0 commit comments

Comments
 (0)