mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 15:59:20 +03:00
Merge pull request #3079 from rtfeldman/formatter-empty-record-patterns
Formatter empty record patterns
This commit is contained in:
commit
3bbfb397d2
@ -85,20 +85,22 @@ impl<'a> Formattable for Pattern<'a> {
|
||||
RecordDestructure(loc_patterns) => {
|
||||
buf.indent(indent);
|
||||
buf.push_str("{");
|
||||
buf.spaces(1);
|
||||
|
||||
let mut it = loc_patterns.iter().peekable();
|
||||
if !loc_patterns.is_empty() {
|
||||
buf.spaces(1);
|
||||
let mut it = loc_patterns.iter().peekable();
|
||||
while let Some(loc_pattern) = it.next() {
|
||||
loc_pattern.format(buf, indent);
|
||||
|
||||
while let Some(loc_pattern) = it.next() {
|
||||
loc_pattern.format(buf, indent);
|
||||
|
||||
if it.peek().is_some() {
|
||||
buf.push_str(",");
|
||||
buf.spaces(1);
|
||||
if it.peek().is_some() {
|
||||
buf.push_str(",");
|
||||
buf.spaces(1);
|
||||
}
|
||||
}
|
||||
buf.spaces(1);
|
||||
}
|
||||
|
||||
buf.push_str(" }");
|
||||
buf.push_str("}");
|
||||
}
|
||||
|
||||
RequiredField(name, loc_pattern) => {
|
||||
|
@ -2727,6 +2727,61 @@ mod test_fmt {
|
||||
#[test]
|
||||
fn empty_record() {
|
||||
expr_formats_same("{}");
|
||||
expr_formats_to("{ }", "{}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_record_patterns() {
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
f = \{ } -> "Hello World"
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
f = \{} -> "Hello World"
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
f = \a, b -> { }
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
f = \a, b -> {}
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
expr_formats_to(
|
||||
indoc!(
|
||||
r#"
|
||||
{ } <- f a b
|
||||
|
||||
{}
|
||||
"#
|
||||
),
|
||||
indoc!(
|
||||
r#"
|
||||
{} <- f a b
|
||||
|
||||
{}
|
||||
"#
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -78,7 +78,7 @@ updateCost = \current, neighbor, model ->
|
||||
astar : (position, position -> F64), (position -> Set position), position, Model position -> Result (List position) {}
|
||||
astar = \costFn, moveFn, goal, model ->
|
||||
when cheapestOpen (\source -> costFn source goal) model is
|
||||
Err { } ->
|
||||
Err {} ->
|
||||
Err {}
|
||||
|
||||
Ok current ->
|
||||
|
@ -13,7 +13,7 @@ main =
|
||||
|> Task.putLine
|
||||
|
||||
show : RedBlackTree I64 {} -> Str
|
||||
show = \tree -> showRBTree tree Num.toStr (\{ } -> "{}")
|
||||
show = \tree -> showRBTree tree Num.toStr (\{} -> "{}")
|
||||
|
||||
showRBTree : RedBlackTree k v, (k -> Str), (v -> Str) -> Str
|
||||
showRBTree = \tree, showKey, showValue ->
|
||||
|
@ -6,7 +6,7 @@ Task ok err : Effect.Effect (Result ok err)
|
||||
|
||||
forever : Task val err -> Task * err
|
||||
forever = \task ->
|
||||
looper = \{ } ->
|
||||
looper = \{} ->
|
||||
task
|
||||
|> Effect.map
|
||||
\res ->
|
||||
|
@ -200,7 +200,7 @@ interpretCtxLoop = \ctx ->
|
||||
# `"` end of string
|
||||
when Str.fromUtf8 bytes is
|
||||
Ok str ->
|
||||
{ } <- Task.await (Stdout.raw str)
|
||||
{} <- Task.await (Stdout.raw str)
|
||||
Task.succeed (Step { newCtx & state: Executing })
|
||||
|
||||
Err _ ->
|
||||
@ -481,7 +481,7 @@ stepExecCtx = \ctx, char ->
|
||||
Ok (T popCtx num) ->
|
||||
when Str.fromUtf8 [ Num.intCast num ] is
|
||||
Ok str ->
|
||||
{ } <- Task.await (Stdout.raw str)
|
||||
{} <- Task.await (Stdout.raw str)
|
||||
Task.succeed popCtx
|
||||
|
||||
Err _ ->
|
||||
@ -494,7 +494,7 @@ stepExecCtx = \ctx, char ->
|
||||
# `.` write int
|
||||
when popNumber ctx is
|
||||
Ok (T popCtx num) ->
|
||||
{ } <- Task.await (Stdout.raw (Num.toStr (Num.intCast num)))
|
||||
{} <- Task.await (Stdout.raw (Num.toStr (Num.intCast num)))
|
||||
Task.succeed popCtx
|
||||
|
||||
Err e ->
|
||||
|
@ -23,5 +23,5 @@ withOpen : Str, (Handle -> Task {} a) -> Task {} a
|
||||
withOpen = \path, callback ->
|
||||
handle <- Task.await (open path)
|
||||
result <- Task.attempt (callback handle)
|
||||
{ } <- Task.await (close handle)
|
||||
{} <- Task.await (close handle)
|
||||
Task.fromResult result
|
||||
|
@ -6,7 +6,7 @@ Task ok err : Effect.Effect (Result ok err)
|
||||
|
||||
forever : Task val err -> Task * err
|
||||
forever = \task ->
|
||||
looper = \{ } ->
|
||||
looper = \{} ->
|
||||
task
|
||||
|> Effect.map
|
||||
\res ->
|
||||
|
@ -10,8 +10,8 @@ main =
|
||||
\line ->
|
||||
Effect.after
|
||||
(Effect.putLine "You entered: \(line)")
|
||||
\{ } ->
|
||||
\{} ->
|
||||
Effect.after
|
||||
(Effect.putLine "It is known")
|
||||
\{ } ->
|
||||
\{} ->
|
||||
Effect.always {}
|
||||
|
@ -7,7 +7,7 @@ Model : Str
|
||||
|
||||
main : Program Model
|
||||
main = {
|
||||
init: \{ } -> "Hello World",
|
||||
init: \{} -> "Hello World",
|
||||
update: \model, new -> Str.concat model new,
|
||||
view: \model -> Str.concat model "!",
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user