Remove maplit dependency and stop using a macro for hashmaps (#982)

This commit is contained in:
Micah
2024-10-31 11:56:54 -07:00
committed by GitHub
parent d9ab0e7de8
commit 34106f470f
13 changed files with 111 additions and 108 deletions

View File

@@ -70,7 +70,6 @@ humantime = "2.1.0"
hyper = { version = "0.14.28", features = ["server", "tcp", "http1"] } hyper = { version = "0.14.28", features = ["server", "tcp", "http1"] }
jod-thread = "0.1.2" jod-thread = "0.1.2"
log = "0.4.21" log = "0.4.21"
maplit = "1.0.2"
num_cpus = "1.16.0" num_cpus = "1.16.0"
opener = "0.5.2" opener = "0.5.2"
rayon = "1.9.0" rayon = "1.9.0"

View File

@@ -304,7 +304,6 @@ mod test {
use std::borrow::Cow; use std::borrow::Cow;
use maplit::hashmap;
use rbx_dom_weak::types::Variant; use rbx_dom_weak::types::Variant;
use super::super::PatchAdd; use super::super::PatchAdd;
@@ -322,9 +321,7 @@ mod test {
metadata: Default::default(), metadata: Default::default(),
name: Cow::Borrowed("Foo"), name: Cow::Borrowed("Foo"),
class_name: Cow::Borrowed("Bar"), class_name: Cow::Borrowed("Bar"),
properties: hashmap! { properties: [("Baz".to_owned(), Variant::Int32(5))].into(),
"Baz".to_owned() => Variant::Int32(5),
},
children: Vec::new(), children: Vec::new(),
}; };
@@ -367,16 +364,15 @@ mod test {
id: root_id, id: root_id,
changed_name: Some("Foo".to_owned()), changed_name: Some("Foo".to_owned()),
changed_class_name: Some("NewClassName".to_owned()), changed_class_name: Some("NewClassName".to_owned()),
changed_properties: hashmap! { changed_properties: [
// The value of Foo has changed // The value of Foo has changed
"Foo".to_owned() => Some(Variant::Int32(8)), ("Foo".to_owned(), Some(Variant::Int32(8))),
// Bar has been deleted // Bar has been deleted
"Bar".to_owned() => None, ("Bar".to_owned(), None),
// Baz has been added // Baz has been added
"Baz".to_owned() => Some(Variant::Int32(10)), ("Baz".to_owned(), Some(Variant::Int32(10))),
}, ]
.into(),
changed_metadata: None, changed_metadata: None,
}; };
@@ -387,11 +383,12 @@ mod test {
apply_patch_set(&mut tree, patch_set); apply_patch_set(&mut tree, patch_set);
let expected_properties = hashmap! { let expected_properties = [
"Foo".to_owned() => Variant::Int32(8), ("Foo".to_owned(), Variant::Int32(8)),
"Baz".to_owned() => Variant::Int32(10), ("Baz".to_owned(), Variant::Int32(10)),
"Unchanged".to_owned() => Variant::Int32(-5), ("Unchanged".to_owned(), Variant::Int32(-5)),
}; ]
.into();
let root_instance = tree.get_instance(root_id).unwrap(); let root_instance = tree.get_instance(root_id).unwrap();
assert_eq!(root_instance.name(), "Foo"); assert_eq!(root_instance.name(), "Foo");

View File

@@ -299,8 +299,6 @@ mod test {
use std::borrow::Cow; use std::borrow::Cow;
use maplit::hashmap;
/// This test makes sure that rewriting refs in instance update patches to /// This test makes sure that rewriting refs in instance update patches to
/// instances that already exists works. We should be able to correlate the /// instances that already exists works. We should be able to correlate the
/// snapshot ID and instance ID during patch computation and replace the /// snapshot ID and instance ID during patch computation and replace the
@@ -316,9 +314,7 @@ mod test {
let snapshot_id = Ref::new(); let snapshot_id = Ref::new();
let snapshot = InstanceSnapshot { let snapshot = InstanceSnapshot {
snapshot_id: snapshot_id, snapshot_id: snapshot_id,
properties: hashmap! { properties: [("Self".to_owned(), Variant::Ref(snapshot_id))].into(),
"Self".to_owned() => Variant::Ref(snapshot_id),
},
metadata: Default::default(), metadata: Default::default(),
name: Cow::Borrowed("foo"), name: Cow::Borrowed("foo"),
@@ -333,9 +329,7 @@ mod test {
id: root_id, id: root_id,
changed_name: None, changed_name: None,
changed_class_name: None, changed_class_name: None,
changed_properties: hashmap! { changed_properties: [("Self".to_owned(), Some(Variant::Ref(root_id)))].into(),
"Self".to_owned() => Some(Variant::Ref(root_id)),
},
changed_metadata: None, changed_metadata: None,
}], }],
added_instances: Vec::new(), added_instances: Vec::new(),
@@ -359,9 +353,7 @@ mod test {
let snapshot = InstanceSnapshot { let snapshot = InstanceSnapshot {
snapshot_id: snapshot_id, snapshot_id: snapshot_id,
children: vec![InstanceSnapshot { children: vec![InstanceSnapshot {
properties: hashmap! { properties: [("Self".to_owned(), Variant::Ref(snapshot_id))].into(),
"Self".to_owned() => Variant::Ref(snapshot_id),
},
snapshot_id: Ref::none(), snapshot_id: Ref::none(),
metadata: Default::default(), metadata: Default::default(),
@@ -384,9 +376,7 @@ mod test {
instance: InstanceSnapshot { instance: InstanceSnapshot {
snapshot_id: Ref::none(), snapshot_id: Ref::none(),
metadata: Default::default(), metadata: Default::default(),
properties: hashmap! { properties: [("Self".to_owned(), Variant::Ref(root_id))].into(),
"Self".to_owned() => Variant::Ref(root_id),
},
name: Cow::Borrowed("child"), name: Cow::Borrowed("child"),
class_name: Cow::Borrowed("child"), class_name: Cow::Borrowed("child"),
children: Vec::new(), children: Vec::new(),

View File

@@ -1,5 +1,4 @@
use insta::assert_yaml_snapshot; use insta::assert_yaml_snapshot;
use maplit::hashmap;
use rojo_insta_ext::RedactionMap; use rojo_insta_ext::RedactionMap;
@@ -47,9 +46,7 @@ fn add_property() {
id: tree.get_root_id(), id: tree.get_root_id(),
changed_name: None, changed_name: None,
changed_class_name: None, changed_class_name: None,
changed_properties: hashmap! { changed_properties: [("Foo".to_owned(), Some("Value of Foo".into()))].into(),
"Foo".to_owned() => Some("Value of Foo".into()),
},
changed_metadata: None, changed_metadata: None,
}], }],
..Default::default() ..Default::default()
@@ -88,9 +85,7 @@ fn remove_property() {
id: tree.get_root_id(), id: tree.get_root_id(),
changed_name: None, changed_name: None,
changed_class_name: None, changed_class_name: None,
changed_properties: hashmap! { changed_properties: [("Foo".to_owned(), None).into()].into(),
"Foo".to_owned() => None,
},
changed_metadata: None, changed_metadata: None,
}], }],
..Default::default() ..Default::default()

View File

@@ -1,7 +1,6 @@
use std::borrow::Cow; use std::borrow::Cow;
use insta::assert_yaml_snapshot; use insta::assert_yaml_snapshot;
use maplit::hashmap;
use rbx_dom_weak::types::Ref; use rbx_dom_weak::types::Ref;
use rojo_insta_ext::RedactionMap; use rojo_insta_ext::RedactionMap;
@@ -42,9 +41,7 @@ fn set_property() {
metadata: Default::default(), metadata: Default::default(),
name: Cow::Borrowed("ROOT"), name: Cow::Borrowed("ROOT"),
class_name: Cow::Borrowed("ROOT"), class_name: Cow::Borrowed("ROOT"),
properties: hashmap! { properties: [("PropertyName".into(), "Hello, world!".into())].into(),
"PropertyName".to_owned() => "Hello, world!".into(),
},
children: Vec::new(), children: Vec::new(),
}; };

View File

@@ -1,7 +1,6 @@
use std::{collections::BTreeMap, path::Path}; use std::{collections::BTreeMap, path::Path};
use anyhow::Context; use anyhow::Context;
use maplit::hashmap;
use memofs::{IoResultExt, Vfs}; use memofs::{IoResultExt, Vfs};
use serde::Serialize; use serde::Serialize;
@@ -31,9 +30,7 @@ pub fn snapshot_csv(
let mut snapshot = InstanceSnapshot::new() let mut snapshot = InstanceSnapshot::new()
.name(name) .name(name)
.class_name("LocalizationTable") .class_name("LocalizationTable")
.properties(hashmap! { .properties([("Contents".to_owned(), table_contents.into())])
"Contents".to_owned() => table_contents.into(),
})
.metadata( .metadata(
InstanceMetadata::new() InstanceMetadata::new()
.instigating_source(path) .instigating_source(path)

View File

@@ -108,7 +108,6 @@ pub fn snapshot_dir_no_meta(
mod test { mod test {
use super::*; use super::*;
use maplit::hashmap;
use memofs::{InMemoryFs, VfsSnapshot}; use memofs::{InMemoryFs, VfsSnapshot};
#[test] #[test]
@@ -132,9 +131,7 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([("Child", VfsSnapshot::empty_dir())]),
"Child" => VfsSnapshot::empty_dir(),
}),
) )
.unwrap(); .unwrap();

View File

@@ -1,7 +1,6 @@
use std::path::Path; use std::path::Path;
use anyhow::Context; use anyhow::Context;
use maplit::hashmap;
use memofs::{IoResultExt, Vfs}; use memofs::{IoResultExt, Vfs};
use crate::{ use crate::{
@@ -24,9 +23,7 @@ pub fn snapshot_json(
let as_lua = json_to_lua(value).to_string(); let as_lua = json_to_lua(value).to_string();
let properties = hashmap! { let properties = [("Source".to_owned(), as_lua.into())];
"Source".to_owned() => as_lua.into(),
};
let meta_path = path.with_file_name(format!("{}.meta.json", name)); let meta_path = path.with_file_name(format!("{}.meta.json", name));

View File

@@ -116,7 +116,6 @@ pub fn snapshot_lua_init(
mod test { mod test {
use super::*; use super::*;
use maplit::hashmap;
use memofs::{InMemoryFs, VfsSnapshot}; use memofs::{InMemoryFs, VfsSnapshot};
#[test] #[test]
@@ -263,9 +262,7 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/root", "/root",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([("init.lua", VfsSnapshot::file("Hello!"))]),
"init.lua" => VfsSnapshot::file("Hello!"),
}),
) )
.unwrap(); .unwrap();

View File

@@ -340,7 +340,6 @@ fn infer_class_name(name: &str, parent_class: Option<&str>) -> Option<Cow<'stati
mod test { mod test {
use super::*; use super::*;
use maplit::hashmap;
use memofs::{InMemoryFs, VfsSnapshot}; use memofs::{InMemoryFs, VfsSnapshot};
#[ignore = "Functionality moved to root snapshot middleware"] #[ignore = "Functionality moved to root snapshot middleware"]
@@ -351,16 +350,19 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([(
"default.project.json" => VfsSnapshot::file(r#" "default.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "indirect-project", "name": "indirect-project",
"tree": { "tree": {
"$className": "Folder" "$className": "Folder"
} }
} }
"#), "#,
}), ),
)]),
) )
.unwrap(); .unwrap();
@@ -385,16 +387,19 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([(
"hello.project.json" => VfsSnapshot::file(r#" "hello.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "direct-project", "name": "direct-project",
"tree": { "tree": {
"$className": "Model" "$className": "Model"
} }
} }
"#), "#,
}), ),
)]),
) )
.unwrap(); .unwrap();
@@ -533,17 +538,22 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([
"default.project.json" => VfsSnapshot::file(r#" (
"default.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "path-project", "name": "path-project",
"tree": { "tree": {
"$path": "other.txt" "$path": "other.txt"
} }
} }
"#), "#,
"other.txt" => VfsSnapshot::file("Hello, world!"), ),
}), ),
("other.txt", VfsSnapshot::file("Hello, world!")),
]),
) )
.unwrap(); .unwrap();
@@ -568,24 +578,34 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([
"default.project.json" => VfsSnapshot::file(r#" (
"default.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "path-project", "name": "path-project",
"tree": { "tree": {
"$path": "other.project.json" "$path": "other.project.json"
} }
} }
"#), "#,
"other.project.json" => VfsSnapshot::file(r#" ),
),
(
"other.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "other-project", "name": "other-project",
"tree": { "tree": {
"$className": "Model" "$className": "Model"
} }
} }
"#), "#,
}), ),
),
]),
) )
.unwrap(); .unwrap();
@@ -610,16 +630,24 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([
"default.project.json" => VfsSnapshot::file(r#" (
"default.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "path-child-project", "name": "path-child-project",
"tree": { "tree": {
"$path": "other.project.json" "$path": "other.project.json"
} }
} }
"#), "#,
"other.project.json" => VfsSnapshot::file(r#" ),
),
(
"other.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "other-project", "name": "other-project",
"tree": { "tree": {
@@ -630,8 +658,10 @@ mod test {
} }
} }
} }
"#), "#,
}), ),
),
]),
) )
.unwrap(); .unwrap();
@@ -659,8 +689,11 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([
"default.project.json" => VfsSnapshot::file(r#" (
"default.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "path-property-override", "name": "path-property-override",
"tree": { "tree": {
@@ -670,8 +703,13 @@ mod test {
} }
} }
} }
"#), "#,
"other.project.json" => VfsSnapshot::file(r#" ),
),
(
"other.project.json",
VfsSnapshot::file(
r#"
{ {
"name": "other-project", "name": "other-project",
"tree": { "tree": {
@@ -681,8 +719,10 @@ mod test {
} }
} }
} }
"#), "#,
}), ),
),
]),
) )
.unwrap(); .unwrap();
@@ -707,15 +747,18 @@ mod test {
let mut imfs = InMemoryFs::new(); let mut imfs = InMemoryFs::new();
imfs.load_snapshot( imfs.load_snapshot(
"/foo", "/foo",
VfsSnapshot::dir(hashmap! { VfsSnapshot::dir([(
"default.project.json" => VfsSnapshot::file(r#" "default.project.json",
VfsSnapshot::file(
r#"
{ {
"tree": { "tree": {
"$className": "Model" "$className": "Model"
} }
} }
"#), "#,
}), ),
)]),
) )
.unwrap(); .unwrap();

View File

@@ -1,7 +1,6 @@
use std::path::Path; use std::path::Path;
use anyhow::Context; use anyhow::Context;
use maplit::hashmap;
use memofs::{IoResultExt, Vfs}; use memofs::{IoResultExt, Vfs};
use crate::{ use crate::{
@@ -24,9 +23,7 @@ pub fn snapshot_toml(
let as_lua = toml_to_lua(value).to_string(); let as_lua = toml_to_lua(value).to_string();
let properties = hashmap! { let properties = [("Source".to_owned(), as_lua.into())];
"Source".to_owned() => as_lua.into(),
};
let meta_path = path.with_file_name(format!("{}.meta.json", name)); let meta_path = path.with_file_name(format!("{}.meta.json", name));

View File

@@ -1,6 +1,5 @@
use std::{path::Path, str}; use std::{path::Path, str};
use maplit::hashmap;
use memofs::{IoResultExt, Vfs}; use memofs::{IoResultExt, Vfs};
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot}; use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
@@ -16,9 +15,7 @@ pub fn snapshot_txt(
let contents = vfs.read_to_string(path)?; let contents = vfs.read_to_string(path)?;
let contents_str = contents.as_str(); let contents_str = contents.as_str();
let properties = hashmap! { let properties = [("Value".to_owned(), contents_str.into())];
"Value".to_owned() => contents_str.into(),
};
let meta_path = path.with_file_name(format!("{}.meta.json", name)); let meta_path = path.with_file_name(format!("{}.meta.json", name));

View File

@@ -7,7 +7,6 @@
use std::{borrow::Cow, sync::Arc, time::Duration}; use std::{borrow::Cow, sync::Arc, time::Duration};
use hyper::{header, Body, Method, Request, Response, StatusCode}; use hyper::{header, Body, Method, Request, Response, StatusCode};
use maplit::hashmap;
use rbx_dom_weak::types::{Ref, Variant}; use rbx_dom_weak::types::{Ref, Variant};
use ritz::{html, Fragment, HtmlContent, HtmlSelfClosingTag}; use ritz::{html, Fragment, HtmlContent, HtmlSelfClosingTag};
@@ -296,11 +295,12 @@ impl<'a> ExpandableSection<'a> {
// support for conditional attributes like `checked`. // support for conditional attributes like `checked`.
let mut input = HtmlSelfClosingTag { let mut input = HtmlSelfClosingTag {
name: Cow::Borrowed("input"), name: Cow::Borrowed("input"),
attributes: hashmap! { attributes: [
Cow::Borrowed("class") => Cow::Borrowed("expandable-input"), (Cow::Borrowed("class"), Cow::Borrowed("expandable-input")),
Cow::Borrowed("id") => Cow::Owned(input_id.clone()), (Cow::Borrowed("id"), Cow::Owned(input_id.clone())),
Cow::Borrowed("type") => Cow::Borrowed("checkbox"), (Cow::Borrowed("type"), Cow::Borrowed("checkbox")),
}, ]
.into(),
}; };
if self.expanded { if self.expanded {