lint / clippy

main
blob42 7 months ago
parent 1583b06fb9
commit 5c5c8875fa

@ -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"),
}

@ -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<usize> {
// 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<Columns> {
mod tests {
use super::*;
use crate::DEFAULT_SEP_PATTERN;
use regex::Regex;
use std::error::Error;
type TestResult = Result<(), Box<dyn Error>>;
@ -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() {

@ -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<Box<String>> {
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)?;
Ok(buf)
}

@ -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();
}

Loading…
Cancel
Save