diff --git a/01.workspace/heave/src/lib.rs b/01.workspace/heave/src/lib.rs index 55a8b06..3e34c42 100644 --- a/01.workspace/heave/src/lib.rs +++ b/01.workspace/heave/src/lib.rs @@ -193,6 +193,9 @@ pub use crate::str::filter::O as Filter; pub(crate) use crate::str::value::Value; pub use crate::trt::eav::T as EAV; +#[cfg(test)] +pub(crate) use crate::str::item::O as Item; + mod sqlite { pub use crate::str::sqlite_failed_to::FailedTo; pub mod build { diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index 06a25c5..534129b 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -14,56 +14,6 @@ pub struct O { #[cfg(test)] mod tests { use super::*; - #[derive(Debug, Default, PartialEq, Clone)] - struct Item { - pub id: String, - pub name: String, - pub price: u64, - pub discount: f64, - pub sell_trend: i64, - pub in_stock: bool, - pub subclass: Option, - } - impl EAV for Item { - fn class() -> &'static str { - "item" - } - } - impl From for Entity { - fn from(value: Item) -> Entity { - let mut entity = Entity::new::() - .with_id(&value.id) - .with_subclass("subitem") - .with_attribute("name", value.name) - .with_attribute("price", value.price) - .with_attribute("discount", value.discount) - .with_attribute("sell_trend", value.sell_trend) - .with_attribute("in_stock", value.in_stock); - if let Some(subclass) = value.subclass { - entity = entity.with_subclass(&subclass); - } - entity - } - } - impl From for Item { - fn from(entity: Entity) -> Self { - Self { - id: entity.id.clone(), - name: entity.unwrap("name").expect("name is always present"), - price: entity.unwrap("price").expect("price is always present"), - discount: entity - .unwrap("discount") - .expect("discount is always present"), - sell_trend: entity - .unwrap("sell_trend") - .expect("sell_trend is always present"), - in_stock: entity - .unwrap("in_stock") - .expect("in_stock is always present"), - subclass: entity.subclass, - } - } - } // ## 'new()' #[test] fn new_should_create_catalog_with_path_and_empty_items() { diff --git a/01.workspace/heave/src/str/item.rs b/01.workspace/heave/src/str/item.rs new file mode 100644 index 0000000..7a77601 --- /dev/null +++ b/01.workspace/heave/src/str/item.rs @@ -0,0 +1,57 @@ +#[cfg(test)] +use crate::*; + +#[cfg(test)] +#[derive(Debug, Default, PartialEq, Clone)] +pub struct O { + pub id: String, + pub name: String, + pub price: u64, + pub discount: f64, + pub sell_trend: i64, + pub in_stock: bool, + pub subclass: Option, +} +#[cfg(test)] +impl EAV for Item { + fn class() -> &'static str { + "item" + } +} +#[cfg(test)] +impl From for Entity { + fn from(value: Item) -> Entity { + let mut entity = Entity::new::() + .with_id(&value.id) + .with_subclass("subitem") + .with_attribute("name", value.name) + .with_attribute("price", value.price) + .with_attribute("discount", value.discount) + .with_attribute("sell_trend", value.sell_trend) + .with_attribute("in_stock", value.in_stock); + if let Some(subclass) = value.subclass { + entity = entity.with_subclass(&subclass); + } + entity + } +} +#[cfg(test)] +impl From for Item { + fn from(entity: Entity) -> Self { + Self { + id: entity.id.clone(), + name: entity.unwrap("name").expect("name is always present"), + price: entity.unwrap("price").expect("price is always present"), + discount: entity + .unwrap("discount") + .expect("discount is always present"), + sell_trend: entity + .unwrap("sell_trend") + .expect("sell_trend is always present"), + in_stock: entity + .unwrap("in_stock") + .expect("in_stock is always present"), + subclass: entity.subclass, + } + } +} diff --git a/01.workspace/heave/src/str/mod.rs b/01.workspace/heave/src/str/mod.rs index c50b2e4..9d90979 100644 --- a/01.workspace/heave/src/str/mod.rs +++ b/01.workspace/heave/src/str/mod.rs @@ -6,5 +6,6 @@ pub mod entity; pub mod entity_state; pub mod failed_to; pub mod filter; +pub mod item; pub mod sqlite_failed_to; pub mod value;