Flesh out project loading tests

This commit is contained in:
Lucien Greathouse
2018-12-17 12:50:40 -08:00
parent 5707b8c7e8
commit e3e4809446
2 changed files with 69 additions and 6 deletions

View File

@@ -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,

View File

@@ -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");
}