Support .jsonc extension for all JSON files (#1159)

This commit is contained in:
Micah
2025-11-18 18:47:43 -08:00
committed by GitHub
parent 03410ced6d
commit ea70d89291
46 changed files with 759 additions and 153 deletions

View File

@@ -1,7 +1,7 @@
use std::path::Path;
use anyhow::Context as _;
use memofs::{IoResultExt, Vfs};
use memofs::Vfs;
use rbx_dom_weak::ustr;
use yaml_rust2::{Yaml, YamlLoader};
@@ -30,8 +30,6 @@ pub fn snapshot_yaml(
let as_lua = Statement::Return(yaml_to_luau(value)?);
let meta_path = path.with_file_name(format!("{}.meta.json", name));
let mut snapshot = InstanceSnapshot::new()
.name(name)
.class_name("ModuleScript")
@@ -39,14 +37,11 @@ pub fn snapshot_yaml(
.metadata(
InstanceMetadata::new()
.instigating_source(path)
.relevant_paths(vec![path.to_path_buf(), meta_path.clone()])
.relevant_paths(vec![path.to_path_buf()])
.context(context),
);
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
let mut metadata = AdjacentMetadata::from_slice(&meta_contents, meta_path)?;
metadata.apply_all(&mut snapshot)?;
}
AdjacentMetadata::read_and_apply_all(vfs, path, name, &mut snapshot)?;
Ok(Some(snapshot))
}
@@ -231,4 +226,40 @@ value: 9007199254740993
.unwrap()
.unwrap();
}
#[test]
fn with_metadata() {
let mut imfs = InMemoryFs::new();
imfs.load_snapshot(
"foo.yaml",
VfsSnapshot::file(
r#"
value: 1234
"#,
),
)
.unwrap();
imfs.load_snapshot(
"foo.meta.json",
VfsSnapshot::file(
r#"{
"id": "manually specified",
}"#,
),
)
.unwrap();
let vfs = Vfs::new(imfs.clone());
let instance_snapshot = snapshot_yaml(
&InstanceContext::default(),
&vfs,
Path::new("foo.yaml"),
"foo",
)
.unwrap()
.unwrap();
insta::assert_yaml_snapshot!(instance_snapshot);
}
}