mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 22:11:38 +00:00
Reorganize tree-related snapshot code
This commit is contained in:
parent
61b9e5a6a2
commit
c86e25f039
3 changed files with 25 additions and 25 deletions
|
|
@ -24,7 +24,7 @@ use librojo::{
|
|||
use crate::test_util::{
|
||||
copy_recursive,
|
||||
snapshot::*,
|
||||
tree::trees_equal,
|
||||
tree::{read_tree_by_name, write_tree_by_name, trees_equal},
|
||||
};
|
||||
|
||||
macro_rules! generate_snapshot_tests {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use rbx_dom_weak::RbxTree;
|
||||
|
||||
use librojo::{
|
||||
project::ProjectNode,
|
||||
snapshot_reconciler::RbxSnapshotInstance,
|
||||
|
|
@ -59,28 +57,6 @@ pub fn anonymize_path(project_folder_path: &Path, path: &Path) -> PathBuf {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_tree_by_name(path: &Path, identifier: &str) -> Option<RbxTree> {
|
||||
let mut file_path = path.join(identifier);
|
||||
file_path.set_extension("tree.json");
|
||||
|
||||
let contents = fs::read(&file_path).ok()?;
|
||||
let tree: RbxTree = serde_json::from_slice(&contents)
|
||||
.expect("Could not deserialize tree");
|
||||
|
||||
Some(tree)
|
||||
}
|
||||
|
||||
pub fn write_tree_by_name(path: &Path, identifier: &str, tree: &RbxTree) {
|
||||
let mut file_path = path.join(identifier);
|
||||
file_path.set_extension("tree.json");
|
||||
|
||||
let mut file = File::create(file_path)
|
||||
.expect("Could not open file to write tree");
|
||||
|
||||
serde_json::to_writer_pretty(&mut file, tree)
|
||||
.expect("Could not serialize tree to file");
|
||||
}
|
||||
|
||||
pub fn read_expected_snapshot(path: &Path) -> Option<Option<RbxSnapshotInstance<'static>>> {
|
||||
let contents = fs::read(path.join(SNAPSHOT_EXPECTED_NAME)).ok()?;
|
||||
let snapshot: Option<RbxSnapshotInstance<'static>> = serde_json::from_slice(&contents)
|
||||
|
|
|
|||
|
|
@ -13,11 +13,35 @@
|
|||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashSet,
|
||||
path::Path,
|
||||
fs::{self, File},
|
||||
fmt,
|
||||
};
|
||||
|
||||
use rbx_dom_weak::{RbxId, RbxTree};
|
||||
|
||||
pub fn read_tree_by_name(path: &Path, identifier: &str) -> Option<RbxTree> {
|
||||
let mut file_path = path.join(identifier);
|
||||
file_path.set_extension("tree.json");
|
||||
|
||||
let contents = fs::read(&file_path).ok()?;
|
||||
let tree: RbxTree = serde_json::from_slice(&contents)
|
||||
.expect("Could not deserialize tree");
|
||||
|
||||
Some(tree)
|
||||
}
|
||||
|
||||
pub fn write_tree_by_name(path: &Path, identifier: &str, tree: &RbxTree) {
|
||||
let mut file_path = path.join(identifier);
|
||||
file_path.set_extension("tree.json");
|
||||
|
||||
let mut file = File::create(file_path)
|
||||
.expect("Could not open file to write tree");
|
||||
|
||||
serde_json::to_writer_pretty(&mut file, tree)
|
||||
.expect("Could not serialize tree to file");
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TreeMismatch {
|
||||
pub path: Cow<'static, str>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue