libikarus 0.1.14

The core functionality of Ikarus wrapped neatly in a rust library
Documentation
#[cfg(test)]
pub mod tests {
    use crate::objects::entity::{EntityValue, ToggleValue};
    use crate::objects::property::{PropertyScope, PropertyType};
    use crate::persistence::project::Project;
    use crate::tests::*;
    use std::collections::HashSet;

    #[test]
    pub fn entity_blueprint_fetching() -> Result<(), Box<dyn std::error::Error>> {
        let project = Project::open_in_memory()?;

        let blueprints = vec![
            new_blueprint(&project),
            new_blueprint(&project),
            new_blueprint(&project),
        ];

        for blueprints in (0..2).map(|l| &blueprints[0..l]) {
            let entity = new_entity(&project, blueprints.iter().collect());
            assert_eq!(entity.get_blueprints()?.as_slice(), blueprints);
        }

        let duplicate = new_blueprint(&project);

        let entity = new_entity(&project, [&duplicate, &duplicate].into());
        assert_eq!(entity.get_blueprints()?.as_slice(), &[duplicate]);

        Ok(())
    }

    #[test]
    pub fn entity_value_default_fetching() -> Result<(), Box<dyn std::error::Error>> {
        let project = Project::open_in_memory()?;

        let entity = new_entity(&project, HashSet::new());

        for property_type in PropertyType::values() {
            let property = new_property(
                &project,
                PropertyScope::Entity(entity.clone()),
                property_type,
                None,
                None,
            );

            assert!(entity.is_default_value(&property)?);
            assert_eq!(property.default_value()?, entity.value(&property)?);
        }

        Ok(())
    }

    #[test]
    pub fn entity_value_default_changing() -> Result<(), Box<dyn std::error::Error>> {
        let project = Project::open_in_memory()?;

        let mut entity = new_entity(&project, HashSet::new());

        for property_type in PropertyType::values() {
            let property = new_property(
                &project,
                PropertyScope::Entity(entity.clone()),
                property_type,
                None,
                None,
            );

            let new_value = match property_type {
                PropertyType::Toggle => EntityValue::Toggle(ToggleValue::True),
                PropertyType::Number => EntityValue::Number(10.0),
                PropertyType::Text => EntityValue::Text(String::from("test")),
            };

            entity.set_value(&property, &new_value)?;

            assert_eq!(entity.value(&property)?, new_value)
        }

        Ok(())
    }

    #[test]
    pub fn entity_value_default_resetting() -> Result<(), Box<dyn std::error::Error>> {
        let project = Project::open_in_memory()?;

        let mut entity = new_entity(&project, HashSet::new());

        for property_type in PropertyType::values() {
            let property = new_property(
                &project,
                PropertyScope::Entity(entity.clone()),
                property_type,
                None,
                None,
            );

            let new_value = match property_type {
                PropertyType::Toggle => EntityValue::Toggle(ToggleValue::True),
                PropertyType::Number => EntityValue::Number(10.0),
                PropertyType::Text => EntityValue::Text(String::from("test")),
            };

            entity.set_value(&property, &new_value)?;

            entity.reset_value(&property)?;

            assert_eq!(property.default_value()?, entity.value(&property)?);
        }

        Ok(())
    }
}