use citum_schema::options::TypeClass;
pub(crate) use citum_schema::options::{
TitleCategory, container_title_category, parent_serial_title_category, title_category,
};
#[must_use]
pub(crate) fn is_serial_parent_type(ref_type: &str) -> bool {
matches!(
ref_type,
"article-journal" | "article-magazine" | "article-newspaper" | "broadcast"
)
}
#[must_use]
pub(crate) fn matches_type_class(ref_type: &str, type_class: TypeClass) -> bool {
match type_class {
TypeClass::Legal => matches!(
ref_type,
"legal-case"
| "legal_case"
| "statute"
| "treaty"
| "regulation"
| "bill"
| "legislation"
),
TypeClass::Classical => matches!(ref_type, "classic" | "religious-text" | "religious_text"),
TypeClass::Standard => true,
}
}
#[must_use]
pub(crate) fn type_selector_aliases(ref_type: &str) -> Vec<&str> {
match ref_type {
"chapter" => vec!["chapter", "entry-dictionary"],
_ => vec![ref_type],
}
}
#[must_use]
pub(crate) fn synthesizes_doi_url(ref_type: &str) -> bool {
ref_type == "dataset"
}
#[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 given_journal_article_when_is_serial_parent_type_then_true() {
assert!(is_serial_parent_type("article-journal"));
}
#[test]
fn given_broadcast_when_is_serial_parent_type_then_true() {
assert!(is_serial_parent_type("broadcast"));
}
#[test]
fn given_book_when_is_serial_parent_type_then_false() {
assert!(!is_serial_parent_type("book"));
}
#[test]
fn given_legal_case_when_matches_legal_type_class_then_true() {
assert!(matches_type_class("legal-case", TypeClass::Legal));
}
#[test]
fn given_classic_when_matches_classical_type_class_then_true() {
assert!(matches_type_class("classic", TypeClass::Classical));
}
#[test]
fn given_classic_ref_type_when_checked_for_ancient_substring_then_absent() {
assert!(!"classic".contains("ancient"));
}
#[test]
fn given_book_when_matches_classical_type_class_then_false() {
assert!(!matches_type_class("book", TypeClass::Classical));
}
#[test]
fn given_any_ref_type_when_matches_standard_type_class_then_true() {
assert!(matches_type_class("anything", TypeClass::Standard));
}
#[test]
fn given_chapter_when_type_selector_aliases_then_includes_entry_dictionary() {
let aliases = type_selector_aliases("chapter");
assert_eq!(aliases, vec!["chapter", "entry-dictionary"]);
}
#[test]
fn given_book_when_type_selector_aliases_then_only_itself() {
let aliases = type_selector_aliases("book");
assert_eq!(aliases, vec!["book"]);
}
#[test]
fn given_dataset_when_synthesizes_doi_url_then_true() {
assert!(synthesizes_doi_url("dataset"));
}
#[test]
fn given_book_when_synthesizes_doi_url_then_false() {
assert!(!synthesizes_doi_url("book"));
}
}