mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
fmt: use "unwrap()" instead of "?" in tests
This commit is contained in:
parent
263f4a0377
commit
b64183b0de
1 changed files with 18 additions and 26 deletions
|
@ -470,62 +470,54 @@ pub fn uu_app() -> Command {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
use crate::uu_app;
|
use crate::uu_app;
|
||||||
use crate::{extract_files, extract_width};
|
use crate::{extract_files, extract_width};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_negative_width() -> Result<(), Box<dyn Error>> {
|
fn parse_negative_width() {
|
||||||
let matches = uu_app().try_get_matches_from(vec!["fmt", "-3", "some-file"])?;
|
let matches = uu_app()
|
||||||
|
.try_get_matches_from(vec!["fmt", "-3", "some-file"])
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
||||||
|
|
||||||
assert_eq!(extract_width(&matches).ok(), Some(Some(3)));
|
assert_eq!(extract_width(&matches).ok(), Some(Some(3)));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_width_as_arg() -> Result<(), Box<dyn Error>> {
|
fn parse_width_as_arg() {
|
||||||
let matches = uu_app().try_get_matches_from(vec!["fmt", "-w3", "some-file"])?;
|
let matches = uu_app()
|
||||||
|
.try_get_matches_from(vec!["fmt", "-w3", "some-file"])
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
||||||
|
|
||||||
assert_eq!(extract_width(&matches).ok(), Some(Some(3)));
|
assert_eq!(extract_width(&matches).ok(), Some(Some(3)));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_no_args() -> Result<(), Box<dyn Error>> {
|
fn parse_no_args() {
|
||||||
let matches = uu_app().try_get_matches_from(vec!["fmt"])?;
|
let matches = uu_app().try_get_matches_from(vec!["fmt"]).unwrap();
|
||||||
|
|
||||||
assert_eq!(extract_files(&matches).unwrap(), vec!["-"]);
|
assert_eq!(extract_files(&matches).unwrap(), vec!["-"]);
|
||||||
|
|
||||||
assert_eq!(extract_width(&matches).ok(), Some(None));
|
assert_eq!(extract_width(&matches).ok(), Some(None));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_just_file_name() -> Result<(), Box<dyn Error>> {
|
fn parse_just_file_name() {
|
||||||
let matches = uu_app().try_get_matches_from(vec!["fmt", "some-file"])?;
|
let matches = uu_app()
|
||||||
|
.try_get_matches_from(vec!["fmt", "some-file"])
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
||||||
|
|
||||||
assert_eq!(extract_width(&matches).ok(), Some(None));
|
assert_eq!(extract_width(&matches).ok(), Some(None));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_with_both_widths_positional_first() -> Result<(), Box<dyn Error>> {
|
fn parse_with_both_widths_positional_first() {
|
||||||
let matches = uu_app().try_get_matches_from(vec!["fmt", "-10", "-w3", "some-file"])?;
|
let matches = uu_app()
|
||||||
|
.try_get_matches_from(vec!["fmt", "-10", "-w3", "some-file"])
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
assert_eq!(extract_files(&matches).unwrap(), vec!["some-file"]);
|
||||||
|
|
||||||
assert_eq!(extract_width(&matches).ok(), Some(Some(3)));
|
assert_eq!(extract_width(&matches).ok(), Some(Some(3)));
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue