106 lines
2.7 KiB
Rust
106 lines
2.7 KiB
Rust
mod common;
|
|
|
|
use common::client::ClientTest;
|
|
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 status_exepected(config: &Config, staged: Vec<&str>, not_staged: Vec<&str>) {
|
|
let res = get_obj_changes(&DEFAULT_STATUS_ARG, config);
|
|
|
|
assert_eq!(res.staged.len(), staged.len());
|
|
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());
|
|
}
|
|
|
|
for obj in not_staged {
|
|
assert!(res
|
|
.not_staged
|
|
.iter()
|
|
.position(|e| { e.get_obj_path() == &PathBuf::from(obj) })
|
|
.is_some());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn simple_file() -> io::Result<()> {
|
|
let mut client = ClientTest::new("status__simple_file").init();
|
|
|
|
client.add_file("foo", "foo")?;
|
|
status_exepected(&client.get_config(), vec![], vec!["foo"]);
|
|
|
|
client.exec_ok("add foo");
|
|
status_exepected(&client.get_config(), vec!["foo"], vec![]);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
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_exepected(&client.get_config(), vec![], vec!["foo", "dir"]);
|
|
|
|
client.exec_ok("add dir");
|
|
status_exepected(&client.get_config(), vec!["dir"], vec!["foo"]);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
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_exepected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
|
|
|
client.exec_ok("add dir");
|
|
status_exepected(
|
|
&Config::from(Some(&String::from("./dir"))),
|
|
vec!["foor", "bar"],
|
|
vec!["../foo"],
|
|
);
|
|
|
|
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_exepected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
|
|
|
client.exec_ok("add dir/foo");
|
|
status_exepected(
|
|
&client.get_config(),
|
|
vec!["dir/foo"],
|
|
vec!["foor", "dir/bar"],
|
|
);
|
|
|
|
client.ok()
|
|
}
|
|
|
|
// ../folder/file add
|