// Imports
imports_indent: IndentStyle, IndentStyle::Block, false, "Indent of imports";
imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block";
- merge_imports: bool, false, false, "Merge imports";
+ imports_granularity: ImportGranularity, ImportGranularity::Preserve, false,
+ "Merge or split imports to the provided granularity";
+ group_imports: GroupImportsTactic, GroupImportsTactic::Preserve, false,
+ "Controls the strategy for how imports are grouped together";
+ merge_imports: bool, false, false, "(deprecated: use imports_granularity instead)";
// Ordering
reorder_imports: bool, true, true, "Reorder import and extern crate statements alphabetically";
cloned.verbose = None;
cloned.width_heuristics = None;
cloned.print_misformatted_file_names = None;
+ cloned.merge_imports = None;
::toml::to_string(&cloned).map_err(ToTomlError)
}
via the --file-lines option";
width_heuristics: WidthHeuristics, WidthHeuristics::scaled(100), false,
"'small' heuristic values";
+ // merge_imports deprecation
+ imports_granularity: ImportGranularity, ImportGranularity::Preserve, false,
+ "Merge imports";
+ merge_imports: bool, false, false, "(deprecated: use imports_granularity instead)";
// Options that are used by the tests
stable_option: bool, false, true, "A stable option";
assert!(config.license_template.is_some());
}
+ #[test]
+ fn test_override_existing_license_with_no_license() {
+ if !crate::is_nightly_channel!() {
+ return;
+ }
+ let toml = r#"license_template_path = "tests/license-template/lt.txt""#;
+ let mut config = Config::from_toml(toml, Path::new("")).unwrap();
+ assert!(config.license_template.is_some());
+ config.override_value("license_template_path", "");
+ assert!(config.license_template.is_none());
+ }
+
#[test]
fn test_dump_default_config() {
let default_config = format!(
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
-merge_imports = false
+imports_granularity = "Preserve"
+group_imports = "Preserve"
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
// assert_eq!(config.unstable_features(), true);
// ::std::env::set_var("CFG_RELEASE_CHANNEL", v);
// }
+
+ #[cfg(test)]
+ mod deprecated_option_merge_imports {
+ use super::*;
+
+ #[test]
+ fn test_old_option_set() {
+ if !crate::is_nightly_channel!() {
+ return;
+ }
+ let toml = r#"
+ unstable_features = true
+ merge_imports = true
+ "#;
+ let config = Config::from_toml(toml, Path::new("")).unwrap();
+ assert_eq!(config.imports_granularity(), ImportGranularity::Crate);
+ }
+
+ #[test]
+ fn test_both_set() {
+ if !crate::is_nightly_channel!() {
+ return;
+ }
+ let toml = r#"
+ unstable_features = true
+ merge_imports = true
+ imports_granularity = "Preserve"
+ "#;
+ let config = Config::from_toml(toml, Path::new("")).unwrap();
+ assert_eq!(config.imports_granularity(), ImportGranularity::Preserve);
+ }
+
+ #[test]
+ fn test_new_overridden() {
+ if !crate::is_nightly_channel!() {
+ return;
+ }
+ let toml = r#"
+ unstable_features = true
+ merge_imports = true
+ "#;
+ let mut config = Config::from_toml(toml, Path::new("")).unwrap();
+ config.override_value("imports_granularity", "Preserve");
+ assert_eq!(config.imports_granularity(), ImportGranularity::Preserve);
+ }
+
+ #[test]
+ fn test_old_overridden() {
+ if !crate::is_nightly_channel!() {
+ return;
+ }
+ let toml = r#"
+ unstable_features = true
+ imports_granularity = "Module"
+ "#;
+ let mut config = Config::from_toml(toml, Path::new("")).unwrap();
+ config.override_value("merge_imports", "true");
+ // no effect: the new option always takes precedence
+ assert_eq!(config.imports_granularity(), ImportGranularity::Module);
+ }
+ }
}