Fix tests for autofmt

This commit is contained in:
Jonathan Kelley committed 2024-01-10 22:41:40 -08:00
1 parent d9b84f9f8f
commit fa9d92f956
17 files changed
+287 -177

No files matched your search

+4
View File
@@ -182,6 +182,9 @@ impl Writer<'_> {
s.source.as_ref().unwrap().to_token_stream()
)?;
}
ContentField::Shorthand(e) => {
write!(self.out, "{}", e.to_token_stream())?;
}
ContentField::OnHandlerRaw(exp) => {
let out = prettyplease::unparse_expr(exp);
let mut lines = out.split('\n').peekable();
@@ -223,6 +226,7 @@ impl Writer<'_> {
.iter()
.map(|field| match &field.content {
ContentField::Formatted(s) => ifmt_to_string(s).len() ,
ContentField::Shorthand(e) => e.to_token_stream().to_string().len(),
ContentField::OnHandlerRaw(exp) | ContentField::ManExpr(exp) => {
let formatted = prettyplease::unparse_expr(exp);
let len = if formatted.contains('\n') {
+42 -2
View File
@@ -232,8 +232,48 @@ impl<'a> Writer<'a> {
}
fn write_if_chain(&mut self, ifchain: &IfChain) -> std::fmt::Result {
todo!()
// self.write_raw_expr(ifchain.span())
// Recurse in place by setting the next chain
let mut branch = Some(ifchain);
while let Some(chain) = branch {
let IfChain {
if_token,
cond,
then_branch,
else_if_branch,
else_branch,
} = chain;
write!(
self.out,
"{} {} {{",
if_token.to_token_stream(),
prettyplease::unparse_expr(cond)
)?;
self.write_body_indented(then_branch)?;
if let Some(else_if_branch) = else_if_branch {
// write the closing bracket and else
self.out.tabbed_line()?;
write!(self.out, "}} else ")?;
branch = Some(else_if_branch);
} else if let Some(else_branch) = else_branch {
self.out.tabbed_line()?;
write!(self.out, "}} else {{")?;
self.write_body_indented(else_branch)?;
branch = None;
} else {
branch = None;
}
}
self.out.tabbed_line()?;
write!(self.out, "}}")?;
Ok(())
}
}
@@ -8,17 +8,17 @@ rsx! {
"hello world"
// Comments
expr1,
{expr1},
// Comments
expr2,
{expr2},
// Comments
// Comments
// Comments
// Comments
// Comments
expr3,
{expr3},
div {
// todo some work in here
+4 -4
View File
@@ -18,7 +18,7 @@ rsx! {
to: "{to}",
span { class: "inline-block mr-3", icons::icon_0 {} }
span { "{name}" }
children.is_some().then(|| rsx! {
{children.is_some().then(|| rsx! {
span {
class: "inline-block ml-auto hover:bg-gray-500",
onclick: move |evt| {
@@ -27,9 +27,9 @@ rsx! {
},
icons::icon_8 {}
}
})
})}
}
div { class: "px-4", is_current.then(|| rsx!{ children }) }
div { class: "px-4", {is_current.then(|| rsx!{ children })} }
}
// No nesting
@@ -48,5 +48,5 @@ rsx! {
}
}
div { asdbascasdbasd, asbdasbdabsd, asbdabsdbasdbas }
div { "asdbascasdbasd", "asbdasbdabsd", {asbdabsdbasdbas} }
}
@@ -8,6 +8,20 @@ rsx! {
// Some ifchain
if a > 10 {
//
rsx! { div {} }
div {}
} else if a > 20 {
h1 {}
} else if a > 20 {
h1 {}
} else if a > 20 {
h1 {}
} else if a > 20 {
h1 {}
} else if a > 20 {
h1 {}
} else if a > 20 {
h1 {}
} else {
h3 {}
}
}
@@ -1,4 +1,4 @@
fn it_works() {
cx.render(rsx!(()))
cx.render(rsx!({()}))
}
+4 -4
View File
@@ -11,7 +11,7 @@ pub fn Explainer<'a>(
// pt-5 sm:pt-24 lg:pt-24
let mut right = rsx! {
div { class: "relative w-1/2", flasher }
div { class: "relative w-1/2", {flasher} }
};
let align = match invert {
@@ -24,7 +24,7 @@ pub fn Explainer<'a>(
h2 { class: "mb-6 text-3xl leading-tight md:text-4xl md:leading-tight lg:text-3xl lg:leading-tight font-heading font-mono font-bold",
"{title}"
}
content
{content}
}
};
@@ -34,8 +34,8 @@ pub fn Explainer<'a>(
cx.render(rsx! {
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light",
left,
right
{left},
{right}
}
})
}
@@ -6,7 +6,7 @@ rsx! {
section { class: "body-font overflow-hidden dark:bg-ideblack",
div { class: "container px-6 mx-auto",
div { class: "-my-8 divide-y-2 divide-gray-100",
POSTS.iter().enumerate().map(|(id, post)| rsx! { BlogPostItem { post: post, id: id } })
{POSTS.iter().enumerate().map(|(id, post)| rsx! { BlogPostItem { post: post, id: id } })}
}
}
}
+5 -5
View File
@@ -4,20 +4,20 @@ rsx! {
div {}
// hi
div { abcd, ball, s }
div { "abcd", "ball", "s" }
//
//
//
div { abcd, ball, s }
div { "abcd", "ball", "s" }
//
//
//
div {
abcd,
ball,
s,
"abcd"
"ball"
"s"
//
"asdasd"
@@ -1,7 +1,7 @@
fn it_works() {
cx.render(rsx! {
div {
span { "Description: ", package.description.as_deref().unwrap_or("❌❌❌❌ missing") }
span { "Description: ", {package.description.as_deref().unwrap_or("❌❌❌❌ missing")} }
}
})
}
@@ -1,8 +1,8 @@
fn ItWroks() {
cx.render(rsx! {
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light",
left,
right
{left},
{right}
}
})
}
@@ -1,5 +1,5 @@
fn ItWroks() {
cx.render(rsx! {
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", left, right }
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", {left}, {right} }
})
}
@@ -1,8 +1,8 @@
fn ItWroks() {
cx.render(rsx! {
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light",
left,
right
{left},
{right}
}
})
}
@@ -1,5 +1,5 @@
fn ItWroks() {
cx.render(rsx! {
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", left, right }
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", {left}, {right} }
})
}