Skip to content

Commit

Permalink
Tiny steps towards understanding rev-parsing better (#427)
Browse files Browse the repository at this point in the history
They parse it backwards, which we most certainly won't do though.
  • Loading branch information
Byron committed May 29, 2022
1 parent f54ad38 commit 221252c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 8 additions & 7 deletions git-revision/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ impl Default for Kind {

pub mod parse {
#![allow(missing_docs)]
use bstr::BStr;
use bstr::{BStr, BString};

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("A portion of the input could not be parsed: {:?}", .input)]
UnconsumedInput { input: BString },
#[error("The delegate didn't indicate success - check delegate for more information")]
Delegate,
}
Expand Down Expand Up @@ -77,12 +79,11 @@ pub mod parse {
}
input = revision(input, delegate)?;

assert!(
input.is_empty(),
"BUG: we must parse all of our input or fail gracefully: {:?}",
input
);
Ok(())
if input.is_empty() {
Ok(())
} else {
Err(Error::UnconsumedInput { input: input.into() })
}
}

fn try_range(input: &BStr) -> Option<(&[u8], spec::Kind)> {
Expand Down
17 changes: 16 additions & 1 deletion git-revision/tests/spec/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn all_characters_are_taken_verbatim_which_includes_whitespace() {
}

mod revision {
use crate::spec::parse::parse;
use crate::spec::parse::{parse, try_parse_opts};

#[test]
fn at_by_iteself_is_shortcut_for_head() {
Expand All @@ -99,6 +99,13 @@ mod revision {
assert_eq!(rec.resolve_ref_input.unwrap(), "HEAD");
}

#[test]
#[ignore]
fn lonely_at_after_ref_is_invalid() {
let _err = try_parse_opts("HEAD@", Default::default()).unwrap_err();
// TODO: assertion
}

#[test]
fn refname_head() {
let rec = parse("HEAD");
Expand All @@ -113,6 +120,14 @@ mod revision {
assert!(rec.kind.is_none());
assert_eq!(rec.resolve_ref_input.unwrap(), "HEADfake");
}

#[test]
#[ignore]
fn full_head_ref_name() {
let rec = parse("refs/heads/main");
assert!(rec.kind.is_none());
assert_eq!(rec.resolve_ref_input.unwrap(), "refs/heads/main");
}
}

mod range {
Expand Down

0 comments on commit 221252c

Please sign in to comment.