diff --git a/server/src/project.rs b/server/src/project.rs index 539401d9..d99d3f15 100644 --- a/server/src/project.rs +++ b/server/src/project.rs @@ -126,14 +126,14 @@ pub struct ProjectInitError; #[fail(display = "Project save error")] pub struct ProjectSaveError; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(tag = "type")] pub enum ProjectNode { Instance(InstanceProjectNode), SyncPoint(SyncPointProjectNode), } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct InstanceProjectNode { pub class_name: String, @@ -142,13 +142,13 @@ pub struct InstanceProjectNode { // ignore_unknown: bool, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SyncPointProjectNode { pub path: PathBuf, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Project { pub name: String, pub tree: ProjectNode, diff --git a/server/tests/read_projects.rs b/server/tests/read_projects.rs index b8a1315d..6de207ea 100644 --- a/server/tests/read_projects.rs +++ b/server/tests/read_projects.rs @@ -3,11 +3,12 @@ extern crate librojo; use std::{ + collections::HashMap, path::{Path, PathBuf}, }; use librojo::{ - project::Project, + project::{Project, ProjectNode, InstanceProjectNode, SyncPointProjectNode}, }; lazy_static! { @@ -17,7 +18,7 @@ lazy_static! { } #[test] -fn fullexample() { +fn tour_de_force() { let project_file_location = TEST_PROJECTS_ROOT.join("example.json"); let project = Project::load_exact(&project_file_location).unwrap(); @@ -30,4 +31,66 @@ fn empty() { let project = Project::load_exact(&project_file_location).unwrap(); assert_eq!(project.name, "empty"); +} + +#[test] +fn empty_fuzzy_file() { + let project_file_location = TEST_PROJECTS_ROOT.join("empty/roblox-project.json"); + let project = Project::load_fuzzy(&project_file_location).unwrap(); + + assert_eq!(project.name, "empty"); +} + +#[test] +fn empty_fuzzy_folder() { + let project_location = TEST_PROJECTS_ROOT.join("empty"); + let project = Project::load_fuzzy(&project_location).unwrap(); + + assert_eq!(project.name, "empty"); +} + +#[test] +fn single_sync_point() { + let project_file_location = TEST_PROJECTS_ROOT.join("single-sync-point/roblox-project.json"); + let project = Project::load_exact(&project_file_location).unwrap(); + + let expected_project = { + let foo = ProjectNode::SyncPoint(SyncPointProjectNode { + path: project_file_location.parent().unwrap().join("lib"), + }); + + let mut replicated_storage_children = HashMap::new(); + replicated_storage_children.insert("Foo".to_string(), foo); + + let replicated_storage = ProjectNode::Instance(InstanceProjectNode { + class_name: "ReplicatedStorage".to_string(), + children: replicated_storage_children, + properties: HashMap::new(), + }); + + let mut root_children = HashMap::new(); + root_children.insert("ReplicatedStorage".to_string(), replicated_storage); + + let root_node = ProjectNode::Instance(InstanceProjectNode { + class_name: "DataModel".to_string(), + children: root_children, + properties: HashMap::new(), + }); + + Project { + name: "single-sync-point".to_string(), + tree: root_node, + file_location: project_file_location.clone(), + } + }; + + assert_eq!(project, expected_project); +} + +#[test] +fn test_model() { + let project_file_location = TEST_PROJECTS_ROOT.join("test-model/roblox-project.json"); + let project = Project::load_exact(&project_file_location).unwrap(); + + assert_eq!(project.name, "test-model"); } \ No newline at end of file