136 lines
3.5 KiB
Rust
136 lines
3.5 KiB
Rust
mod common;
|
|
|
|
use common::client::ClientTest;
|
|
use nextsync::store::object::Obj;
|
|
use nextsync::commands::status::{get_obj_changes, StatusArgs};
|
|
use nextsync::config::config::Config;
|
|
use std::io;
|
|
use std::path::PathBuf;
|
|
|
|
const DEFAULT_STATUS_ARG: StatusArgs = StatusArgs { nostyle: false };
|
|
|
|
fn compare_vect(vec1: Vec<Obj>, vec2: Vec<&str>, config: &Config) {
|
|
for obj in vec2 {
|
|
assert!(
|
|
vec1.iter()
|
|
.position(|e| {
|
|
e.get_env_relative_path(config.get_root_unsafe()) == PathBuf::from(obj)
|
|
})
|
|
.is_some(),
|
|
"{:?}",
|
|
vec1.iter()
|
|
.map(|e| { e.get_env_relative_path(config.get_root_unsafe()) })
|
|
.collect::<Vec<PathBuf>>()
|
|
);
|
|
}
|
|
}
|
|
|
|
fn status_expected(config: &Config, staged: Vec<&str>, not_staged: Vec<&str>) {
|
|
let res = get_obj_changes(config);
|
|
|
|
assert_eq!(res.staged.len(), staged.len());
|
|
assert_eq!(res.not_staged.len(), not_staged.len());
|
|
|
|
compare_vect(res.staged, staged, &config);
|
|
compare_vect(res.not_staged, not_staged, &config);
|
|
}
|
|
|
|
#[test]
|
|
fn simple_file() -> io::Result<()> {
|
|
let mut client = ClientTest::new("status__simple_file").init();
|
|
|
|
client.add_file("foo", "foo")?;
|
|
status_expected(&client.get_config(), vec![], vec!["foo"]);
|
|
|
|
client.exec_ok("add foo");
|
|
status_expected(&client.get_config(), vec!["foo"], vec![]);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
#[test]
|
|
fn all_folder() -> io::Result<()> {
|
|
let mut client = ClientTest::new("status__all_folder").init();
|
|
|
|
client.add_dir("dir")?;
|
|
client.add_file("dir/foo", "foo")?;
|
|
client.add_file("dir/bar", "bar")?;
|
|
client.add_file("foo", "foo")?;
|
|
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"],
|
|
);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
#[test]
|
|
fn all_folder_current() -> 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");
|
|
status_expected(
|
|
&client.new_config("dir"),
|
|
vec!["dir/foo", "dir/bar"],
|
|
vec![],
|
|
);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
#[test]
|
|
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.get_config(),
|
|
vec!["foo", "bar"],
|
|
vec!["../foor"],
|
|
);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
#[test]
|
|
fn part_of_folder() -> io::Result<()> {
|
|
let mut client = ClientTest::new("status__part_of_folder").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/foo");
|
|
status_expected(
|
|
&client.get_config(),
|
|
vec!["dir/foo"],
|
|
vec!["foor", "dir/bar"],
|
|
);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
// ../folder/file add
|
|
// force add ignored file
|
|
// status without ignored file
|
|
// all folder without ignored file
|