#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TitleCategory {
Component,
Monograph,
Periodical,
Serial,
ContainerMonograph,
Default,
}
#[must_use]
pub fn title_category(ref_type: &str) -> TitleCategory {
match ref_type {
"article-journal" | "article-magazine" | "article-newspaper" | "chapter" | "entry"
| "entry-dictionary" | "entry-encyclopedia" | "paper-conference" | "post"
| "post-weblog" => TitleCategory::Component,
"book" | "thesis" | "report" => TitleCategory::Monograph,
_ => TitleCategory::Default,
}
}
#[must_use]
pub fn container_title_category(ref_type: &str) -> TitleCategory {
match ref_type {
"article-journal" | "article-magazine" | "article-newspaper" | "broadcast" => {
TitleCategory::Periodical
}
"chapter" | "paper-conference" => TitleCategory::ContainerMonograph,
_ => TitleCategory::Default,
}
}
#[must_use]
pub fn parent_serial_title_category(ref_type: &str) -> TitleCategory {
match ref_type {
"article-journal" | "article-magazine" | "article-newspaper" => TitleCategory::Periodical,
_ => TitleCategory::Serial,
}
}
#[must_use]
pub fn classified_ref_types() -> &'static [&'static str] {
&[
"article-journal",
"article-magazine",
"article-newspaper",
"chapter",
"entry",
"entry-dictionary",
"entry-encyclopedia",
"paper-conference",
"post",
"post-weblog",
"book",
"thesis",
"report",
"broadcast",
]
}
#[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_component_ref_type_when_title_category_then_component() {
let category = title_category("chapter");
assert_eq!(category, TitleCategory::Component);
}
#[test]
fn given_monograph_ref_type_when_title_category_then_monograph() {
let category = title_category("book");
assert_eq!(category, TitleCategory::Monograph);
}
#[test]
fn given_unclassified_ref_type_when_title_category_then_default() {
let category = title_category("dataset");
assert_eq!(category, TitleCategory::Default);
}
#[test]
fn given_periodical_ref_type_when_container_title_category_then_periodical() {
let category = container_title_category("article-journal");
assert_eq!(category, TitleCategory::Periodical);
}
#[test]
fn given_chapter_ref_type_when_container_title_category_then_container_monograph() {
let category = container_title_category("chapter");
assert_eq!(category, TitleCategory::ContainerMonograph);
}
#[test]
fn given_journal_article_when_parent_serial_title_category_then_periodical() {
let category = parent_serial_title_category("article-journal");
assert_eq!(category, TitleCategory::Periodical);
}
#[test]
fn given_book_when_parent_serial_title_category_then_serial() {
let category = parent_serial_title_category("book");
assert_eq!(category, TitleCategory::Serial);
}
#[test]
fn given_broadcast_when_parent_serial_title_category_then_serial_not_periodical() {
let category = parent_serial_title_category("broadcast");
assert_eq!(category, TitleCategory::Serial);
}
#[test]
fn given_classified_ref_types_when_categorized_then_none_panic() {
for ref_type in classified_ref_types() {
let _ = title_category(ref_type);
let _ = container_title_category(ref_type);
let _ = parent_serial_title_category(ref_type);
}
}
}