-
-
Notifications
You must be signed in to change notification settings - Fork 260
/
mod.rs
49 lines (43 loc) · 1.27 KB
/
mod.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
mod parse {
use git_object::bstr::{BStr, BString};
use git_revision::spec;
#[derive(Default, Debug)]
struct Recorder {
resolve_ref_input: Option<BString>,
}
impl spec::parse::Delegate for Recorder {
fn resolve_ref(&mut self, input: &BStr) -> Option<()> {
assert!(
self.resolve_ref_input.is_none(),
"called resolve_ref twice with '{}'",
input
);
self.resolve_ref_input = input.to_owned().into();
Some(())
}
fn find_by_prefix(&mut self, _input: &BStr) -> Option<()> {
todo!()
}
fn nth_ancestor(&mut self, _n: usize) -> Option<()> {
todo!()
}
fn nth_parent(&mut self, _n: usize) -> Option<()> {
todo!()
}
}
fn b(s: &str) -> &BStr {
s.into()
}
#[test]
fn at_alone_is_shortcut_for_head() {
let mut rec = Recorder::default();
spec::parse(b("@"), &mut rec).unwrap();
assert_eq!(rec.resolve_ref_input.unwrap(), "HEAD");
}
#[test]
fn refname() {
let mut rec = Recorder::default();
spec::parse(b("HEAD"), &mut rec).unwrap();
assert_eq!(rec.resolve_ref_input.unwrap(), "HEAD");
}
}