Extraction done from #53453 I removed the default Oid implementation we had and added support back for SHA264 back as well. I also removed the hex dependency and just added some of those functions we needed in house so we can avoid building yet another dependency Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - N/A
92 lines
2.6 KiB
Rust
92 lines
2.6 KiB
Rust
mod assertions;
|
|
mod marked_text;
|
|
|
|
pub use assertions::*;
|
|
pub use marked_text::*;
|
|
|
|
use std::ffi::OsStr;
|
|
use std::path::{Path, PathBuf};
|
|
use tempfile::TempDir;
|
|
|
|
pub struct TempTree {
|
|
_temp_dir: TempDir,
|
|
path: PathBuf,
|
|
}
|
|
|
|
impl TempTree {
|
|
pub fn new(tree: serde_json::Value) -> Self {
|
|
let dir = TempDir::new().unwrap();
|
|
let path = std::fs::canonicalize(dir.path()).unwrap();
|
|
write_tree(path.as_path(), tree);
|
|
|
|
Self {
|
|
_temp_dir: dir,
|
|
path,
|
|
}
|
|
}
|
|
|
|
pub fn path(&self) -> &Path {
|
|
self.path.as_path()
|
|
}
|
|
}
|
|
|
|
fn write_tree(path: &Path, tree: serde_json::Value) {
|
|
use serde_json::Value;
|
|
use std::fs;
|
|
|
|
if let Value::Object(map) = tree {
|
|
for (name, contents) in map {
|
|
let mut path = PathBuf::from(path);
|
|
path.push(name);
|
|
match contents {
|
|
Value::Object(_) => {
|
|
fs::create_dir(&path).unwrap();
|
|
|
|
#[cfg(not(target_family = "wasm"))]
|
|
#[allow(clippy::disallowed_methods)]
|
|
if path.file_name() == Some(OsStr::new(".git")) {
|
|
let output = std::process::Command::new("git")
|
|
.args(["init", "-b", "main"])
|
|
.current_dir(path.parent().unwrap())
|
|
.env("GIT_CONFIG_GLOBAL", "")
|
|
.env("GIT_CONFIG_SYSTEM", "")
|
|
.output()
|
|
.expect("failed to init git repo");
|
|
assert!(
|
|
output.status.success(),
|
|
"git init failed: {}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
}
|
|
|
|
write_tree(&path, contents);
|
|
}
|
|
Value::Null => {
|
|
fs::create_dir(&path).unwrap();
|
|
}
|
|
Value::String(contents) => {
|
|
fs::write(&path, contents).unwrap();
|
|
}
|
|
_ => {
|
|
panic!("JSON object must contain only objects, strings, or null");
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
panic!("You must pass a JSON object to this helper")
|
|
}
|
|
}
|
|
|
|
pub fn sample_text(rows: usize, cols: usize, start_char: char) -> String {
|
|
let mut text = String::new();
|
|
for row in 0..rows {
|
|
let c: char = (start_char as u32 + row as u32) as u8 as char;
|
|
let mut line = c.to_string().repeat(cols);
|
|
if row < rows - 1 {
|
|
line.push('\n');
|
|
}
|
|
text += &line;
|
|
}
|
|
text
|
|
}
|