-
-
Notifications
You must be signed in to change notification settings - Fork 257
/
invalid.rs
69 lines (62 loc) · 1.74 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
60
61
62
63
64
65
66
67
68
69
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_must_not_be_object_hash() {
for op in [Operation::Fetch, Operation::Push] {
assert!(matches!(
try_parse("^e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", op).unwrap_err(),
Error::NegativeObjectHash
));
}
}
#[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
));
}