Skip to content

Commit

Permalink
chore: tests are useless
Browse files Browse the repository at this point in the history
  • Loading branch information
Milo123459 committed Oct 14, 2023
1 parent 49ba806 commit de808c1
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 511 deletions.
317 changes: 0 additions & 317 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,320 +620,3 @@ fn get_current_epoch() -> u128 {
.expect("Time went backwards");
since_the_epoch.as_millis()
}

// tests
#[cfg(test)]
mod tests {
use crate::cli::action;
use crate::match_cmds;
use std::path::PathBuf;

use crate::config::{Arguments, CommitMessageArguments, CustomTaskOptions, GlitterRc};

use super::get_commit_message;

#[test]
fn basic() {
let args = Arguments {
action: "push".to_string(),
arguments: vec![
"test".to_string(),
"a".to_string(),
"b".to_string(),
"c".to_string(),
],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
commit_message: "$1($2): $3+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert_eq!(get_commit_message(&config, &args).unwrap(), "test(a): b c")
}

#[test]
fn reuse_arguments() {
let args = Arguments {
action: "push".to_string(),
arguments: vec![
"test".to_string(),
"a".to_string(),
"b".to_string(),
"c".to_string(),
],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
commit_message: "$1($2): $3+ : $2 | $1+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert_eq!(
get_commit_message(&config, &args).unwrap(),
"test(a): b c : a | test a b c"
)
}

#[test]
fn less_than_required_args() {
let args = Arguments {
action: "push".to_string(),
arguments: vec!["test".to_string(), "a".to_string()],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let args_2 = Arguments {
action: "push".to_string(),
arguments: vec!["test".to_string()],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
commit_message: "$1($2): $3+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

let config_2 = GlitterRc {
commit_message: "$1($2): $3+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert!(get_commit_message(&config, &args).is_err());
assert!(get_commit_message(&config_2, &args_2).is_err());
}

#[test]
fn no_commit_message_format() {
let args = Arguments {
action: "push".to_string(),
arguments: vec!["test".to_string(), "a".to_string()],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
// "$1+" is the default
commit_message: "$1+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert!(get_commit_message(&config, &args).is_ok())
}

#[test]
fn commit_message_arguments() {
let args = Arguments {
action: "push".to_string(),
arguments: vec!["feat".to_string(), "test".to_string(), "tests".to_string()],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
commit_message: "$1: $2: $3+".to_string(),
arguments: None,
commit_message_arguments: Some(vec![CommitMessageArguments {
argument: 1,
case: Some("snake".to_string()),
type_enums: Some(vec![
"fix".to_owned(),
"feat".to_owned(),
"chore".to_owned(),
]),
}]),
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert_eq!(
get_commit_message(&config, &args).unwrap(),
"feat: test: tests"
)
}

#[test]
fn test_action() {
assert!(action(vec!["test"]).is_ok())
}

#[test]
fn matching_cmds() {
let args = Arguments {
action: "action".to_string(),
arguments: vec![
"test".to_string(),
"a".to_string(),
"b".to_string(),
"c".to_string(),
],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
commit_message: "$1($2): $3+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert!(match_cmds(args, config).is_ok());

let args = Arguments {
action: "actions".to_string(),
arguments: vec![
"test".to_string(),
"a".to_string(),
"b".to_string(),
"c".to_string(),
],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
commit_message: "$1($2): $3+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert!(match_cmds(args, config).is_ok());

let args = Arguments {
action: "fasdafsfsa".to_string(),
arguments: vec![
"test".to_string(),
"a".to_string(),
"b".to_string(),
"c".to_string(),
],
rc_path: PathBuf::new(),
dry: Some(Some(false)),
raw: Some(Some(false)),
no_verify: Some(Some(false)),
verbose: Some(Some(false)),
yes: None,
};

let config = GlitterRc {
commit_message: "$1($2): $3+".to_string(),
arguments: None,
commit_message_arguments: None,
fetch: None,
custom_tasks: Some(vec![CustomTaskOptions {
name: "fmt".to_owned(),
execute: Some(vec!["cargo fmt".to_owned()]),
}]),
__default: None,
hooks: None,
verbose: None,
};

assert!(match_cmds(args, config).is_err());
}
}
Loading

0 comments on commit de808c1

Please sign in to comment.