-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for line range plus syntax #1810
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,16 @@ impl LineRange { | |
} | ||
2 => { | ||
new_range.lower = line_numbers[0].parse()?; | ||
new_range.upper = line_numbers[1].parse()?; | ||
|
||
new_range.upper = if line_numbers[1].bytes().next().unwrap() == b'+' { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the if line_numbers[1].bytes().next() == Some(b'+') { what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like using |
||
let more_lines = &line_numbers[1][1..] | ||
.parse() | ||
.map_err(|_| "Invalid line number after +")?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "invalid number after"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After a bit more thinking I changed it to "Invalid character after +". |
||
new_range.lower + more_lines | ||
} else { | ||
line_numbers[1].parse()? | ||
}; | ||
|
||
Ok(new_range) | ||
} | ||
_ => Err( | ||
|
@@ -100,6 +109,23 @@ fn test_parse_fail() { | |
assert!(range.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_parse_plus() { | ||
let range = LineRange::from("40:+10").expect("Shouldn't fail on test!"); | ||
assert_eq!(40, range.lower); | ||
assert_eq!(50, range.upper); | ||
} | ||
|
||
#[test] | ||
fn test_parse_plus_fail() { | ||
let range = LineRange::from("40:+z"); | ||
assert!(range.is_err()); | ||
let range = LineRange::from("40:+-10"); | ||
assert!(range.is_err()); | ||
let range = LineRange::from("40:+"); | ||
assert!(range.is_err()); | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq)] | ||
pub enum RangeCheckResult { | ||
// Within one of the given ranges | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
n:+delta
syntax?