Skip to content

Commit

Permalink
Merge branch 'master' into jjcnn/move-external-modules-to-root
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcnn authored Jan 9, 2025
2 parents 73142ca + 96ee0b8 commit 9c39636
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion swayfmt/src/utils/language/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl Format for Expr {
|formatter| -> Result<(), FormatterError> {
write!(formatted_code, "{} ", ForToken::AS_STR)?;
value_pattern.format(formatted_code, formatter)?;
write!(formatted_code, "{} ", InToken::AS_STR)?;
write!(formatted_code, " {} ", InToken::AS_STR)?;
iterator.format(formatted_code, formatter)?;
IfExpr::open_curly_brace(formatted_code, formatter)?;
block.get().format(formatted_code, formatter)?;
Expand Down
10 changes: 10 additions & 0 deletions swayfmt/src/utils/language/expr/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,13 @@ intermediate_whitespace
"{
let i = 42;
}");

fmt_test_expr!(basic_for_loop
"for iter in [0, 1, 7, 8, 15] {
let i = 42;
}",
intermediate_whitespace
"for iter in [0, 1, 7, 8, 15]{
let i = 42;
}"
);
40 changes: 40 additions & 0 deletions swayfmt/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3449,3 +3449,43 @@ fn tuple_field_access() {
"#},
);
}

#[test]
fn contract_for_loop() {
check(
indoc! {r#"
contract;
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
let mut my_vec: Vec<u64> = Vec::new();
for iter in my_vec.iter() {
}
true
}
}
"#},
indoc! {r#"
contract;
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
let mut my_vec: Vec<u64> = Vec::new();
for iter in my_vec.iter() { }
true
}
}
"#},
);
}

0 comments on commit 9c39636

Please sign in to comment.