Skip to content

Commit ffcae6f

Browse files
committed
[review] test override skip macro names
1 parent b535436 commit ffcae6f

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/config/macro_names.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ use thiserror::Error;
1111
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
1212
pub struct MacroName(String);
1313

14+
impl MacroName {
15+
pub fn new(other: String) -> Self {
16+
Self(other)
17+
}
18+
}
19+
1420
impl fmt::Display for MacroName {
1521
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1622
self.0.fmt(f)
@@ -52,13 +58,7 @@ impl str::FromStr for MacroSelector {
5258

5359
/// A set of macro selectors.
5460
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
55-
pub struct MacroSelectors(Vec<MacroSelector>);
56-
57-
impl MacroSelectors {
58-
pub fn into_inner(self) -> Vec<MacroSelector> {
59-
self.0
60-
}
61-
}
61+
pub struct MacroSelectors(pub Vec<MacroSelector>);
6262

6363
impl fmt::Display for MacroSelectors {
6464
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/config/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ mod test {
414414
use super::*;
415415
use std::str;
416416

417+
use crate::config::macro_names::MacroName;
417418
use rustfmt_config_proc_macro::{nightly_only_test, stable_only_test};
418419

419420
#[allow(dead_code)]
@@ -962,4 +963,17 @@ make_backup = false
962963
assert_eq!(config.single_line_if_else_max_width(), 100);
963964
}
964965
}
966+
967+
#[test]
968+
fn test_override_skip_macro_names() {
969+
let mut config = Config::default();
970+
config.override_value("skip_macro_names", r#"["*", "println"]"#);
971+
assert_eq!(
972+
config.skip_macro_names(),
973+
MacroSelectors(vec![
974+
MacroSelector::All,
975+
MacroSelector::Name(MacroName::new("println".to_owned()))
976+
])
977+
);
978+
}
965979
}

src/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
771771
) -> FmtVisitor<'a> {
772772
let mut skip_context = SkipContext::default();
773773
let mut macro_names = Vec::new();
774-
for macro_selector in config.skip_macro_names().into_inner() {
774+
for macro_selector in config.skip_macro_names().0 {
775775
match macro_selector {
776776
MacroSelector::Name(name) => macro_names.push(name.to_string()),
777777
MacroSelector::All => skip_context.all_macros = true,

0 commit comments

Comments
 (0)