Skip to content

Commit

Permalink
support for range parsing with range in the middle (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed May 29, 2022
1 parent 8069ad9 commit 98f1d19
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions git-revision/src/lib.rs
@@ -1,8 +1,8 @@
//! Interact with git revisions by parsing them from rev-specs and turning them into rev-specs.
//!
//! One can also describe revisions using a different algorithm.
#![forbid(unsafe_code, rust_2018_idioms)]
#![deny(missing_docs)]
#![forbid(unsafe_code)]
#![deny(missing_docs, rust_2018_idioms)]

/// Access to collections optimized for keys that are already a hash.
pub use hash_hasher;
Expand Down
1 change: 1 addition & 0 deletions git-revision/src/spec.rs
Expand Up @@ -74,6 +74,7 @@ pub mod parse {
delegate.kind(kind);
input = rest.as_bstr();
}
input = revision(input, delegate)?;

assert!(
input.is_empty(),
Expand Down
30 changes: 24 additions & 6 deletions git-revision/tests/spec/mod.rs
Expand Up @@ -5,17 +5,19 @@ mod parse {
#[derive(Default, Debug)]
struct Recorder {
resolve_ref_input: Option<BString>,
resolve_ref_input2: Option<BString>,
kind: Option<spec::Kind>,
calls: usize,
}
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();
if self.resolve_ref_input.is_none() {
self.resolve_ref_input = input.to_owned().into();
} else if self.resolve_ref_input2.is_none() {
self.resolve_ref_input2 = input.to_owned().into();
} else {
panic!("called resolve_ref more than twice with '{}'", input);
}
self.calls += 1;
Some(())
}
Expand Down Expand Up @@ -85,6 +87,22 @@ mod parse {
assert_eq!(rec.resolve_ref_input.unwrap(), "HEAD");
}

#[test]
fn middle_dot_dot_dot_is_merge_base() {
let rec = parse("HEAD...@");
assert_eq!(rec.kind.unwrap(), spec::Kind::MergeBase);
assert_eq!(rec.resolve_ref_input.unwrap(), "HEAD");
assert_eq!(rec.resolve_ref_input2.unwrap(), "HEAD");
}

#[test]
fn middle_dot_dot_is_range() {
let rec = parse("@..HEAD");
assert_eq!(rec.kind.unwrap(), spec::Kind::Range);
assert_eq!(rec.resolve_ref_input.unwrap(), "HEAD");
assert_eq!(rec.resolve_ref_input2.unwrap(), "HEAD");
}

#[test]
fn at_by_iteself_is_shortcut_for_head() {
let rec = parse("@");
Expand Down

0 comments on commit 98f1d19

Please sign in to comment.