Skip to content

Commit

Permalink
refactor - minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rufevean committed Sep 3, 2024
1 parent dc86ea4 commit e7c3280
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 56 deletions.
64 changes: 40 additions & 24 deletions src/cargo-fmt/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,34 @@ fn good_options() {

#[test]
fn unexpected_option() {
assert!(Opts::command()
.try_get_matches_from(["test", "unexpected"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "unexpected"])
.is_err()
);
}

#[test]
fn unexpected_flag() {
assert!(Opts::command()
.try_get_matches_from(["test", "--flag"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "--flag"])
.is_err()
);
}

#[test]
fn mandatory_separator() {
assert!(Opts::command()
.try_get_matches_from(["test", "--emit"])
.is_err());
assert!(Opts::command()
.try_get_matches_from(["test", "--", "--emit"])
.is_ok());
assert!(
Opts::command()
.try_get_matches_from(["test", "--emit"])
.is_err()
);
assert!(
Opts::command()
.try_get_matches_from(["test", "--", "--emit"])
.is_ok()
);
}

#[test]
Expand Down Expand Up @@ -98,28 +106,36 @@ fn multiple_packages_grouped() {

#[test]
fn empty_packages_1() {
assert!(Opts::command()
.try_get_matches_from(["test", "-p"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "-p"])
.is_err()
);
}

#[test]
fn empty_packages_2() {
assert!(Opts::command()
.try_get_matches_from(["test", "-p", "--", "--check"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "-p", "--", "--check"])
.is_err()
);
}

#[test]
fn empty_packages_3() {
assert!(Opts::command()
.try_get_matches_from(["test", "-p", "--verbose"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "-p", "--verbose"])
.is_err()
);
}

#[test]
fn empty_packages_4() {
assert!(Opts::command()
.try_get_matches_from(["test", "-p", "--check"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "-p", "--check"])
.is_err()
);
}
5 changes: 1 addition & 4 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ pub(crate) fn combine_strs_with_missing_comments(
) -> RewriteResult {
trace!(
"combine_strs_with_missing_comments `{}` `{}` {:?} {:?}",
prev_str,
next_str,
span,
shape
prev_str, next_str, span, shape
);

let mut result =
Expand Down
20 changes: 8 additions & 12 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl Config {

#[allow(dead_code)]
pub(super) fn from_toml(toml: &str, file_path: &Path) -> Result<Config, String> {
Self::from_toml_for_style_edition(toml,file_path, None, None, None)
Self::from_toml_for_style_edition(toml, file_path, None, None, None)
}

pub(crate) fn from_toml_for_style_edition(
Expand Down Expand Up @@ -397,21 +397,17 @@ impl Config {
Ok(parsed_config.to_parsed_config(style_edition, edition, version, file_path))
}
Err(e) => {
let config_file_path_str = file_path.to_string_lossy();

let config_file_path_str = file_path.to_string_lossy();

let err_msg = format!(
"The file `{}` failed to parse.\n\
let err_msg = format!(
"The file `{}` failed to parse.\n\
Error details: {}\n\
Help: Ensure that the configuration file at `{}` is correctly formatted.",
config_file_path_str,
e,
config_file_path_str
);

Err(err_msg)
}
config_file_path_str, e, config_file_path_str
);

Err(err_msg)
}
}
}
}
Expand Down
32 changes: 20 additions & 12 deletions src/format-diff/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,37 @@ mod cmd_line_tests {

#[test]
fn unexpected_option() {
assert!(Opts::command()
.try_get_matches_from(["test", "unexpected"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "unexpected"])
.is_err()
);
}

#[test]
fn unexpected_flag() {
assert!(Opts::command()
.try_get_matches_from(["test", "--flag"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "--flag"])
.is_err()
);
}

#[test]
fn overridden_option() {
assert!(Opts::command()
.try_get_matches_from(["test", "-p", "10", "-p", "20"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "-p", "10", "-p", "20"])
.is_err()
);
}

#[test]
fn negative_filter() {
assert!(Opts::command()
.try_get_matches_from(["test", "-p", "-1"])
.is_err());
assert!(
Opts::command()
.try_get_matches_from(["test", "-p", "-1"])
.is_err()
);
}
}
10 changes: 6 additions & 4 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,12 @@ fn merge_rest(
DUMMY_SP,
)];
match rest {
[UseSegment {
kind: UseSegmentKind::List(rest_list),
..
}] => list.extend(rest_list.clone()),
[
UseSegment {
kind: UseSegmentKind::List(rest_list),
..
},
] => list.extend(rest_list.clone()),
_ => list.push(UseTree::from_path(rest.to_vec(), DUMMY_SP)),
}
return Some(vec![
Expand Down

0 comments on commit e7c3280

Please sign in to comment.