#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectRef {
pub iri: String,
pub shortcode: String,
pub shortname: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProjectStatus {
Active,
Inactive,
}
impl ProjectStatus {
pub fn as_str(self) -> &'static str {
match self {
ProjectStatus::Active => "active",
ProjectStatus::Inactive => "inactive",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectDescription {
pub value: String,
pub language: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataModelSummary {
pub name: String,
pub iri: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectDetail {
pub iri: String,
pub shortcode: String,
pub shortname: String,
pub longname: Option<String>,
pub status: ProjectStatus,
pub description: Vec<ProjectDescription>,
pub keywords: Vec<String>,
pub data_models: Vec<DataModelSummary>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Project {
pub iri: String,
pub shortcode: String,
pub shortname: String,
pub longname: Option<String>,
pub status: ProjectStatus,
pub data_models: usize,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn project_ref_construction_and_equality() {
let a = ProjectRef {
iri: "http://rdfh.ch/projects/0001".into(),
shortcode: "0001".into(),
shortname: "anything".into(),
};
let b = a.clone();
assert_eq!(a, b);
assert_eq!(a.iri, "http://rdfh.ch/projects/0001");
assert_eq!(a.shortcode, "0001");
assert_eq!(a.shortname, "anything");
}
#[test]
fn project_status_as_str() {
assert_eq!(ProjectStatus::Active.as_str(), "active");
assert_eq!(ProjectStatus::Inactive.as_str(), "inactive");
}
#[test]
fn project_status_derives() {
let s = ProjectStatus::Active;
let t = s; assert_eq!(s, t);
assert_ne!(ProjectStatus::Active, ProjectStatus::Inactive);
let _ = format!("{s:?}"); }
#[test]
fn project_construction_and_equality() {
let p = Project {
iri: "http://rdfh.ch/projects/0001".into(),
shortcode: "0001".into(),
shortname: "anything".into(),
longname: Some("Anything Project".into()),
status: ProjectStatus::Active,
data_models: 3,
};
let cloned = p.clone();
assert_eq!(p, cloned);
assert_eq!(p.iri, "http://rdfh.ch/projects/0001");
assert_eq!(p.shortcode, "0001");
assert_eq!(p.shortname, "anything");
assert_eq!(p.longname.as_deref(), Some("Anything Project"));
assert_eq!(p.status, ProjectStatus::Active);
assert_eq!(p.data_models, 3);
}
#[test]
fn project_longname_none() {
let p = Project {
iri: "http://rdfh.ch/projects/0002".into(),
shortcode: "0002".into(),
shortname: "images".into(),
longname: None,
status: ProjectStatus::Inactive,
data_models: 0,
};
assert_eq!(p.longname, None);
assert_eq!(p.status, ProjectStatus::Inactive);
assert_eq!(p.data_models, 0);
}
#[test]
fn project_description_with_language() {
let d = ProjectDescription {
value: "<b>Project Metadata</b>".into(),
language: Some("en".into()),
};
let cloned = d.clone();
assert_eq!(d, cloned);
assert_eq!(d.value, "<b>Project Metadata</b>");
assert_eq!(d.language.as_deref(), Some("en"));
}
#[test]
fn project_description_without_language() {
let d = ProjectDescription {
value: "Beschreibung".into(),
language: None,
};
let cloned = d.clone();
assert_eq!(d, cloned);
assert_eq!(d.language, None);
}
#[test]
fn data_model_summary_construction_and_equality() {
let dm = DataModelSummary {
name: "beol".into(),
iri: "http://api.dasch.swiss/ontology/0801/beol/v2".into(),
};
let cloned = dm.clone();
assert_eq!(dm, cloned);
assert_eq!(dm.name, "beol");
assert_eq!(dm.iri, "http://api.dasch.swiss/ontology/0801/beol/v2");
}
#[test]
fn project_detail_construction_and_equality() {
let detail = ProjectDetail {
iri: "http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF".into(),
shortcode: "0801".into(),
shortname: "beol".into(),
longname: Some("Bernoulli-Euler Online".into()),
status: ProjectStatus::Active,
description: vec![ProjectDescription {
value: "<b>Project Metadata</b>".into(),
language: Some("en".into()),
}],
keywords: vec!["Bernoulli".into(), "Condorcet".into(), "Euler".into()],
data_models: vec![
DataModelSummary {
name: "beol".into(),
iri: "http://api.dasch.swiss/ontology/0801/beol/v2".into(),
},
DataModelSummary {
name: "biblio".into(),
iri: "http://api.dasch.swiss/ontology/0801/biblio/v2".into(),
},
],
};
let cloned = detail.clone();
assert_eq!(detail, cloned);
assert_eq!(detail.iri, "http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF");
assert_eq!(detail.shortcode, "0801");
assert_eq!(detail.shortname, "beol");
assert_eq!(detail.longname.as_deref(), Some("Bernoulli-Euler Online"));
assert_eq!(detail.status, ProjectStatus::Active);
assert_eq!(detail.description.len(), 1);
assert_eq!(detail.keywords.len(), 3);
assert_eq!(detail.data_models.len(), 2);
}
#[test]
fn project_detail_empty_case() {
let detail = ProjectDetail {
iri: "http://rdfh.ch/projects/0000".into(),
shortcode: "0000".into(),
shortname: "minimal".into(),
longname: None,
status: ProjectStatus::Inactive,
description: vec![],
keywords: vec![],
data_models: vec![],
};
assert_eq!(detail.longname, None);
assert!(detail.description.is_empty());
assert!(detail.keywords.is_empty());
assert!(detail.data_models.is_empty());
assert_eq!(detail.status, ProjectStatus::Inactive);
}
}