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