Skip to content

Commit

Permalink
Add Bibliography::keys (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
PgBiel authored Sep 30, 2024
1 parent f1067e2 commit 06d0c2b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ impl Bibliography {
self.entries.iter_mut()
}

/// An iterator over the bibliography's entry keys.
pub fn keys(&self) -> impl Iterator<Item = &str> {
self.entries.iter().map(|entry| &*entry.key)
}

/// Consume this struct and return a vector of the bibliography's entries.
pub fn into_vec(self) -> Vec<Entry> {
self.entries
Expand Down Expand Up @@ -1001,6 +1006,18 @@ mod tests {
};
}

#[test]
fn test_keys() {
let contents = fs::read_to_string("tests/editortypes.bib").unwrap();

let bibliography = Bibliography::parse(&contents).unwrap();

assert_eq!(
bibliography.keys().collect::<Vec<_>>(),
&["acerolaThisDifferenceGaussians2022", "mozart_KV183_1773", "Smith2018"]
);
}

#[test]
fn test_gral_paper() {
dump_debug("tests/gral.bib");
Expand Down

0 comments on commit 06d0c2b

Please sign in to comment.