summaryrefslogtreecommitdiff
path: root/test_util/src/fs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test_util/src/fs.rs')
-rw-r--r--test_util/src/fs.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/test_util/src/fs.rs b/test_util/src/fs.rs
index 2a64fb9c4..005c467a6 100644
--- a/test_util/src/fs.rs
+++ b/test_util/src/fs.rs
@@ -10,6 +10,8 @@ use std::sync::Arc;
use anyhow::Context;
use lsp_types::Url;
+use serde::de::DeserializeOwned;
+use serde::Serialize;
use crate::assertions::assert_wildcard_match;
@@ -110,6 +112,10 @@ impl PathRef {
.with_context(|| format!("Could not read file: {}", self))
}
+ pub fn read_json<TValue: DeserializeOwned>(&self) -> TValue {
+ serde_json::from_str(&self.read_to_string()).unwrap()
+ }
+
pub fn rename(&self, to: impl AsRef<Path>) {
fs::rename(self, self.join(to)).unwrap();
}
@@ -118,6 +124,11 @@ impl PathRef {
fs::write(self, text.as_ref()).unwrap();
}
+ pub fn write_json<TValue: Serialize>(&self, value: &TValue) {
+ let text = serde_json::to_string_pretty(value).unwrap();
+ self.write(text);
+ }
+
pub fn symlink_dir(
&self,
oldpath: impl AsRef<Path>,