Skip to content

Commit

Permalink
tests causing all instrucitons (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 6, 2022
1 parent c4499ce commit c23a21d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
7 changes: 7 additions & 0 deletions git-refspec/src/spec.rs
Expand Up @@ -17,6 +17,13 @@ impl RefSpecRef<'_> {
match self.op {
Operation::Fetch => match (self.mode, self.src, self.dst) {
(Mode::Normal | Mode::Force, Some(src), None) => Instruction::Fetch(Fetch::Only { src }),
(Mode::Normal | Mode::Force, Some(src), Some(dst)) if has_pattern(src) => {
Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob {
src,
dst,
allow_non_fast_forward: matches!(self.mode, Mode::Force),
})
}
(Mode::Normal | Mode::Force, Some(src), Some(dst)) => Instruction::Fetch(Fetch::AndUpdateSingle {
src,
dst,
Expand Down
86 changes: 85 additions & 1 deletion git-refspec/tests/parse/mod.rs
Expand Up @@ -31,7 +31,11 @@ fn baseline() {
let res = catch_unwind(|| try_parse(spec.to_str().unwrap(), op));
match res {
Ok(res) => match (res.is_ok(), err_code == 0) {
(true, true) | (false, false) => {}
(true, true) | (false, false) => {
if let Ok(spec) = res {
spec.instruction(); // should not panic
}
}
_ => {
eprintln!("{err_code} {res:?} {} {:?}", kind.as_bstr(), spec.as_bstr());
mismatch += 1;
Expand Down Expand Up @@ -132,6 +136,46 @@ mod fetch {
);
}

#[test]
fn lhs_colon_rhs_updates_single_ref() {
assert_parse(
"a:b",
Instruction::Fetch(Fetch::AndUpdateSingle {
src: b("a"),
dst: b("b"),
allow_non_fast_forward: false,
}),
);
assert_parse(
"+a:b",
Instruction::Fetch(Fetch::AndUpdateSingle {
src: b("a"),
dst: b("b"),
allow_non_fast_forward: true,
}),
);
}

#[test]
fn lhs_colon_rhs_with_glob_updates_multiple_refs() {
assert_parse(
"a/*:b/*",
Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob {
src: b("a/*"),
dst: b("b/*"),
allow_non_fast_forward: false,
}),
);
assert_parse(
"+a/*:b/*",
Instruction::Fetch(Fetch::AndUpdateMultipleWithGlob {
src: b("a/*"),
dst: b("b/*"),
allow_non_fast_forward: true,
}),
);
}

#[test]
fn empty_lhs_colon_rhs_fetches_head_to_destination() {
assert_parse(
Expand Down Expand Up @@ -180,6 +224,46 @@ mod push {
assert_parse("^a*", Instruction::Push(Push::ExcludeMultipleWithGlob { src: b("a*") }));
}

#[test]
fn lhs_colon_rhs_pushes_single_ref() {
assert_parse(
"a:b",
Instruction::Push(Push::Single {
src: b("a"),
dst: b("b"),
allow_non_fast_forward: false,
}),
);
assert_parse(
"+a:b",
Instruction::Push(Push::Single {
src: b("a"),
dst: b("b"),
allow_non_fast_forward: true,
}),
);
}

#[test]
fn lhs_colon_rhs_with_glob_pushes_multiple_refs() {
assert_parse(
"a/*:b/*",
Instruction::Push(Push::MultipleWithGlob {
src: b("a/*"),
dst: b("b/*"),
allow_non_fast_forward: false,
}),
);
assert_parse(
"+a/*:b/*",
Instruction::Push(Push::MultipleWithGlob {
src: b("a/*"),
dst: b("b/*"),
allow_non_fast_forward: true,
}),
);
}

#[test]
fn colon_alone_is_for_pushing_matching_refs() {
assert_parse(
Expand Down

0 comments on commit c23a21d

Please sign in to comment.