Skip to main content

citum_engine/
reference.rs

1/*
2SPDX-License-Identifier: MIT OR Apache-2.0
3SPDX-FileCopyrightText: © 2023-2026 Bruce D'Arcus and Citum contributors
4*/
5
6//! Reference types for the Citum processor.
7//!
8//! This module re-exports types from `citum_schema` (for citations) and `csl_legacy`
9//! (for CSL-JSON bibliography data) for backward compatibility.
10//!
11//! For new data, prefer using `citum_schema::reference::InputReference` which
12//! provides a more type-safe model with EDTF date support.
13
14// Re-export citation types from citum_schema
15pub use citum_schema::citation::{Citation, CitationItem, CitationMode, LocatorType};
16
17// Re-export reference types from citum_schema
18pub use citum_schema::reference::{
19    Contributor, ContributorList, EdtfString, FlatName, InputReference as Reference,
20    MultilingualString, NumOrStr, SimpleName, StructuredName, Title,
21};
22
23/// A bibliography is a collection of references keyed by ID.
24pub type Bibliography = indexmap::IndexMap<String, Reference>;
25
26#[cfg(test)]
27#[allow(
28    clippy::unwrap_used,
29    clippy::expect_used,
30    clippy::panic,
31    clippy::indexing_slicing,
32    clippy::todo,
33    clippy::unimplemented,
34    clippy::unreachable,
35    clippy::get_unwrap,
36    reason = "Panicking is acceptable and often desired in tests."
37)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_parse_csl_json() {
43        let json = r#"{
44            "id": "kuhn1962",
45            "type": "book",
46            "author": [{"family": "Kuhn", "given": "Thomas S."}],
47            "title": "The Structure of Scientific Revolutions",
48            "issued": {"date-parts": [[1962]]},
49            "publisher": "University of Chicago Press",
50            "publisher-place": "Chicago"
51        }"#;
52
53        let legacy: csl_legacy::csl_json::Reference = serde_json::from_str(json).unwrap();
54        let reference: Reference = legacy.into();
55        assert_eq!(reference.id().unwrap(), "kuhn1962");
56        assert_eq!(reference.ref_type(), "book");
57        // No longer direct access to family on Contributor
58        if let Some(Contributor::ContributorList(list)) = reference.author()
59            && let Contributor::StructuredName(name) = &list.0[0]
60        {
61            assert_eq!(name.family, MultilingualString::Simple("Kuhn".to_string()));
62        }
63    }
64}