History

feat: `CommitRefIter::(author|committer)()`, better usability (#364)

The methods returning an iterator are now consuming, which allows them to be nested by callers.

Sebastian Thiel committed 4 years ago

Commit c51a9251 parent 91065cd2 files · +41 −20Browse files

Showing the changes to git-object/tests/immutable/commit (1 of 2 files). Show all

Unified · Split

git-object/tests/immutable/commit/iter.rs+23−20
@@ -24,9 +24,10 @@ fn newline_right_after_signature_multiline_header() -> crate::Result { · 23 unmodified lines
2424
2525 #[test]
2626 fn signed_with_encoding() -> crate::Result {
27+ let input = fixture_bytes("commit", "signed-with-encoding.txt");
28+ let mut iter = CommitRefIter::from_bytes(&input);
2729 assert_eq!(
28− CommitRefIter::from_bytes(&fixture_bytes("commit", "signed-with-encoding.txt"))
29− .collect::<Result<Vec<_>, _>>()?,
30+ iter.collect::<Result<Vec<_>, _>>()?,
3031 vec![
3132 Token::Tree {
3233 id: hex_to_id("1973afa74d87b2bb73fa884aaaa8752aec43ea88")
@@ -45,6 +46,9 @@ fn signed_with_encoding() -> crate::Result { · 12 unmodified lines
4546 Token::Message(b"encoding & sig".as_bstr()),
4647 ]
4748 );
49+
50+ assert_eq!(iter.author(), Some(signature(1592448995)));
51+ assert_eq!(iter.committer(), Some(signature(1592449083)));
4852 Ok(())
4953 }
5054
@@ -135,8 +139,10 @@ fn error_handling() -> crate::Result { · 84 unmodified lines
135139
136140 #[test]
137141 fn mergetag() -> crate::Result {
142+ let input = fixture_bytes("commit", "mergetag.txt");
143+ let mut iter = CommitRefIter::from_bytes(&input);
138144 assert_eq!(
139− CommitRefIter::from_bytes(&fixture_bytes("commit", "mergetag.txt")).collect::<Result<Vec<_>, _>>()?,
145+ iter.collect::<Result<Vec<_>, _>>()?,
140146 vec![
141147 Token::Tree {
142148 id: hex_to_id("1c61918031bf2c7fab9e17dde3c52a6a9884fcb5")
@@ -154,18 +160,17 @@ fn mergetag() -> crate::Result { · 11 unmodified lines
154160 signature: linus_signature(1591996221)
155161 },
156162 Token::ExtraHeader((b"mergetag".as_bstr(), MERGE_TAG.as_bytes().as_bstr().into())),
157− Token::Message(LONG_MESSAGE.as_bytes().as_bstr()),
163+ Token::Message(LONG_MESSAGE.into()),
158164 ]
159165 );
160166 assert_eq!(
161− CommitRefIter::from_bytes(&fixture_bytes("commit", "mergetag.txt"))
162− .parent_ids()
163− .collect::<Vec<_>>(),
167+ iter.parent_ids().collect::<Vec<_>>(),
164168 vec![
165169 hex_to_id("44ebe016df3aad96e3be8f95ec52397728dd7701"),
166170 hex_to_id("8d485da0ddee79d0e6713405694253d401e41b93")
167171 ]
168172 );
173+ assert_eq!(iter.message(), Some(LONG_MESSAGE.into()));
169174 Ok(())
170175 }
171176
@@ -179,33 +184,31 @@ mod method { · 7 unmodified lines
179184
180185 #[test]
181186 fn tree_id() -> crate::Result {
187+ let input = fixture_bytes("commit", "unsigned.txt");
188+ let iter = CommitRefIter::from_bytes(&input);
182189 assert_eq!(
183− CommitRefIter::from_bytes(&fixture_bytes("commit", "unsigned.txt")).tree_id(),
190+ iter.clone().tree_id(),
184191 Some(hex_to_id("1b2dfb4ac5e42080b682fc676e9738c94ce6d54d"))
185192 );
186193 assert_eq!(
187− CommitRefIter::from_bytes(&fixture_bytes("commit", "unsigned.txt"))
188− .signatures()
189− .collect::<Vec<_>>(),
194+ iter.signatures().collect::<Vec<_>>(),
190195 vec![signature(1592437401), signature(1592437401)]
191196 );
192− assert_eq!(
193− CommitRefIter::from_bytes(&fixture_bytes("commit", "unsigned.txt"))
194− .parent_ids()
195− .count(),
196− 0
197− );
197+ assert_eq!(iter.parent_ids().count(), 0);
198198 Ok(())
199199 }
200200
201201 #[test]
202202 fn signatures() -> crate::Result {
203+ let input = fixture_bytes("commit", "unsigned.txt");
204+ let mut iter = CommitRefIter::from_bytes(&input);
203205 assert_eq!(
204− CommitRefIter::from_bytes(&fixture_bytes("commit", "unsigned.txt"))
205− .signatures()
206− .collect::<Vec<_>>(),
206+ iter.signatures().collect::<Vec<_>>(),
207207 vec![signature(1592437401), signature(1592437401)]
208208 );
209+ assert_eq!(iter.author(), Some(signature(1592437401)));
210+ assert_eq!(iter.committer(), Some(signature(1592437401)));
211+ assert_eq!(iter.committer(), None, "it's consuming");
209212 Ok(())
210213 }
211214 }