use super::*;
fn arguments(words: &[&str]) -> Vec<OsString> {
return words.iter().map(OsString::from).collect();
}
fn strings(words: &[&str]) -> Vec<String> {
return words.iter().map(|word| { return (*word).to_string(); }).collect();
}
#[test]
fn parents_come_from_the_header_block_in_order() {
let merge: &[u8] = b"tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\nparent 1111\nparent 2222\nauthor A <a@b> 1 +0000\n\nparent 3333\n";
assert_eq!(parents_of(merge), strings(&["1111", "2222"]));
let root: &[u8] = b"tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\nauthor A <a@b> 1 +0000\n\nparent 9999\n";
assert_eq!(parents_of(root), Vec::<String>::new());
}
#[test]
fn named_paths_and_the_separator_are_left_out_for_git() {
let (globals, commit) = private_invocation(
&arguments(&["commit", "--only", "-m", "subject", "--", "a.txt", "dir/b.txt"]),
&strings(&["a.txt", "dir/b.txt"]),
TransactionMode::ExplicitPath,
false,
false,
);
assert!(globals.is_empty());
assert_eq!(commit, strings(&["-m", "subject"]));
}
#[test]
fn global_options_that_redirect_git_are_dropped() {
let (globals, commit) = private_invocation(
&arguments(&["-C", "/elsewhere", "-c", "core.editor=true", "commit", "-S", "-m", "signed"]),
&[],
TransactionMode::Index,
false,
false,
);
assert_eq!(globals, strings(&["-c", "core.editor=true"]));
assert_eq!(commit, strings(&["-S", "-m", "signed"]));
}
#[test]
fn a_selection_the_private_index_holds_is_not_given_to_git_again() {
let line: Vec<OsString> = arguments(&["commit", "-i", "-m", "all", "--pathspec-from-file=list", "--pathspec-file-nul", "--", "a.txt"]);
assert_eq!(private_invocation(&line, &strings(&["a.txt"]), TransactionMode::Index, false, true).1, strings(&["-m", "all"]));
let patch: Vec<OsString> = arguments(&["commit", "--patch", "-m", "p"]);
assert_eq!(private_invocation(&patch, &[], TransactionMode::Index, false, true).1, strings(&["-m", "p"]));
assert_eq!(private_invocation(&patch, &[], TransactionMode::Index, false, false).1, strings(&["--patch", "-m", "p"]));
}
#[test]
fn commit_all_is_removed_only_when_the_index_already_holds_it() {
let line: Vec<OsString> = arguments(&["commit", "-am", "all"]);
assert_eq!(private_invocation(&line, &[], TransactionMode::Index, true, false).1, strings(&["-m", "all"]));
assert_eq!(private_invocation(&line, &[], TransactionMode::Index, false, false).1, strings(&["-am", "all"]));
}