|
| 1 | +use crate::parse::try_parse; |
| 2 | +use git_refspec::{parse::Error, Operation}; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn empty() { |
| 6 | + assert!(matches!(try_parse("", Operation::Push).unwrap_err(), Error::Empty)); |
| 7 | +} |
| 8 | + |
| 9 | +#[test] |
| 10 | +fn negative_must_not_be_empty() { |
| 11 | + for op in [Operation::Fetch, Operation::Push] { |
| 12 | + assert!(matches!(try_parse("^", op).unwrap_err(), Error::NegativeEmpty)); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +#[test] |
| 17 | +fn negative_with_destination() { |
| 18 | + for op in [Operation::Fetch, Operation::Push] { |
| 19 | + for spec in ["^a:b", "^a:", "^:", "^:b"] { |
| 20 | + assert!(matches!( |
| 21 | + try_parse(spec, op).unwrap_err(), |
| 22 | + Error::NegativeWithDestination |
| 23 | + )); |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +#[test] |
| 29 | +fn complex_patterns_with_more_than_one_asterisk() { |
| 30 | + for op in [Operation::Fetch, Operation::Push] { |
| 31 | + for spec in ["^*/*", "a/*/c/*", "a**:**b", "+:**/"] { |
| 32 | + assert!(matches!( |
| 33 | + try_parse(spec, op).unwrap_err(), |
| 34 | + Error::PatternUnsupported { .. } |
| 35 | + )); |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +#[test] |
| 41 | +fn both_sides_need_pattern_if_one_uses_it() { |
| 42 | + for op in [Operation::Fetch, Operation::Push] { |
| 43 | + for spec in ["refs/*/a", ":a/*", "+:a/*", "a*:b/c", "a:b/*"] { |
| 44 | + assert!( |
| 45 | + matches!(try_parse(spec, op).unwrap_err(), Error::PatternUnbalanced), |
| 46 | + "{}", |
| 47 | + spec |
| 48 | + ); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +#[test] |
| 54 | +fn push_to_empty() { |
| 55 | + assert!(matches!( |
| 56 | + try_parse("HEAD:", Operation::Push).unwrap_err(), |
| 57 | + Error::PushToEmpty |
| 58 | + )); |
| 59 | +} |
0 commit comments