feat(status): relative path of obj

This commit is contained in:
grimhilt
2024-09-11 23:36:29 +02:00
parent e66dc8d408
commit 8f636b4bf7
6 changed files with 107 additions and 24 deletions

View File

@@ -66,6 +66,13 @@ impl ClientTest {
Config::from(Some(&self.volume))
}
pub fn new_config(&self, path: &str) -> Config {
let mut full_path = self.volume.clone();
full_path.push_str("/");
full_path.push_str(path);
Config::from(Some(&full_path))
}
pub fn ok(self) -> io::Result<()> {
fs::remove_dir_all(&self.volume)?;
Ok(())

View File

@@ -15,19 +15,35 @@ fn status_expected(config: &Config, staged: Vec<&str>, not_staged: Vec<&str>) {
assert_eq!(res.not_staged.len(), not_staged.len());
for obj in staged {
assert!(res
.staged
.iter()
.position(|e| { e.get_obj_path() == &PathBuf::from(obj) })
.is_some());
assert!(
res.staged
.iter()
.position(|e| {
e.get_env_relative_path(config.get_root_unsafe()) == PathBuf::from(obj)
})
.is_some(),
"{:?}",
res.staged
.iter()
.map(|e| { e.get_env_relative_path(config.get_root_unsafe()) })
.collect::<Vec<PathBuf>>()
);
}
for obj in not_staged {
assert!(res
.not_staged
.iter()
.position(|e| { e.get_obj_path() == &PathBuf::from(obj) })
.is_some());
assert!(
res.not_staged
.iter()
.position(|e| {
e.get_env_relative_path(config.get_root_unsafe()) == PathBuf::from(obj)
})
.is_some(),
"{:?}",
res.not_staged
.iter()
.map(|e| { e.get_env_relative_path(config.get_root_unsafe()) })
.collect::<Vec<PathBuf>>()
);
}
}
@@ -55,13 +71,16 @@ fn all_folder() -> io::Result<()> {
status_expected(&client.get_config(), vec![], vec!["foo", "dir"]);
client.exec_ok("add dir");
status_expected(&client.get_config(), vec!["dir/foo", "dir/bar"], vec!["foo"]);
status_expected(
&client.get_config(),
vec!["dir/foo", "dir/bar"],
vec!["foo"],
);
client.ok()
}
#[test]
#[ignore]
fn all_folder_current() -> io::Result<()> {
let mut client = ClientTest::new("status__all_folder_current").init();
@@ -73,9 +92,31 @@ fn all_folder_current() -> io::Result<()> {
client.exec_ok("add dir");
status_expected(
&Config::from(Some(&String::from("./dir"))),
vec!["foor", "bar"],
vec!["../foo"],
&client.new_config("dir"),
vec!["dir/foo", "dir/bar"],
vec![],
);
client.ok()
}
#[test]
#[ignore]
fn relative_path() -> io::Result<()> {
let mut client = ClientTest::new("status__all_folder_current").init();
client.add_dir("dir")?;
client.add_file("dir/foo", "foo")?;
client.add_file("dir/bar", "bar")?;
client.add_file("foor", "foor")?;
status_expected(&client.get_config(), vec![], vec!["foor", "dir"]);
client.exec_ok("add dir");
// client.set_execution_path("dir");
status_expected(
&client.new_config("dir"),
vec!["foo", "bar"],
vec!["../foor"],
);
client.ok()