citum-engine 0.64.0

Citum citation and bibliography processor
Documentation
/*
SPDX-License-Identifier: MIT OR Apache-2.0
SPDX-FileCopyrightText: © 2023-2026 Bruce D'Arcus and Citum contributors
*/

//! Reference types for the Citum processor.
//!
//! This module re-exports types from `citum_schema` (for citations) and `csl_legacy`
//! (for CSL-JSON bibliography data) for backward compatibility.
//!
//! For new data, prefer using `citum_schema::reference::InputReference` which
//! provides a more type-safe model with EDTF date support.

// Re-export citation types from citum_schema
pub use citum_schema::citation::{Citation, CitationItem, CitationMode, LocatorType};

// Re-export reference types from citum_schema
pub use citum_schema::reference::{
    Contributor, ContributorList, EdtfString, FlatName, InputReference as Reference,
    MultilingualString, NumOrStr, SimpleName, StructuredName, Title,
};

/// A bibliography is a collection of references keyed by ID.
pub type Bibliography = indexmap::IndexMap<String, Reference>;

#[cfg(test)]
#[allow(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::panic,
    clippy::indexing_slicing,
    clippy::todo,
    clippy::unimplemented,
    clippy::unreachable,
    clippy::get_unwrap,
    reason = "Panicking is acceptable and often desired in tests."
)]
mod tests {
    use super::*;

    #[test]
    fn test_parse_csl_json() {
        let json = r#"{
            "id": "kuhn1962",
            "type": "book",
            "author": [{"family": "Kuhn", "given": "Thomas S."}],
            "title": "The Structure of Scientific Revolutions",
            "issued": {"date-parts": [[1962]]},
            "publisher": "University of Chicago Press",
            "publisher-place": "Chicago"
        }"#;

        let legacy: csl_legacy::csl_json::Reference = serde_json::from_str(json).unwrap();
        let reference: Reference = legacy.into();
        assert_eq!(reference.id().unwrap(), "kuhn1962");
        assert_eq!(reference.ref_type(), "book");
        // No longer direct access to family on Contributor
        if let Some(Contributor::ContributorList(list)) = reference.author()
            && let Contributor::StructuredName(name) = &list.0[0]
        {
            assert_eq!(name.family, MultilingualString::Simple("Kuhn".to_string()));
        }
    }
}