diff --git a/examples/multipos.rs b/examples/multipos.rs index b76bf8e..953829d 100644 --- a/examples/multipos.rs +++ b/examples/multipos.rs @@ -40,7 +40,7 @@ fn main() { 0 => println!("Debug mode is off"), 1 => println!("Debug mode is kind of on"), 2 => println!("Debug mode is on"), - 3 | 4 | 5 => println!("too much dude !"), + 3 ..= 5 => println!("too much dude !"), _ => println!("Don't be crazy"), } diff --git a/src/parse.rs b/src/parse.rs index fbe5569..92c072e 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,4 +1,3 @@ - use super::{Columns, Column}; use anyhow::{anyhow, Result}; use regex::Regex; @@ -23,7 +22,7 @@ impl<'a> InputText<'a> { pub fn new(raw: &'a str, sep: &str) -> Self { InputText { - raw: raw.into(), + raw, sep: sep.into() } } @@ -45,6 +44,10 @@ impl<'a> InputText<'a> { pub fn len(self) -> usize { self.raw.len() } + + pub fn is_empty(self) -> bool { + self.raw.is_empty() + } } /// Return the number of columns given input text and a separator @@ -58,7 +61,7 @@ pub fn n_columns(text: &str, sep: &str) -> Result { // count number of columns match lines.first() { Some(line) => Ok(re.split(line).count()), - None => return Err(anyhow!("no lines left")), + None => Err(anyhow!("no lines left")), } } @@ -98,7 +101,6 @@ pub fn split_columns(text: &str, sep: &str) -> Result { mod tests { use super::*; use crate::DEFAULT_SEP_PATTERN; - use regex::Regex; use std::error::Error; type TestResult = Result<(), Box>; @@ -136,13 +138,13 @@ file with space\ttitle 4\textra } // #[test] - fn test_re_split() { - let text = "this is two tabs"; - let re = Regex::new(r"[\t]+").unwrap(); - let fields: Vec<&str> = re.split(text).collect(); - eprintln!("{:?}", fields); - assert!(false); - } + // fn test_re_split() { + // let text = "this is two tabs"; + // let re = Regex::new(r"[\t]+").unwrap(); + // let fields: Vec<&str> = re.split(text).collect(); + // eprintln!("{:?}", fields); + // assert!(false); + // } #[test] fn test_columns_from_str() { diff --git a/src/stdin.rs b/src/stdin.rs index d7f0c1b..23eb08a 100644 --- a/src/stdin.rs +++ b/src/stdin.rs @@ -6,7 +6,7 @@ use std::io::{BufReader, self, Read}; // TODO: make as iterator, avoid loading all stdin to memroy pub fn read_stdin() -> Result> { let mut r = BufReader::new(io::stdin()); - let mut buf = Box::new(String::new()); + let mut buf = Box::::default(); r.read_to_string(&mut buf)?; Ok(buf) } diff --git a/tests/cli.rs b/tests/cli.rs index 2843d28..c3ba37b 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -56,7 +56,7 @@ fn fail_yargs_mismatch1() -> TestResult { let mut cmd = Command::cargo_bin("yargs").unwrap(); let assert = cmd - .args(&["one", "two"]) + .args(["one", "two"]) .pipe_stdin(input)? .assert(); assert.failure(); @@ -67,8 +67,8 @@ fn fail_yargs_mismatch1() -> TestResult { #[test] fn cli_pass2() { let mut cmd = Command::cargo_bin("yargs").unwrap(); - cmd.args(&["-d", r"\s"]) - .args(&["1", "2", "3", "4", "5", "6"]); + cmd.args(["-d", r"\s"]) + .args(["1", "2", "3", "4", "5", "6"]); run_command("tests/inputs/input1", &mut cmd).unwrap() .success(); } @@ -79,8 +79,8 @@ fn cli_pass2() { // delimiter: space fn cli_fail1() { let mut cmd = Command::cargo_bin("yargs").unwrap(); - cmd.args(&["-d", r"\s"]) - .args(&["1", "2", "3", "4", "5", "6", "7", "8"]); + cmd.args(["-d", r"\s"]) + .args(["1", "2", "3", "4", "5", "6", "7", "8"]); run_command("tests/inputs/input1", &mut cmd).unwrap() .failure(); }