mod gen;
pub use gen::*;
#[cfg(test)]
mod test {
use super::*;
use serde_json;
use url::Url;
use chrono::prelude::*;
#[test]
fn builder() {
let agent: vf::Agent = vf::Agent::builder()
.name("Andrew")
.note(Some("His hands are big".into()))
.build().unwrap();
assert_eq!(agent.name(), "Andrew");
assert_eq!(agent.note(), &Some("His hands are big".to_string()));
assert_eq!(agent.image(), &None);
}
#[cfg(feature = "into_builder")]
#[test]
fn into_builder() {
let agent: vf::Agent = vf::Agent::builder()
.name("Andrew")
.note(Some("His hands are big".into()))
.build().unwrap();
let agent_builder = agent.clone().into_builder();
let agent2 = agent_builder.build().unwrap();
assert_eq!(agent, agent2);
let agent3 = agent.clone().into_builder()
.name("LARRY".to_string())
.build().unwrap();
assert!(agent2 != agent3);
}
#[test]
fn builder_throws_on_incomplete_struct() {
let res: Result<vf::EconomicResource<Url, String, String, String, String>, String> = vf::EconomicResource::builder()
.name(Some("hi my name is butch".into()))
.build();
match res {
Ok(_) => panic!("Builder did not throw on missing required field"),
Err(_) => {}
}
}
#[test]
fn builder_setter_into() {
let agent: vf::Agent = vf::Agent::builder()
.name("Andrew".to_string())
.build().unwrap();
assert_eq!(agent.name(), "Andrew");
let agent: vf::Agent = vf::Agent::builder()
.name("Andrew")
.build().unwrap();
assert_eq!(agent.name(), "Andrew");
}
#[cfg(feature = "with_serde")]
#[test]
fn serializes() {
let location = geo::SpatialThing::builder()
.name(Some("https://basisproject.gitlab.io/public/".into()))
.build().unwrap();
let agent: vf::Agent = vf::Agent::builder()
.image("https://basisproject.gitlab.io/public/assets/images/red_star.256.outline.png".parse::<Url>().unwrap())
.name("Basis")
.primary_location(location)
.build().unwrap();
let json = serde_json::to_string(&agent).unwrap();
assert_eq!(json, r#"{"image":"https://basisproject.gitlab.io/public/assets/images/red_star.256.outline.png","name":"Basis","primary_location":{"name":"https://basisproject.gitlab.io/public/"}}"#);
}
#[cfg(feature = "with_serde")]
#[test]
fn deserializes() {
let json = r#"{"image":"https://basisproject.gitlab.io/public/assets/images/red_star.256.outline.png","name":"Basis","primary_location":{"name":"https://basisproject.gitlab.io/public/"}}"#;
let agent: vf::Agent = serde_json::from_str(json).unwrap();
let location = agent.primary_location().as_ref().unwrap();
assert_eq!(agent.image(), &Some("https://basisproject.gitlab.io/public/assets/images/red_star.256.outline.png".parse::<Url>().unwrap()));
assert_eq!(agent.name(), "Basis");
assert_eq!(agent.note(), &None);
assert_eq!(location.name(), &Some("https://basisproject.gitlab.io/public/".into()));
}
#[cfg(feature = "getset_setters")]
#[test]
fn getset_setters() {
let mut plan = vf::Plan::builder()
.created("2018-04-01T00:01:01Z".parse::<DateTime<Utc>>().unwrap())
.name("GOSHPLAN".to_string())
.build().unwrap();
assert_eq!(plan.name(), &Some("GOSHPLAN".to_string()));
plan.set_name(Some("Gffft".into()));
assert_eq!(plan.name(), &Some("Gffft".to_string()));
}
#[cfg(feature = "getset_getmut")]
#[test]
fn getset_getmut() {
let mut plan = vf::Plan::builder()
.created("2018-04-01T00:01:01Z".parse::<DateTime<Utc>>().unwrap())
.name("GOSHPLAN".to_string())
.build().unwrap();
assert_eq!(plan.name(), &Some("GOSHPLAN".to_string()));
(*plan.name_mut()) = Some("Gffft".into());
assert_eq!(plan.name(), &Some("Gffft".to_string()));
}
}