Skip to content

Commit f1a397a

Browse files
committed
[review] test override skip macro names
1 parent 9da7e5c commit f1a397a

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
@@ -408,6 +408,7 @@ mod test {
408408
use super::*;
409409
use std::str;
410410

411+
use crate::config::macro_names::MacroName;
411412
use rustfmt_config_proc_macro::{nightly_only_test, stable_only_test};
412413

413414
#[allow(dead_code)]
@@ -927,4 +928,17 @@ make_backup = false
927928
assert_eq!(config.single_line_if_else_max_width(), 100);
928929
}
929930
}
931+
932+
#[test]
933+
fn test_override_skip_macro_names() {
934+
let mut config = Config::default();
935+
config.override_value("skip_macro_names", r#"["*", "println"]"#);
936+
assert_eq!(
937+
config.skip_macro_names(),
938+
MacroSelectors(vec![
939+
MacroSelector::All,
940+
MacroSelector::Name(MacroName::new("println".to_owned()))
941+
])
942+
);
943+
}
930944
}

src/visitor.rs

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

0 commit comments

Comments
 (0)