mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Format crash
This commit is contained in:
parent
fee01166c7
commit
1011ce9fba
3 changed files with 43 additions and 1 deletions
|
@ -43,7 +43,8 @@ impl<'a> Formattable for Expr<'a> {
|
||||||
| MalformedIdent(_, _)
|
| MalformedIdent(_, _)
|
||||||
| MalformedClosure
|
| MalformedClosure
|
||||||
| Tag(_)
|
| Tag(_)
|
||||||
| OpaqueRef(_) => false,
|
| OpaqueRef(_)
|
||||||
|
| Crash => false,
|
||||||
|
|
||||||
// These expressions always have newlines
|
// These expressions always have newlines
|
||||||
Defs(_, _) | When(_, _) => true,
|
Defs(_, _) | When(_, _) => true,
|
||||||
|
@ -191,6 +192,10 @@ impl<'a> Formattable for Expr<'a> {
|
||||||
buf.push('_');
|
buf.push('_');
|
||||||
buf.push_str(name);
|
buf.push_str(name);
|
||||||
}
|
}
|
||||||
|
Crash => {
|
||||||
|
buf.indent(indent);
|
||||||
|
buf.push_str("crash");
|
||||||
|
}
|
||||||
Apply(loc_expr, loc_args, _) => {
|
Apply(loc_expr, loc_args, _) => {
|
||||||
buf.indent(indent);
|
buf.indent(indent);
|
||||||
if apply_needs_parens && !loc_args.is_empty() {
|
if apply_needs_parens && !loc_args.is_empty() {
|
||||||
|
|
|
@ -666,6 +666,7 @@ impl<'a> RemoveSpaces<'a> for Expr<'a> {
|
||||||
arena.alloc(a.remove_spaces(arena)),
|
arena.alloc(a.remove_spaces(arena)),
|
||||||
arena.alloc(b.remove_spaces(arena)),
|
arena.alloc(b.remove_spaces(arena)),
|
||||||
),
|
),
|
||||||
|
Expr::Crash => Expr::Crash,
|
||||||
Expr::Defs(a, b) => {
|
Expr::Defs(a, b) => {
|
||||||
let mut defs = a.clone();
|
let mut defs = a.clone();
|
||||||
defs.space_before = vec![Default::default(); defs.len()];
|
defs.space_before = vec![Default::default(); defs.len()];
|
||||||
|
|
|
@ -5829,6 +5829,42 @@ mod test_fmt {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn format_crash() {
|
||||||
|
expr_formats_same(indoc!(
|
||||||
|
r#"
|
||||||
|
_ = crash
|
||||||
|
_ = crash ""
|
||||||
|
|
||||||
|
crash "" ""
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
expr_formats_to(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
_ = crash
|
||||||
|
_ = crash ""
|
||||||
|
_ = crash "" ""
|
||||||
|
try
|
||||||
|
foo
|
||||||
|
(\_ -> crash "")
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
_ = crash
|
||||||
|
_ = crash ""
|
||||||
|
_ = crash "" ""
|
||||||
|
|
||||||
|
try
|
||||||
|
foo
|
||||||
|
(\_ -> crash "")
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// this is a parse error atm
|
// this is a parse error atm
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn multiline_apply() {
|
// fn multiline_apply() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue