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_expected(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_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::>() ); } for obj in not_staged { 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::>() ); } } #[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] #[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() } #[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