Skip to content

Commit

Permalink
fix: Encoding parameter default is being broken.
Browse files Browse the repository at this point in the history
- Added unit tests for no encoding and encoding scenarios
  • Loading branch information
OrkunKocyigit committed Aug 1, 2023
1 parent 90187d3 commit bd1a46f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "extractor"
version = "0.4.0"
version = "0.4.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
29 changes: 26 additions & 3 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::thread::available_parallelism;

use clap::Parser;
use clap::{CommandFactory, Parser};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -14,10 +14,15 @@ pub struct Options {
delete: bool,
#[arg(short, long, default_value = "nowaythisis")]
password: String,
#[arg(short, long, default_value_if("no-encoding", "true", "None"))]
encoding: Option<String>,
#[arg(long, default_value_t = false)]
no_encoding: bool,
#[arg(
short,
long,
default_value_if("no_encoding", "true", None),
default_value_if("no_encoding", "false", Some("932"))
)]
encoding: Option<String>,
#[arg(short, long, default_value_t = get_thread_num(), value_parser = parse_thread_count)]
workers: usize,
#[arg(hide = true, default_value = "7z", value_parser = check_archiver)]
Expand Down Expand Up @@ -85,3 +90,21 @@ fn get_thread_num() -> usize {
let default_parallelism_approx = available_parallelism().unwrap().get();
max(default_parallelism_approx / 2, 1)
}

#[test]
fn test_options_when_no_encoding_present() {
let p = Options::command().get_matches_from(vec!["", "--no-encoding", "./test"]);
assert_eq!(p.get_one::<String>("encoding"), None);
}

#[test]
fn test_options_when_no_encoding_not_present() {
let p = Options::command().get_matches_from(vec!["", "./test"]);
assert_eq!(p.get_one::<String>("encoding"), Some(&"932".to_string()));
}

#[test]
fn test_options_when_custom_encoding_present() {
let p = Options::command().get_matches_from(vec!["", "-e", "123", "./test"]);
assert_eq!(p.get_one::<String>("encoding"), Some(&"123".to_string()));
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn main() -> Result<(), anyhow::Error> {
.num_threads(options.workers())
.build()
.unwrap();
dbg!(&options);
pool.install(|| {
file_scan::read_files(&paths, options.path()).expect("Creating file list failed");
paths.lock().unwrap().par_iter().for_each(|path| {
Expand Down

0 comments on commit bd1a46f

Please sign in to comment.