Skip to content

Commit

Permalink
feat(Parser): finished help argument and added a default to opts
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinFillon committed Sep 8, 2023
1 parent 4b18979 commit 6dc3c87
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 482 deletions.
69 changes: 8 additions & 61 deletions src/options/dir_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,63 +66,10 @@ impl RecurseOptions {
mod test {
use super::*;

const DEFAULT: Opts = Opts {
paths: vec![],
all: 0,
long: 0,
git: 0,
oneline: 0,
recurse: 0,
list_dirs: 0,
tree: 0,
level: None,
reverse: 0,
sort: None,
ignore_glob: None,
git_ignore: 0,
dirs_first: 0,
only_dirs: 0,
binary: 0,
bytes: 0,
group: 0,
numeric: 0,
grid: 0,
across: 0,
classify: 0,
dereference: 0,
width: None,
color: None,
color_scale: 0,
almost_all: 0,
header: 0,
icons: 0,
inode: 0,
git_repos: 0,
git_repos_no_status: 0,
links: 0,
modified: 0,
created: 0,
accessed: 0,
changed: 0,
blocksize: 0,
time: None,
time_style: None,
no_filesize: 0,
no_icons: 0,
no_permissions: 0,
no_time: 0,
no_user: 0,
extended: 0,
hyperlink: 0,
octal: 0,
security_context: 0,
help: Some(false),
};

#[test]
fn deduces_list() {
let matches = Opts {
..DEFAULT
..Opts::default()
};

assert_eq!(DirAction::deduce(&matches, false, false).unwrap(), DirAction::List);
Expand All @@ -132,7 +79,7 @@ mod test {
fn deduce_recurse() {
let matches = Opts {
recurse: 1,
..DEFAULT
..Opts::default()
};
assert_eq!(DirAction::deduce(&matches, false, false).unwrap(), DirAction::Recurse(RecurseOptions {
tree: false,
Expand All @@ -144,7 +91,7 @@ mod test {
fn deduce_recurse_tree() {
let matches = Opts {
tree: 1,
..DEFAULT
..Opts::default()
};
assert_eq!(DirAction::deduce(&matches, true, false).unwrap(), DirAction::Recurse(RecurseOptions {
tree: true,
Expand All @@ -156,7 +103,7 @@ mod test {
fn deduce_as_file() {
let matches = Opts {
list_dirs: 1,
..DEFAULT
..Opts::default()
};
assert_eq!(DirAction::deduce(&matches, false, false).unwrap(), DirAction::AsFile);
}
Expand All @@ -165,7 +112,7 @@ mod test {
fn deduce_strict_unuseful_level() {
let matches = Opts {
level: Some(2),
..DEFAULT
..Opts::default()
};

assert!(DirAction::deduce(&matches, false, true).is_err());
Expand All @@ -176,7 +123,7 @@ mod test {
let matches = Opts {
recurse: 1,
list_dirs: 1,
..DEFAULT
..Opts::default()
};

assert!(DirAction::deduce(&matches, false, true).is_err());
Expand All @@ -187,7 +134,7 @@ mod test {
let matches = Opts {
tree: 1,
list_dirs: 1,
..DEFAULT
..Opts::default()
};

assert!(DirAction::deduce(&matches, false, true).is_err());
Expand All @@ -199,7 +146,7 @@ mod test {
recurse: 1,
tree: 1,
level: Some(2),
..DEFAULT
..Opts::default()
};

assert_eq!(DirAction::deduce(&matches, true, false).unwrap(), DirAction::Recurse(RecurseOptions {
Expand Down
61 changes: 4 additions & 57 deletions src/options/file_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,70 +59,17 @@ impl EmbedHyperlinks {
mod test {
use super::*;

const DEFAULT: Opts = Opts {
paths: vec![],
all: 0,
long: 0,
git: 0,
oneline: 0,
recurse: 0,
list_dirs: 0,
tree: 0,
level: None,
reverse: 0,
sort: None,
ignore_glob: None,
git_ignore: 0,
dirs_first: 0,
only_dirs: 0,
binary: 0,
bytes: 0,
group: 0,
numeric: 0,
grid: 0,
across: 0,
classify: 0,
dereference: 0,
width: None,
color: None,
color_scale: 0,
almost_all: 0,
header: 0,
icons: 0,
inode: 0,
git_repos: 0,
git_repos_no_status: 0,
links: 0,
modified: 0,
created: 0,
accessed: 0,
changed: 0,
blocksize: 0,
time: None,
time_style: None,
no_filesize: 0,
no_icons: 0,
no_permissions: 0,
no_time: 0,
no_user: 0,
extended: 0,
hyperlink: 0,
octal: 0,
security_context: 0,
help: Some(false),
};

#[test]
fn deduce_hyperlinks() {
assert_eq!(EmbedHyperlinks::deduce(&DEFAULT), EmbedHyperlinks::Off);
assert_eq!(EmbedHyperlinks::deduce(&Opts::default()), EmbedHyperlinks::Off);
}

#[test]
fn deduce_hyperlinks_on() {

let matches = Opts {
hyperlink: 1,
..DEFAULT
..Opts::default()
};

assert_eq!(EmbedHyperlinks::deduce(&matches), EmbedHyperlinks::On);
Expand All @@ -132,7 +79,7 @@ mod test {
fn deduce_classify() {
let matches = Opts {
classify: 1,
..DEFAULT
..Opts::default()
};

assert_eq!(Classify::deduce(&matches), Classify::AddFileIndicators);
Expand All @@ -141,7 +88,7 @@ mod test {
#[test]
fn deduce_classify_no_classify() {
let matches = Opts {
..DEFAULT
..Opts::default()
};

assert_eq!(Classify::deduce(&matches), Classify::JustFilenames);
Expand Down
153 changes: 0 additions & 153 deletions src/options/help.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ pub(crate) mod parser;
mod error;
pub use self::error::{OptionsError, NumberSource};

mod help;

pub mod vars;
pub use self::vars::Vars;

Expand Down
Loading

0 comments on commit 6dc3c87

Please sign in to comment.