mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Assign contributing paths in simple cases for snapshots
This commit is contained in:
@@ -6,7 +6,7 @@ use serde::Serialize;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
imfs::{Imfs, ImfsEntry, ImfsFetcher},
|
imfs::{Imfs, ImfsEntry, ImfsFetcher},
|
||||||
snapshot::InstanceSnapshot,
|
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware};
|
use super::middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware};
|
||||||
@@ -39,7 +39,10 @@ impl SnapshotMiddleware for SnapshotCsv {
|
|||||||
|
|
||||||
Ok(Some(InstanceSnapshot {
|
Ok(Some(InstanceSnapshot {
|
||||||
snapshot_id: None,
|
snapshot_id: None,
|
||||||
metadata: Default::default(), // TODO
|
metadata: InstanceMetadata {
|
||||||
|
contributing_paths: vec![entry.path().to_path_buf()],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
name: Cow::Owned(instance_name),
|
name: Cow::Owned(instance_name),
|
||||||
class_name: Cow::Borrowed("LocalizationTable"),
|
class_name: Cow::Borrowed("LocalizationTable"),
|
||||||
properties: hashmap! {
|
properties: hashmap! {
|
||||||
@@ -137,6 +140,7 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
use crate::imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher};
|
||||||
|
use insta::assert_yaml_snapshot;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn csv_from_imfs() {
|
fn csv_from_imfs() {
|
||||||
@@ -152,19 +156,6 @@ Ack,Ack!,,An exclamation of despair,¡Ay!"#,
|
|||||||
let entry = imfs.get("/foo.csv").unwrap();
|
let entry = imfs.get("/foo.csv").unwrap();
|
||||||
let instance_snapshot = SnapshotCsv::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
let instance_snapshot = SnapshotCsv::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||||
|
|
||||||
let expected_contents =
|
assert_yaml_snapshot!(instance_snapshot);
|
||||||
r#"[{"key":"Ack","example":"An exclamation of despair","source":"Ack!","values":{"es":"¡Ay!"}}]"#;
|
|
||||||
|
|
||||||
assert_eq!(instance_snapshot.name, "foo");
|
|
||||||
assert_eq!(instance_snapshot.class_name, "LocalizationTable");
|
|
||||||
assert_eq!(instance_snapshot.children, Vec::new());
|
|
||||||
assert_eq!(
|
|
||||||
instance_snapshot.properties,
|
|
||||||
hashmap! {
|
|
||||||
"Contents".to_owned() => RbxValue::String {
|
|
||||||
value: expected_contents.to_owned(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ impl SnapshotMiddleware for SnapshotRbxlx {
|
|||||||
|
|
||||||
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, root_id);
|
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, root_id);
|
||||||
snapshot.name = Cow::Owned(instance_name);
|
snapshot.name = Cow::Owned(instance_name);
|
||||||
// TODO: Assign snapshot.source
|
snapshot.metadata.contributing_paths = vec![entry.path().to_path_buf()];
|
||||||
|
|
||||||
Ok(Some(snapshot))
|
Ok(Some(snapshot))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ impl SnapshotMiddleware for SnapshotRbxm {
|
|||||||
if children.len() == 1 {
|
if children.len() == 1 {
|
||||||
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
|
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
|
||||||
snapshot.name = Cow::Owned(instance_name);
|
snapshot.name = Cow::Owned(instance_name);
|
||||||
// TODO: Assign snapshot.source
|
snapshot.metadata.contributing_paths = vec![entry.path().to_path_buf()];
|
||||||
|
|
||||||
Ok(Some(snapshot))
|
Ok(Some(snapshot))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ impl SnapshotMiddleware for SnapshotRbxmx {
|
|||||||
if children.len() == 1 {
|
if children.len() == 1 {
|
||||||
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
|
let mut snapshot = InstanceSnapshot::from_tree(&temp_tree, children[0]);
|
||||||
snapshot.name = Cow::Owned(instance_name);
|
snapshot.name = Cow::Owned(instance_name);
|
||||||
// TODO: Assign snapshot.source
|
snapshot.metadata.contributing_paths = vec![entry.path().to_path_buf()];
|
||||||
|
|
||||||
Ok(Some(snapshot))
|
Ok(Some(snapshot))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
17
src/snapshot_middleware/snapshots/test__csv_from_imfs.snap
Normal file
17
src/snapshot_middleware/snapshots/test__csv_from_imfs.snap
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot_middleware/csv.rs
|
||||||
|
expression: instance_snapshot
|
||||||
|
---
|
||||||
|
snapshot_id: ~
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: false
|
||||||
|
contributing_paths:
|
||||||
|
- /foo.csv
|
||||||
|
project_node: ~
|
||||||
|
name: foo
|
||||||
|
class_name: LocalizationTable
|
||||||
|
properties:
|
||||||
|
Contents:
|
||||||
|
Type: String
|
||||||
|
Value: "[{\"key\":\"Ack\",\"example\":\"An exclamation of despair\",\"source\":\"Ack!\",\"values\":{\"es\":\"¡Ay!\"}}]"
|
||||||
|
children: []
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot_middleware/txt.rs
|
||||||
|
expression: instance_snapshot
|
||||||
|
---
|
||||||
|
snapshot_id: ~
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: false
|
||||||
|
contributing_paths:
|
||||||
|
- /foo.txt
|
||||||
|
project_node: ~
|
||||||
|
name: foo
|
||||||
|
class_name: StringValue
|
||||||
|
properties:
|
||||||
|
Value:
|
||||||
|
Type: String
|
||||||
|
Value: Hello there!
|
||||||
|
children: []
|
||||||
@@ -5,7 +5,7 @@ use rbx_dom_weak::{RbxId, RbxTree, RbxValue};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
imfs::{FileSnapshot, Imfs, ImfsEntry, ImfsFetcher, ImfsSnapshot},
|
imfs::{FileSnapshot, Imfs, ImfsEntry, ImfsFetcher, ImfsSnapshot},
|
||||||
snapshot::InstanceSnapshot,
|
snapshot::{InstanceMetadata, InstanceSnapshot},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware};
|
use super::middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware};
|
||||||
@@ -51,7 +51,10 @@ impl SnapshotMiddleware for SnapshotTxt {
|
|||||||
|
|
||||||
Ok(Some(InstanceSnapshot {
|
Ok(Some(InstanceSnapshot {
|
||||||
snapshot_id: None,
|
snapshot_id: None,
|
||||||
metadata: Default::default(), // TODO
|
metadata: InstanceMetadata {
|
||||||
|
contributing_paths: vec![entry.path().to_path_buf()],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
name: Cow::Owned(instance_name),
|
name: Cow::Owned(instance_name),
|
||||||
class_name: Cow::Borrowed("StringValue"),
|
class_name: Cow::Borrowed("StringValue"),
|
||||||
properties,
|
properties,
|
||||||
@@ -91,6 +94,7 @@ impl SnapshotMiddleware for SnapshotTxt {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
use insta::assert_yaml_snapshot;
|
||||||
use maplit::hashmap;
|
use maplit::hashmap;
|
||||||
use rbx_dom_weak::RbxInstanceProperties;
|
use rbx_dom_weak::RbxInstanceProperties;
|
||||||
|
|
||||||
@@ -106,16 +110,7 @@ mod test {
|
|||||||
let entry = imfs.get("/foo.txt").unwrap();
|
let entry = imfs.get("/foo.txt").unwrap();
|
||||||
let instance_snapshot = SnapshotTxt::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
let instance_snapshot = SnapshotTxt::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||||
|
|
||||||
assert_eq!(instance_snapshot.name, "foo");
|
assert_yaml_snapshot!(instance_snapshot);
|
||||||
assert_eq!(instance_snapshot.class_name, "StringValue");
|
|
||||||
assert_eq!(
|
|
||||||
instance_snapshot.properties,
|
|
||||||
hashmap! {
|
|
||||||
"Value".to_owned() => RbxValue::String {
|
|
||||||
value: "Hello there!".to_owned(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user