fix: record format when module select

- instead of checking the container we need to check
  the FieldAccess label.

closes #601
This commit is contained in:
rvcas 2023-06-13 00:18:32 -04:00
parent a5245fdc6b
commit aeaec6bcd8
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
2 changed files with 18 additions and 3 deletions

View File

@ -946,9 +946,7 @@ impl<'comments> Formatter<'comments> {
fn call<'a>(&mut self, fun: &'a UntypedExpr, args: &'a [CallArg<UntypedExpr>]) -> Document<'a> {
let is_constr = match fun {
UntypedExpr::Var { name, .. } => name[0..1].chars().all(|c| c.is_uppercase()),
UntypedExpr::FieldAccess { container, .. } => {
matches!(&**container, UntypedExpr::Var { name, .. } if name[0..1].chars().all(|c| c.is_uppercase()))
}
UntypedExpr::FieldAccess { label, .. } => label[0..1].chars().all(|c| c.is_uppercase()),
_ => false,
};

View File

@ -34,6 +34,23 @@ fn comment_at_end_of_file() {
assert_fmt(input, output);
}
#[test]
fn module_select_record() {
let input = indoc! { r#"
fn smth() {
let a = foo.Foo { bar: 1 }
}
"#};
let output = indoc! { r#"
fn smth() {
let a = foo.Foo { bar: 1 }
}
"#};
assert_fmt(input, output);
}
#[test]
fn test_format_if() {
let src = indoc! {r#"