Raise an explicit panic when context_lines is 0. Fixes #37
This commit is contained in:
parent
3c784d6e9d
commit
3a938ae1d3
3 changed files with 13 additions and 1 deletions
|
|
@ -101,6 +101,8 @@ pub fn get_diff_ratio(ops: &[DiffOp], old_len: usize, new_len: usize) -> f32 {
|
|||
/// This will leave holes behind in long periods of equal ranges so that
|
||||
/// you can build things like unified diffs.
|
||||
pub fn group_diff_ops(mut ops: Vec<DiffOp>, n: usize) -> Vec<Vec<DiffOp>> {
|
||||
assert!(n > 0, "n must be 1 or larger");
|
||||
|
||||
if ops.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -758,3 +758,12 @@ fn test_serde_ops() {
|
|||
let json = serde_json::to_string_pretty(&changes).unwrap();
|
||||
insta::assert_snapshot!(&json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic = "n must be 1 or larger"]
|
||||
fn test_regression_issue_37() {
|
||||
let config = TextDiffConfig::default();
|
||||
let diff = config.diff_lines("", "");
|
||||
let mut output = diff.unified_diff();
|
||||
output.context_radius(0).to_string();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,8 @@ impl<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> UnifiedDiff<'diff, 'old,
|
|||
/// Changes the context radius.
|
||||
///
|
||||
/// The context radius is the number of lines between changes that should
|
||||
/// be emitted. This defaults to `3`.
|
||||
/// be emitted. This defaults to `3`. This value must be one or larger or
|
||||
/// creating the diff will panic.
|
||||
pub fn context_radius(&mut self, n: usize) -> &mut Self {
|
||||
self.context_radius = n;
|
||||
self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue