lint / clippy

main
blob42 8 months ago
parent 1583b06fb9
commit 5c5c8875fa

@ -40,7 +40,7 @@ fn main() {
0 => println!("Debug mode is off"), 0 => println!("Debug mode is off"),
1 => println!("Debug mode is kind of on"), 1 => println!("Debug mode is kind of on"),
2 => println!("Debug mode is 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"), _ => println!("Don't be crazy"),
} }

@ -1,4 +1,3 @@
use super::{Columns, Column}; use super::{Columns, Column};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use regex::Regex; use regex::Regex;
@ -23,7 +22,7 @@ impl<'a> InputText<'a> {
pub fn new(raw: &'a str, sep: &str) -> Self { pub fn new(raw: &'a str, sep: &str) -> Self {
InputText { InputText {
raw: raw.into(), raw,
sep: sep.into() sep: sep.into()
} }
} }
@ -45,6 +44,10 @@ impl<'a> InputText<'a> {
pub fn len(self) -> usize { pub fn len(self) -> usize {
self.raw.len() self.raw.len()
} }
pub fn is_empty(self) -> bool {
self.raw.is_empty()
}
} }
/// Return the number of columns given input text and a separator /// Return the number of columns given input text and a separator
@ -58,7 +61,7 @@ pub fn n_columns(text: &str, sep: &str) -> Result<usize> {
// count number of columns // count number of columns
match lines.first() { match lines.first() {
Some(line) => Ok(re.split(line).count()), 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<Columns> {
mod tests { mod tests {
use super::*; use super::*;
use crate::DEFAULT_SEP_PATTERN; use crate::DEFAULT_SEP_PATTERN;
use regex::Regex;
use std::error::Error; use std::error::Error;
type TestResult = Result<(), Box<dyn Error>>; type TestResult = Result<(), Box<dyn Error>>;
@ -136,13 +138,13 @@ file with space\ttitle 4\textra
} }
// #[test] // #[test]
fn test_re_split() { // fn test_re_split() {
let text = "this is two tabs"; // let text = "this is two tabs";
let re = Regex::new(r"[\t]+").unwrap(); // let re = Regex::new(r"[\t]+").unwrap();
let fields: Vec<&str> = re.split(text).collect(); // let fields: Vec<&str> = re.split(text).collect();
eprintln!("{:?}", fields); // eprintln!("{:?}", fields);
assert!(false); // assert!(false);
} // }
#[test] #[test]
fn test_columns_from_str() { fn test_columns_from_str() {

@ -6,7 +6,7 @@ use std::io::{BufReader, self, Read};
// TODO: make as iterator, avoid loading all stdin to memroy // TODO: make as iterator, avoid loading all stdin to memroy
pub fn read_stdin() -> Result<Box<String>> { pub fn read_stdin() -> Result<Box<String>> {
let mut r = BufReader::new(io::stdin()); let mut r = BufReader::new(io::stdin());
let mut buf = Box::new(String::new()); let mut buf = Box::<String>::default();
r.read_to_string(&mut buf)?; r.read_to_string(&mut buf)?;
Ok(buf) Ok(buf)
} }

@ -56,7 +56,7 @@ fn fail_yargs_mismatch1() -> TestResult {
let mut cmd = Command::cargo_bin("yargs").unwrap(); let mut cmd = Command::cargo_bin("yargs").unwrap();
let assert = cmd let assert = cmd
.args(&["one", "two"]) .args(["one", "two"])
.pipe_stdin(input)? .pipe_stdin(input)?
.assert(); .assert();
assert.failure(); assert.failure();
@ -67,8 +67,8 @@ fn fail_yargs_mismatch1() -> TestResult {
#[test] #[test]
fn cli_pass2() { fn cli_pass2() {
let mut cmd = Command::cargo_bin("yargs").unwrap(); let mut cmd = Command::cargo_bin("yargs").unwrap();
cmd.args(&["-d", r"\s"]) cmd.args(["-d", r"\s"])
.args(&["1", "2", "3", "4", "5", "6"]); .args(["1", "2", "3", "4", "5", "6"]);
run_command("tests/inputs/input1", &mut cmd).unwrap() run_command("tests/inputs/input1", &mut cmd).unwrap()
.success(); .success();
} }
@ -79,8 +79,8 @@ fn cli_pass2() {
// delimiter: space // delimiter: space
fn cli_fail1() { fn cli_fail1() {
let mut cmd = Command::cargo_bin("yargs").unwrap(); let mut cmd = Command::cargo_bin("yargs").unwrap();
cmd.args(&["-d", r"\s"]) cmd.args(["-d", r"\s"])
.args(&["1", "2", "3", "4", "5", "6", "7", "8"]); .args(["1", "2", "3", "4", "5", "6", "7", "8"]);
run_command("tests/inputs/input1", &mut cmd).unwrap() run_command("tests/inputs/input1", &mut cmd).unwrap()
.failure(); .failure();
} }

Loading…
Cancel
Save