Skip to content
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

Fix fast lane delimiter detection #130

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion src/fast_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl TryFrom<&Opt> for FastOpt {
type Error = &'static str;

fn try_from(value: &Opt) -> Result<Self, Self::Error> {
if !value.delimiter.as_bytes().len() == 1 {
if value.delimiter.as_bytes().len() != 1 {
return Err("Delimiter must be 1 byte wide for FastOpt");
}

Expand Down Expand Up @@ -307,6 +307,20 @@ mod tests {
assert_eq!(output, b"foo\n".as_slice());
}

#[test]
fn fail_to_convert_opt_with_long_delimiter_to_fastopt() {
let opt = Opt {
delimiter: "foo".to_owned(),
..Default::default()
};

assert!(FastOpt::try_from(&opt).is_err());
assert_eq!(
FastOpt::try_from(&opt).unwrap_err(),
"Delimiter must be 1 byte wide for FastOpt"
);
}

fn make_cut_str_buffers() -> (Vec<u8>, Vec<Range<usize>>) {
let output = Vec::new();
let fields = Vec::new();
Expand Down
12 changes: 12 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ fn it_cut_consecutive_delimiters() {
assert.success().stdout("foobar\n");
}

#[test]
fn it_cut_using_multibyte_delimiters() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();

let assert = cmd
.args(["-d", "...", "-f", "2"])
.write_stdin("foo...bar")
.assert();

assert.success().stdout("bar\n");
}

#[test]
fn it_works_on_multiple_lines() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
Expand Down
Loading