Skip to content

Commit

Permalink
chore: added test cases for diff parser bugs
Browse files Browse the repository at this point in the history
This commit adds new test cases to the diff parser to catch some
bugs we've identified.

Signed-of-by: Julian Lanson <[email protected]>
  • Loading branch information
j-lanson authored and alilleybrinker committed Nov 5, 2024
1 parent be226d7 commit 6e99222
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions plugins/git/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,18 @@ mod test {
let (leftover, _parsed) = crate::parse::patch(input).unwrap();
assert!(leftover.is_empty());
}

#[test]
fn test_hyphens_in_diff_stats() {
let input = "0\t4\tsite/content/_index.md\n136\t2\tsite/content/install/_index.md\n-\t-\tsite/static/images/homepage-bg.png\n2\t2\tsite/tailwind.config.js\n2\t0\tsite/templates/bases/base.tera.html\n82\t1\tsite/templates/index.html\n3\t3\tsite/templates/shortcodes/info.html\n15\t14\txtask/src/task/site/serve.rs";
let (leftover, _) = crate::parse::stats(input).unwrap();
assert!(leftover.is_empty());
}

#[test]
fn test_patch_with_only_meta() {
let input = "diff --git a/hipcheck/src/analysis/session/spdx.rs b/hipcheck/src/session/spdx.rs\nsimilarity index 100%\nrename from hipcheck/src/analysis/session/spdx.rs\nrename to hipcheck/src/session/spdx.rs\n";
let (leftover, _) = crate::parse::patch(input).unwrap();
assert!(leftover.is_empty());
}
}
6 changes: 3 additions & 3 deletions plugins/git/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ fn stat(input: &str) -> IResult<&str, Stat<'_>> {
)
}

fn stats(input: &str) -> IResult<&str, Vec<Stat<'_>>> {
pub(crate) fn stats(input: &str) -> IResult<&str, Vec<Stat<'_>>> {
many0(stat)(input)
}

fn diff(input: &str) -> IResult<&str, Diff> {
pub(crate) fn diff(input: &str) -> IResult<&str, Diff> {
log::trace!("input is {:#?}", input);
tuple((stats, line, patches))(input).map(|(i, (stats, _, patches))| {
log::trace!("patches are {:#?}", patches);
Expand Down Expand Up @@ -238,7 +238,7 @@ fn gh_diff(input: &str) -> IResult<&str, Diff> {
})
}

fn diffs(input: &str) -> IResult<&str, Vec<Diff>> {
pub(crate) fn diffs(input: &str) -> IResult<&str, Vec<Diff>> {
many0(diff)(input)
}

Expand Down

0 comments on commit 6e99222

Please sign in to comment.