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