From 5d0628e6a6958b4695e3b2f50ae29f602d0a1db2 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 31 Dec 2023 13:15:16 -0800 Subject: [PATCH] tree: tests: Test `TreeIter::nth` --- src/tree.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/tree.rs b/src/tree.rs index a9ddca0802..916cf83c5f 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -482,6 +482,24 @@ mod tests { } } + #[test] + fn smoke_tree_nth() { + let (td, repo) = crate::test::repo_init(); + + setup_repo(&td, &repo); + + let head = repo.head().unwrap(); + let target = head.target().unwrap(); + let commit = repo.find_commit(target).unwrap(); + + let tree = repo.find_tree(commit.tree_id()).unwrap(); + assert_eq!(tree.id(), commit.tree_id()); + assert_eq!(tree.len(), 8); + let mut it = tree.iter(); + let e = it.nth(4).unwrap(); + assert_eq!(e.name(), Some("f4")); + } + fn setup_repo(td: &TempDir, repo: &Repository) { let mut index = repo.index().unwrap(); for n in 0..8 {