Skip to content

Commit b69d6d6

Browse files
committed
[pack-gen] more tests for Tag iterator
1 parent df5ef8a commit b69d6d6

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed

git-object/src/immutable/tag.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ pub struct Tag<'a> {
2020
/// The hash in hexadecimal being the object this tag points to. Use [`target()`][Tag::target()] to obtain a byte representation.
2121
#[cfg_attr(feature = "serde1", serde(borrow))]
2222
pub target: &'a BStr,
23-
/// The name of the tag, e.g. "v1.0".
24-
pub name: &'a BStr,
2523
/// The kind of object that `target` points to.
2624
pub target_kind: crate::Kind,
27-
/// The message describing this release.
28-
pub message: &'a BStr,
25+
/// The name of the tag, e.g. "v1.0".
26+
pub name: &'a BStr,
2927
/// The author of the tag.
3028
pub tagger: Option<Signature<'a>>,
29+
/// The message describing this release.
30+
pub message: &'a BStr,
3131
/// A cryptographic signature over the entire content of the serialized tag object thus far.
3232
pub pgp_signature: Option<&'a BStr>,
3333
}

git-object/tests/immutable/tag.rs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod method {
1010
use pretty_assertions::assert_eq;
1111

1212
#[test]
13-
fn target() -> Result<(), Box<dyn std::error::Error>> {
13+
fn target() -> crate::Result {
1414
let fixture = fixture_bytes("tag", "signed.txt");
1515
let tag = Tag::from_bytes(&fixture)?;
1616
assert_eq!(tag.target(), hex_to_id("ffa700b4aca13b80cb6b98a078e7c96804f8e0ec"));
@@ -28,7 +28,7 @@ mod iter {
2828
};
2929

3030
#[test]
31-
fn empty() -> Result<(), Box<dyn std::error::Error>> {
31+
fn empty() -> crate::Result {
3232
assert_eq!(
3333
TagIter::from_bytes(&fixture_bytes("tag", "empty.txt")).collect::<Result<Vec<_>, _>>()?,
3434
vec![
@@ -43,6 +43,62 @@ mod iter {
4343
Ok(())
4444
}
4545

46+
#[test]
47+
fn no_tagger() -> crate::Result {
48+
assert_eq!(
49+
TagIter::from_bytes(&fixture_bytes("tag", "no-tagger.txt")).collect::<Result<Vec<_>, _>>()?,
50+
vec![
51+
Token::Target {
52+
id: hex_to_id("c39ae07f393806ccf406ef966e9a15afc43cc36a")
53+
},
54+
Token::TargetKind(Kind::Tree),
55+
Token::Name(b"v2.6.11-tree".as_bstr()),
56+
Token::Tagger(None),
57+
Token::Body {
58+
message: b"This is the 2.6.11 tree object.
59+
60+
NOTE! There's no commit for this, since it happened before I started with git.
61+
Eventually we'll import some sort of history, and that should tie this tree
62+
object up to a real commit. In the meantime, this acts as an anchor point for
63+
doing diffs etc under git."
64+
.as_bstr(),
65+
pgp_signature: Some(
66+
b"-----BEGIN PGP SIGNATURE-----
67+
Version: GnuPG v1.2.4 (GNU/Linux)
68+
69+
iD8DBQBCeV/eF3YsRnbiHLsRAl+SAKCVp8lVXwpUhMEvy8N5jVBd16UCmACeOtP6
70+
KLMHist5yj0sw1E4hDTyQa0=
71+
=/bIK
72+
-----END PGP SIGNATURE-----
73+
"
74+
.as_bstr()
75+
)
76+
}
77+
]
78+
);
79+
Ok(())
80+
}
81+
82+
#[test]
83+
fn whitespace() -> crate::Result {
84+
assert_eq!(
85+
TagIter::from_bytes(&fixture_bytes("tag", "whitespace.txt")).collect::<Result<Vec<_>, _>>()?,
86+
vec![
87+
Token::Target {
88+
id: hex_to_id("01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc")
89+
},
90+
Token::TargetKind(Kind::Commit),
91+
Token::Name(b"whitespace".as_bstr()),
92+
Token::Tagger(Some(signature(1592382888))),
93+
Token::Body {
94+
message: b" \ttab\nnewline\n\nlast-with-trailer\n".as_bstr(),
95+
pgp_signature: None
96+
}
97+
]
98+
);
99+
Ok(())
100+
}
101+
46102
#[test]
47103
fn error_handling() -> crate::Result {
48104
let data = fixture_bytes("tag", "empty.txt");
@@ -61,13 +117,13 @@ mod from_bytes {
61117
use git_object::{bstr::ByteSlice, immutable::Tag, Kind};
62118

63119
#[test]
64-
fn signed() -> Result<(), Box<dyn std::error::Error>> {
120+
fn signed() -> crate::Result {
65121
assert_eq!(Tag::from_bytes(&fixture_bytes("tag", "signed.txt"))?, tag_fixture(9000));
66122
Ok(())
67123
}
68124

69125
#[test]
70-
fn empty() -> Result<(), Box<dyn std::error::Error>> {
126+
fn empty() -> crate::Result {
71127
assert_eq!(
72128
Tag::from_bytes(&fixture_bytes("tag", "empty.txt"))?,
73129
Tag {
@@ -83,7 +139,7 @@ mod from_bytes {
83139
}
84140

85141
#[test]
86-
fn with_newlines() -> Result<(), Box<dyn std::error::Error>> {
142+
fn with_newlines() -> crate::Result {
87143
assert_eq!(
88144
Tag::from_bytes(&fixture_bytes("tag", "with-newlines.txt"))?,
89145
Tag {
@@ -99,7 +155,7 @@ mod from_bytes {
99155
}
100156

101157
#[test]
102-
fn no_tagger() -> Result<(), Box<dyn std::error::Error>> {
158+
fn no_tagger() -> crate::Result {
103159
assert_eq!(
104160
Tag::from_bytes(&fixture_bytes("tag", "no-tagger.txt"))?,
105161
Tag {
@@ -131,14 +187,14 @@ KLMHist5yj0sw1E4hDTyQa0=
131187
}
132188

133189
#[test]
134-
fn whitespace() -> Result<(), Box<dyn std::error::Error>> {
190+
fn whitespace() -> crate::Result {
135191
assert_eq!(
136192
Tag::from_bytes(&fixture_bytes("tag", "whitespace.txt"))?,
137193
Tag {
138194
target: b"01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc".as_bstr(),
139195
name: b"whitespace".as_bstr(),
140196
target_kind: Kind::Commit,
141-
message: b" \ttab\nnewline\n\nlast-with-trailer\n".as_bstr(), // odd, was created with \n\n actually
197+
message: b" \ttab\nnewline\n\nlast-with-trailer\n".as_bstr(),
142198
tagger: Some(signature(1592382888)),
143199
pgp_signature: None
144200
}

0 commit comments

Comments
 (0)