WIP Merge remote-tracking branch 'remote/main' into rebuild-platform

This commit is contained in:
Luke Boswell 2024-10-09 09:21:46 +11:00
commit e3afeaa7ff
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
138 changed files with 3544 additions and 4651 deletions

View file

@ -0,0 +1 @@
Expr(If(IndentElseBranch(@31), @0), @0)

View file

@ -0,0 +1,4 @@
if thing then
whatever
else
something better

View file

@ -1,6 +1,6 @@
SpaceAfter(
If(
[
If {
if_thens: [
(
@3-6 Var {
module_name: "",
@ -60,7 +60,7 @@ SpaceAfter(
),
),
],
@49-50 SpaceBefore(
final_else: @49-50 SpaceBefore(
Var {
module_name: "",
ident: "c",
@ -71,7 +71,8 @@ SpaceAfter(
),
],
),
),
indented_else: false,
},
[
LineComment(
" 4",

View file

@ -1,6 +1,6 @@
SpaceAfter(
If(
[
If {
if_thens: [
(
@3-5 Var {
module_name: "",
@ -40,7 +40,7 @@ SpaceAfter(
),
),
],
@42-43 SpaceBefore(
final_else: @42-43 SpaceBefore(
Num(
"3",
),
@ -48,7 +48,8 @@ SpaceAfter(
Newline,
],
),
),
indented_else: false,
},
[
Newline,
],

View file

@ -0,0 +1,16 @@
SpaceAfter(
BinOps(
[
(
@0-1 Num(
"1",
),
@2-4 Pizza,
),
],
@5-8 Dbg,
),
[
Newline,
],
)

View file

@ -0,0 +1 @@
1 |> dbg

View file

@ -8,8 +8,8 @@ SpaceAfter(
@2-3 Star,
),
],
@4-30 If(
[
@4-30 If {
if_thens: [
(
@7-16 Var {
module_name: "Bool",
@ -20,10 +20,11 @@ SpaceAfter(
),
),
],
@29-30 Num(
final_else: @29-30 Num(
"1",
),
),
indented_else: false,
},
),
[
Newline,

View file

@ -3,8 +3,8 @@ Record(
@1-31 RequiredValue(
@1-2 "x",
[],
@5-31 If(
[
@5-31 If {
if_thens: [
(
@8-17 Var {
module_name: "Bool",
@ -15,10 +15,11 @@ Record(
),
),
],
@30-31 Num(
final_else: @30-31 Num(
"2",
),
),
indented_else: false,
},
),
@33-37 RequiredValue(
@33-34 "y",

View file

@ -1986,7 +1986,7 @@ mod test_fmt {
}
#[test]
fn new_record_builder() {
fn record_builder() {
expr_formats_same(indoc!(
r"
{ shoes <- leftShoe: nothing }
@ -2077,170 +2077,6 @@ mod test_fmt {
);
}
#[test]
fn old_record_builder() {
expr_formats_same(indoc!(
r#"
{ a: 1, b: <- get "b" |> batch, c: <- get "c" |> batch, d }
"#
));
expr_formats_to(
indoc!(
r#"
{ a: 1, b: <- get "b" |> batch, c:<- get "c" |> batch }
"#
),
indoc!(
r#"
{ a: 1, b: <- get "b" |> batch, c: <- get "c" |> batch }
"#
),
);
expr_formats_same(indoc!(
r#"
{
a: 1,
b: <- get "b" |> batch,
c: <- get "c" |> batch,
d,
}
"#
));
expr_formats_to(
indoc!(
r#"
{ a: 1, b: <- get "b" |> batch,
c: <- get "c" |> batch, d }
"#
),
indoc!(
r#"
{
a: 1,
b: <- get "b" |> batch,
c: <- get "c" |> batch,
d,
}
"#
),
);
}
#[test]
fn multiline_record_builder_field() {
expr_formats_to(
indoc!(
r#"
succeed {
a: <- get "a" |> map (\x -> x * 2)
|> batch,
b: <- get "b" |> batch,
c: items
|> List.map \x -> x * 2
}
"#
),
indoc!(
r#"
succeed {
a: <-
get "a"
|> map (\x -> x * 2)
|> batch,
b: <- get "b" |> batch,
c:
items
|> List.map \x -> x * 2,
}
"#
),
);
expr_formats_same(indoc!(
r#"
succeed {
a: # I like to comment in weird places
<- get "a" |> batch,
b: <- get "b" |> batch,
}
"#
));
expr_formats_same(indoc!(
r#"
succeed {
a:
# I like to comment in weird places
<- get "a" |> batch,
b: <- get "b" |> batch,
}
"#
));
}
#[test]
fn outdentable_record_builders() {
expr_formats_to(
indoc!(
r#"
succeed { a: <- get "a" |> batch,
b: <- get "b" |> batch,
}
"#
),
indoc!(
r#"
succeed {
a: <- get "a" |> batch,
b: <- get "b" |> batch,
}
"#
),
);
expr_formats_to(
indoc!(
r#"
succeed
{
a: <- get "a" |> batch,
b: <- get "b" |> batch,
}
"#
),
indoc!(
r#"
succeed {
a: <- get "a" |> batch,
b: <- get "b" |> batch,
}
"#
),
);
}
#[test]
fn can_format_multiple_record_builders() {
expr_formats_to(
indoc!(
r#"
succeed { a: <- get "a" }
{ b: <- get "b" }
"#
),
indoc!(
r#"
succeed
{ a: <- get "a" }
{ b: <- get "b" }
"#
),
);
}
#[test]
fn final_comments_in_records() {
expr_formats_same(indoc!(
@ -3628,6 +3464,60 @@ mod test_fmt {
));
}
#[test]
fn early_return_else() {
expr_formats_same(indoc!(
r"
if foo then
bar
else
baz
"
));
expr_formats_to(
indoc!(
r"
if thing then
whatever
else
too close
"
),
indoc!(
r"
if thing then
whatever
else
too close
"
),
);
expr_formats_to(
indoc!(
r"
if isGrowing plant then
LetBe
else
Water
"
),
indoc!(
r"
if isGrowing plant then
LetBe
else
Water
"
),
);
}
#[test]
fn multi_line_application() {
expr_formats_same(indoc!(

View file

@ -202,6 +202,7 @@ mod test_snapshots {
fail/expression_indentation_end.expr,
fail/if_guard_without_condition.expr,
fail/if_missing_else.expr,
fail/if_outdented_else_branch.expr,
fail/if_outdented_then.expr,
fail/import_with_lowercase_alias.moduledefs,
fail/imports_missing_comma.header,
@ -442,6 +443,7 @@ mod test_snapshots {
pass/pattern_as_spaces.expr,
pass/pattern_with_space_in_parens.expr, // https://github.com/roc-lang/roc/issues/929
pass/pizza_bang.moduledefs,
pass/pizza_dbg.expr,
pass/plus_if.expr,
pass/plus_when.expr,
pass/pos_inf_float.expr,