The methods returning an iterator are now consuming, which allows them to be nested by callers.
Showing the changes to git-object/tests/immutable/commit (1 of 2 files). Show all
Unified · Split
| @@ -24,9 +24,10 @@ fn newline_right_after_signature_multiline_header() -> crate::Result { · 23 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | #[test] |
| 26 | 26 | fn signed_with_encoding() -> crate::Result { |
| 27 | + let input = fixture_bytes("commit", "signed-with-encoding.txt"); | |
| 28 | + let mut iter = CommitRefIter::from_bytes(&input); | |
| 27 | 29 | assert_eq!( |
| 28 | − CommitRefIter::from_bytes(&fixture_bytes("commit", "signed-with-encoding.txt")) | |
| 29 | − .collect::<Result<Vec<_>, _>>()?, | |
| 30 | + iter.collect::<Result<Vec<_>, _>>()?, | |
| 30 | 31 | vec![ |
| 31 | 32 | Token::Tree { |
| 32 | 33 | id: hex_to_id("1973afa74d87b2bb73fa884aaaa8752aec43ea88") |
| @@ -45,6 +46,9 @@ fn signed_with_encoding() -> crate::Result { · 12 unmodified lines | ||
| 45 | 46 | Token::Message(b"encoding & sig".as_bstr()), |
| 46 | 47 | ] |
| 47 | 48 | ); |
| 49 | + | |
| 50 | + assert_eq!(iter.author(), Some(signature(1592448995))); | |
| 51 | + assert_eq!(iter.committer(), Some(signature(1592449083))); | |
| 48 | 52 | Ok(()) |
| 49 | 53 | } |
| 50 | 54 | |
| @@ -135,8 +139,10 @@ fn error_handling() -> crate::Result { · 84 unmodified lines | ||
| 135 | 139 | |
| 136 | 140 | #[test] |
| 137 | 141 | fn mergetag() -> crate::Result { |
| 142 | + let input = fixture_bytes("commit", "mergetag.txt"); | |
| 143 | + let mut iter = CommitRefIter::from_bytes(&input); | |
| 138 | 144 | assert_eq!( |
| 139 | − CommitRefIter::from_bytes(&fixture_bytes("commit", "mergetag.txt")).collect::<Result<Vec<_>, _>>()?, | |
| 145 | + iter.collect::<Result<Vec<_>, _>>()?, | |
| 140 | 146 | vec![ |
| 141 | 147 | Token::Tree { |
| 142 | 148 | id: hex_to_id("1c61918031bf2c7fab9e17dde3c52a6a9884fcb5") |
| @@ -154,18 +160,17 @@ fn mergetag() -> crate::Result { · 11 unmodified lines | ||
| 154 | 160 | signature: linus_signature(1591996221) |
| 155 | 161 | }, |
| 156 | 162 | 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()), | |
| 158 | 164 | ] |
| 159 | 165 | ); |
| 160 | 166 | assert_eq!( |
| 161 | − CommitRefIter::from_bytes(&fixture_bytes("commit", "mergetag.txt")) | |
| 162 | − .parent_ids() | |
| 163 | − .collect::<Vec<_>>(), | |
| 167 | + iter.parent_ids().collect::<Vec<_>>(), | |
| 164 | 168 | vec![ |
| 165 | 169 | hex_to_id("44ebe016df3aad96e3be8f95ec52397728dd7701"), |
| 166 | 170 | hex_to_id("8d485da0ddee79d0e6713405694253d401e41b93") |
| 167 | 171 | ] |
| 168 | 172 | ); |
| 173 | + assert_eq!(iter.message(), Some(LONG_MESSAGE.into())); | |
| 169 | 174 | Ok(()) |
| 170 | 175 | } |
| 171 | 176 | |
| @@ -179,33 +184,31 @@ mod method { · 7 unmodified lines | ||
| 179 | 184 | |
| 180 | 185 | #[test] |
| 181 | 186 | fn tree_id() -> crate::Result { |
| 187 | + let input = fixture_bytes("commit", "unsigned.txt"); | |
| 188 | + let iter = CommitRefIter::from_bytes(&input); | |
| 182 | 189 | assert_eq!( |
| 183 | − CommitRefIter::from_bytes(&fixture_bytes("commit", "unsigned.txt")).tree_id(), | |
| 190 | + iter.clone().tree_id(), | |
| 184 | 191 | Some(hex_to_id("1b2dfb4ac5e42080b682fc676e9738c94ce6d54d")) |
| 185 | 192 | ); |
| 186 | 193 | assert_eq!( |
| 187 | − CommitRefIter::from_bytes(&fixture_bytes("commit", "unsigned.txt")) | |
| 188 | − .signatures() | |
| 189 | − .collect::<Vec<_>>(), | |
| 194 | + iter.signatures().collect::<Vec<_>>(), | |
| 190 | 195 | vec![signature(1592437401), signature(1592437401)] |
| 191 | 196 | ); |
| 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); | |
| 198 | 198 | Ok(()) |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | #[test] |
| 202 | 202 | fn signatures() -> crate::Result { |
| 203 | + let input = fixture_bytes("commit", "unsigned.txt"); | |
| 204 | + let mut iter = CommitRefIter::from_bytes(&input); | |
| 203 | 205 | assert_eq!( |
| 204 | − CommitRefIter::from_bytes(&fixture_bytes("commit", "unsigned.txt")) | |
| 205 | − .signatures() | |
| 206 | − .collect::<Vec<_>>(), | |
| 206 | + iter.signatures().collect::<Vec<_>>(), | |
| 207 | 207 | vec![signature(1592437401), signature(1592437401)] |
| 208 | 208 | ); |
| 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"); | |
| 209 | 212 | Ok(()) |
| 210 | 213 | } |
| 211 | 214 | } |