Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn parse_params<I: Iterator<Item = OsString>>(mut opts: Peekable<I>) -> Resu
let mut format = None;
let mut context = None;
let tabsize_re = Regex::new(r"^--tabsize=(?<num>\d+)$").unwrap();
let width_re = Regex::new(r"--width=(?P<long>\d+)$").unwrap();
let width_re = Regex::new(r"^--width=(?P<long>\d+)$").unwrap();
while let Some(param) = opts.next() {
let next_param = opts.peek();
if param == "--" {
Expand Down Expand Up @@ -813,6 +813,56 @@ mod tests {
.is_err());
}
#[test]
fn width() {
assert_eq!(
Ok(Params {
executable: os("diff"),
from: os("foo"),
to: os("bar"),
width: 100,
..Default::default()
}),
parse_params(
[os("diff"), os("--width=100"), os("foo"), os("bar")]
.iter()
.cloned()
.peekable()
)
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a case for xyz--width=5 being an operand, since the PR changes that behavior

}
#[test]
fn width_suffix_is_an_operand() {
assert_eq!(
Ok(Params {
executable: os("diff"),
from: os("xyz--width=5"),
to: os("foo"),
..Default::default()
}),
parse_params(
[os("diff"), os("xyz--width=5"), os("foo")]
.iter()
.cloned()
.peekable()
)
);
}
#[cfg(unix)]
#[test]
fn width_non_utf8_is_not_an_option() {
use std::os::unix::ffi::OsStringExt;
// used to panic in into_string().unwrap()
let bad = OsString::from_vec(b"\xff--width=5".to_vec());
let params = parse_params(
[os("diff"), bad.clone(), os("foo")]
.iter()
.cloned()
.peekable(),
)
.unwrap();
assert_eq!(params.from, bad);
}
#[test]
fn double_dash() {
assert_eq!(
Ok(Params {
Expand Down
Loading