Skip to content

Commit

Permalink
impl rewrite_result for ast::Expr
Browse files Browse the repository at this point in the history
refactor - formatting

refactor - tests

refactor - updated dir value

refactor - updated tests

refactor - updated tests
  • Loading branch information
ding-young authored and rufevean committed Sep 12, 2024
1 parent 4813ccc commit e05badf
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 148 deletions.
50 changes: 25 additions & 25 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,11 @@ impl Config {
if !err.is_empty() {
eprint!("{err}");
}
Ok(parsed_config.to_parsed_config(
style_edition,
edition,
version,
file_path.parent().unwrap_or(Path::new("")),
))
let dir = file_path.parent().ok_or_else(|| {
format!("failed to get parent directory for {}", file_path.display())
})?;

Ok(parsed_config.to_parsed_config(style_edition, edition, version, dir))
}
Err(e) => {
let err_msg = format!(
Expand Down Expand Up @@ -675,7 +674,7 @@ mod test {

#[test]
fn test_was_set() {
let config = Config::from_toml("hard_tabs = true", Path::new("")).unwrap();
let config = Config::from_toml("hard_tabs = true", Path::new("./rustfmt.toml")).unwrap();

assert_eq!(config.was_set().hard_tabs(), true);
assert_eq!(config.was_set().verbose(), false);
Expand Down Expand Up @@ -934,7 +933,8 @@ make_backup = false
#[nightly_only_test]
#[test]
fn test_unstable_from_toml() {
let config = Config::from_toml("unstable_features = true", Path::new("")).unwrap();
let config =
Config::from_toml("unstable_features = true", Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.was_set().unstable_features(), true);
assert_eq!(config.unstable_features(), true);
}
Expand Down Expand Up @@ -964,7 +964,7 @@ make_backup = false
unstable_features = true
merge_imports = true
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.imports_granularity(), ImportGranularity::Crate);
}

Expand All @@ -976,7 +976,7 @@ make_backup = false
merge_imports = true
imports_granularity = "Preserve"
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.imports_granularity(), ImportGranularity::Preserve);
}

Expand All @@ -987,7 +987,7 @@ make_backup = false
unstable_features = true
merge_imports = true
"#;
let mut config = Config::from_toml(toml, Path::new("")).unwrap();
let mut config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
config.override_value("imports_granularity", "Preserve");
assert_eq!(config.imports_granularity(), ImportGranularity::Preserve);
}
Expand All @@ -999,7 +999,7 @@ make_backup = false
unstable_features = true
imports_granularity = "Module"
"#;
let mut config = Config::from_toml(toml, Path::new("")).unwrap();
let mut config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
config.override_value("merge_imports", "true");
// no effect: the new option always takes precedence
assert_eq!(config.imports_granularity(), ImportGranularity::Module);
Expand All @@ -1016,7 +1016,7 @@ make_backup = false
use_small_heuristics = "Default"
max_width = 200
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.array_width(), 120);
assert_eq!(config.attr_fn_like_width(), 140);
assert_eq!(config.chain_width(), 120);
Expand All @@ -1032,7 +1032,7 @@ make_backup = false
use_small_heuristics = "Max"
max_width = 120
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.array_width(), 120);
assert_eq!(config.attr_fn_like_width(), 120);
assert_eq!(config.chain_width(), 120);
Expand All @@ -1048,7 +1048,7 @@ make_backup = false
use_small_heuristics = "Off"
max_width = 100
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.array_width(), usize::max_value());
assert_eq!(config.attr_fn_like_width(), usize::max_value());
assert_eq!(config.chain_width(), usize::max_value());
Expand All @@ -1070,7 +1070,7 @@ make_backup = false
struct_lit_width = 30
struct_variant_width = 34
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.array_width(), 20);
assert_eq!(config.attr_fn_like_width(), 40);
assert_eq!(config.chain_width(), 20);
Expand All @@ -1092,7 +1092,7 @@ make_backup = false
struct_lit_width = 30
struct_variant_width = 34
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.array_width(), 20);
assert_eq!(config.attr_fn_like_width(), 40);
assert_eq!(config.chain_width(), 20);
Expand All @@ -1114,7 +1114,7 @@ make_backup = false
struct_lit_width = 30
struct_variant_width = 34
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.array_width(), 20);
assert_eq!(config.attr_fn_like_width(), 40);
assert_eq!(config.chain_width(), 20);
Expand All @@ -1130,7 +1130,7 @@ make_backup = false
max_width = 90
fn_call_width = 95
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.fn_call_width(), 90);
}

Expand All @@ -1140,7 +1140,7 @@ make_backup = false
max_width = 80
attr_fn_like_width = 90
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.attr_fn_like_width(), 80);
}

Expand All @@ -1150,7 +1150,7 @@ make_backup = false
max_width = 78
struct_lit_width = 90
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.struct_lit_width(), 78);
}

Expand All @@ -1160,7 +1160,7 @@ make_backup = false
max_width = 80
struct_variant_width = 90
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.struct_variant_width(), 80);
}

Expand All @@ -1170,7 +1170,7 @@ make_backup = false
max_width = 60
array_width = 80
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.array_width(), 60);
}

Expand All @@ -1180,7 +1180,7 @@ make_backup = false
max_width = 80
chain_width = 90
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.chain_width(), 80);
}

Expand All @@ -1190,7 +1190,7 @@ make_backup = false
max_width = 70
single_line_if_else_max_width = 90
"#;
let config = Config::from_toml(toml, Path::new("")).unwrap();
let config = Config::from_toml(toml, Path::new("./rustfmt.toml")).unwrap();
assert_eq!(config.single_line_if_else_max_width(), 70);
}

Expand Down
Loading

0 comments on commit e05badf

Please sign in to comment.