mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-30 08:00:21 +00:00
52fb080193
Adds the ability to specify an indent string to public autofmt methods - either a sequence of spaces or a tab character. Get the indentation style and size from rustfmt for dx fmt, or from the editor settings for the vscode extension. Closes #1595
28 lines
1.2 KiB
Rust
28 lines
1.2 KiB
Rust
use dioxus_autofmt::{IndentType, IndentOptions};
|
|
|
|
macro_rules! twoway {
|
|
($val:literal => $name:ident ($indent:expr)) => {
|
|
#[test]
|
|
fn $name() {
|
|
let src_right = include_str!(concat!("./wrong/", $val, ".rsx"));
|
|
let src_wrong = include_str!(concat!("./wrong/", $val, ".wrong.rsx"));
|
|
let formatted = dioxus_autofmt::fmt_file(src_wrong, $indent);
|
|
let out = dioxus_autofmt::apply_formats(src_wrong, formatted);
|
|
|
|
// normalize line endings
|
|
let out = out.replace("\r", "");
|
|
let src_right = src_right.replace("\r", "");
|
|
|
|
pretty_assertions::assert_eq!(&src_right, &out);
|
|
}
|
|
};
|
|
}
|
|
|
|
twoway!("comments-4sp" => comments_4sp (IndentOptions::new(IndentType::Spaces, 4)));
|
|
twoway!("comments-tab" => comments_tab (IndentOptions::new(IndentType::Tabs, 4)));
|
|
|
|
twoway!("multi-4sp" => multi_4sp (IndentOptions::new(IndentType::Spaces, 4)));
|
|
twoway!("multi-tab" => multi_tab (IndentOptions::new(IndentType::Tabs, 4)));
|
|
|
|
twoway!("multiexpr-4sp" => multiexpr_4sp (IndentOptions::new(IndentType::Spaces, 4)));
|
|
twoway!("multiexpr-tab" => multiexpr_tab (IndentOptions::new(IndentType::Tabs, 4)));
|