diff --git a/CHANGES.md b/CHANGES.md index 67dcb7faac..30269a36cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,18 @@ profile. This started with version 0.26.0. ### Fixed +- Fix `begin match … end` (and `begin if … end`) branches: with + `if-then-else=fit-or-vertical` the `match … with` header no longer splits + over several lines and `end` is aligned with `begin`; and a leading comment + on the body no longer reindents it — `begin` keeps the body one indent in + instead of gluing the keyword to the comment. + (#2810, @MisterDA) + +- Fix indentation of a bare `match`/`function`/`try` branch preceded by a + comment with `if-then-else=fit-or-vertical`: the branch is no longer + indented relative to the comment's end column. + (#2810, @MisterDA) + - Fix formatting oscillation with `if-then-else=fit-or-vertical` and `begin...end`. (#2800, @MisterDA) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index a136f24f34..83c39cfebf 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -2581,6 +2581,7 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens in let p = Params.get_if_then_else c.conf ~cmts_before_opt + ~has_cmts_before:(Cmts.has_before c.cmts) ~pro:(fmt_if first pro_inner) ~first ~last ~parens_bch ~parens_prev_bch:!parens_prev_bch ~xcond ~xbch ~expr_loc:pexp_loc @@ -2590,11 +2591,20 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens ~fmt_cond:(fmt_expression ~box:false c) ~cmts_before_kw ~cmts_after_kw in - let branch_pro = + let branch_pro, wrap_parens = match raw_cmts_after_kw with | Some cmts -> - Params.raw_cmts_branch_pro c.conf cmts - | None -> p.branch_pro + let bp = + Params.raw_cmts_branch_pro c.conf cmts + in + if + parens_bch + && Params + .is_special_or_nested_special_beginend + xbch.ast.pexp_desc + then (bp $ str "(", fun k -> k $ str ")") + else (bp, p.wrap_parens) + | None -> (p.branch_pro, p.wrap_parens) in let wrap_beginend = match p.beginend_loc with @@ -2607,7 +2617,7 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens $ p.box_keyword_and_expr ( branch_pro $ wrap_beginend - (p.wrap_parens + (wrap_parens ( fmt_expression c ?box:p.box_expr ~parens:false ?pro:p.expr_pro ?eol:p.expr_eol p.branch_expr @@ -3034,11 +3044,23 @@ and fmt_beginend c ~loc ?(box = true) ?(pro = noop) ~ctx ~ctx0 ~fmt_atrs $ match e.pexp_desc with | Pexp_match _ | Pexp_try _ | Pexp_function _ | Pexp_ifthenelse _ -> - beginend_box - (fmt_expression c - ~pro:(pro $ begin_ $ str " ") - ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) - $ end_ + (* In an [if-then-else] branch the branch break indents [begin] one + level in (e.g. [fit-or-vertical], whose branch box is [hovbox 0]), + while [end] follows the branch box; wrap the body and [end] together + so [end] lines up with [begin]. Other contexts (e.g. [map x begin + fun … end] as an application argument) must keep their own + indentation. *) + let box = + match ctx0 with + | Exp {pexp_desc= Pexp_ifthenelse _; _} -> hvbox 0 + | _ -> Fn.id + in + box + ( beginend_box + (fmt_expression c + ~pro:(pro $ begin_ $ str " ") + ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) + $ end_ ) | _ -> beginend_box ( hvbox 0 (pro $ begin_) diff --git a/lib/Params.ml b/lib/Params.ml index 155f82c562..cce61575c5 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -519,7 +519,7 @@ let is_special_or_nested_special_beginend = function let raw_cmts_branch_pro (c : Conf.t) cmts = match c.fmt_opts.if_then_else.v with | `Compact -> break 1000 0 $ cmts $ break 1000 0 - | _ -> break 1000 2 $ cmts + | _ -> break 1000 2 $ cmts $ break 1000 2 type cases = { leading_space: Fmt.t @@ -858,15 +858,22 @@ type if_then_else = ; break_end_branch: Fmt.t ; space_between_branches: Fmt.t } -let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last - ~parens_bch ~parens_prev_bch ~xcond ~xbch ~expr_loc ~fmt_infix_ext_attrs - ~infix_ext_attrs ~fmt_cond ~cmts_before_kw ~cmts_after_kw = +let get_if_then_else (c : Conf.t) ~cmts_before_opt ~has_cmts_before ~pro + ~first ~last ~parens_bch ~parens_prev_bch ~xcond ~xbch ~expr_loc + ~fmt_infix_ext_attrs ~infix_ext_attrs ~fmt_cond ~cmts_before_kw + ~cmts_after_kw = let imd = c.fmt_opts.indicate_multiline_delimiters.v in let beginend_loc, infix_ext_attrs_beginend, branch_expr = let ast = xbch.Ast.ast in match ast with - | {pexp_desc= Pexp_beginend ({pexp_desc; _}, _); _} - when is_special_beginend pexp_desc -> + | {pexp_desc= Pexp_beginend (nested_exp, _); _} + when is_special_beginend nested_exp.pexp_desc + && not (has_cmts_before nested_exp.pexp_loc) -> + (* [begin match/try/function/if … end] shortcut: keep [begin] glued + to the body keyword. A leading comment on the body breaks the + glue, so fall through to the plain [begin]/[end] machinery below, + which puts [begin] on its own line and the body (comment included) + one indent in. *) (None, None, xbch) | { pexp_desc= Pexp_beginend (nested_exp, infix_ext_attrs) ; pexp_attributes= [] @@ -878,6 +885,18 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last | _ -> (None, None, xbch) in let has_beginend = Option.is_some beginend_loc in + (* A [begin]/[end] branch whose body is a [match]/[try]/[function]/[if] + (the [begin match … end] shortcut, or its plain form when a leading + comment de-glues [begin] from the body). Such a body has a header + ([match … with], [if … then]) that the branch [break_unless_newline + 1000] would wrongly split, so it provides its own break after [begin] + instead. Simple-bodied [begin … end] keeps the regular branch break. *) + let is_special_beginend_branch = + match xbch.ast.pexp_desc with + | Pexp_beginend (nested_exp, _) -> + is_special_beginend nested_exp.pexp_desc + | _ -> false + in let wrap_parens ~wrap_breaks k = if has_beginend then let infix_ext_attrs_beginend = @@ -929,31 +948,44 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last | None when parens_bch -> str " " | None -> break 1 indent in + (* When a comment precedes a multi-line + [match]/[function]/[try]/[if-then-else] branch body (or a [begin]/[end] + wrapping one), emit it from [branch_pro] with forced breaks, so the + branch indentation stays stable regardless of where the comment was + initially attached. [default] is the comment-less [branch_pro] for the + current mode, [guard] an extra mode-specific applicability condition. + Returns [(branch_pro, has_cmts_before)] where [has_cmts_before] is true + when a comment was consumed into [branch_pro]. *) + let branch_pro_with_cmts ~default ~guard = + if + (not has_beginend) + && (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) + && (not has_cmts_after_kw) && guard + then + match cmts_before_opt xbch.ast.pexp_loc with + | Some cmts -> (raw_cmts_branch_pro c cmts, true) + | None -> ( + match xbch.ast.pexp_desc with + | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) + when is_special_beginend pexp_desc -> ( + match cmts_before_opt pexp_loc with + | Some cmts -> (raw_cmts_branch_pro c cmts, true) + | None -> (default, false) ) + | _ -> (default, false) ) + else (default, false) + in match c.fmt_opts.if_then_else.v with | `Compact -> - let branch_pro_with_cmts = - if - (not has_beginend) && (not parens_bch) - && (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) - && (not has_cmts_after_kw) - && is_special_or_nested_special_beginend xbch.ast.pexp_desc - then - match cmts_before_opt xbch.ast.pexp_loc with - | Some cmts -> break 1000 0 $ cmts $ break 1000 0 - | None -> ( - match xbch.ast.pexp_desc with - | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) - when is_special_beginend pexp_desc -> ( - match cmts_before_opt pexp_loc with - | Some cmts -> break 1000 0 $ cmts $ break 1000 0 - | None -> branch_pro ~indent:0 () ) - | _ -> branch_pro ~indent:0 () ) - else branch_pro ~indent:0 () + let branch_pro, _has_cmts = + branch_pro_with_cmts ~default:(branch_pro ~indent:0 ()) + ~guard: + ( (not parens_bch) + && is_special_or_nested_special_beginend xbch.ast.pexp_desc ) in { box_branch= hovbox ~name:"Params.get_if_then_else `Compact" 2 ; cond= cond () ; box_keyword_and_expr= Fn.id - ; branch_pro= branch_pro_with_cmts + ; branch_pro ; wrap_parens= wrap_parens ~wrap_breaks: @@ -973,7 +1005,7 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last ; branch_pro= branch_pro ~begin_end_offset:0 () ; wrap_parens= wrap_parens ~wrap_breaks:(wrap (break 1000 2) noop) ; beginend_loc - ; box_expr= Some has_beginend + ; box_expr= Some (has_beginend && not is_special_beginend_branch) ; expr_pro= None ; expr_eol= Some (break 1 2) ; branch_expr @@ -982,23 +1014,29 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last ; space_between_branches= fmt_if (has_beginend || parens_bch) (str " ") } | `Fit_or_vertical -> - let branch_pro_with_cmts = - if - (not has_beginend) - && (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) - && not has_cmts_after_kw - then - match cmts_before_opt xbch.ast.pexp_loc with - | Some cmts -> break 1000 2 $ cmts - | None -> ( - match xbch.ast.pexp_desc with - | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) - when is_special_beginend pexp_desc -> ( - match cmts_before_opt pexp_loc with - | Some cmts -> break 1000 2 $ cmts - | None -> branch_pro ~begin_end_offset:0 () ) - | _ -> branch_pro ~begin_end_offset:0 () ) - else branch_pro ~begin_end_offset:0 () + let branch_pro_default, has_cmts = + branch_pro_with_cmts + ~default:(branch_pro ~begin_end_offset:0 ()) + ~guard:true + in + let paren_glue = + has_cmts && parens_bch + && is_special_or_nested_special_beginend xbch.ast.pexp_desc + in + let branch_pro, wrap_parens = + if paren_glue then + let cls = + match imd with + | `Closing_on_separate_line -> break 1000 0 $ str ")" + | _ -> str ")" + in + (branch_pro_default $ str "(", fun k -> k $ cls) + else + ( branch_pro_default + , wrap_parens + ~wrap_breaks: + (get_parens_breaks ~opn_hint_indent:2 + ~cls_hint:((1, 0), (1000, 0)) ) ) in { box_branch= hovbox @@ -1007,19 +1045,18 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last | _ -> 0 ) ; cond= cond () ; box_keyword_and_expr= Fn.id - ; branch_pro= branch_pro_with_cmts - ; wrap_parens= - wrap_parens - ~wrap_breaks: - (get_parens_breaks ~opn_hint_indent:2 - ~cls_hint:((1, 0), (1000, 0)) ) + ; branch_pro + ; wrap_parens ; beginend_loc ; box_expr= Some false ; expr_pro= - Some - (fmt_if - (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) - (break_unless_newline 1000 2) ) + ( if is_special_beginend_branch || paren_glue then None + else + Some + (fmt_if + (not + (Location.is_single_line expr_loc c.fmt_opts.margin.v) ) + (break_unless_newline 1000 2) ) ) ; expr_eol= Some (break 1 2) ; branch_expr ; break_end_branch= noop @@ -1040,7 +1077,9 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last ~cls_hint:((1, 0), (1000, 0)) ) ; beginend_loc ; box_expr= None - ; expr_pro= Some (break_unless_newline 1000 2) + ; expr_pro= + ( if is_special_beginend_branch then None + else Some (break_unless_newline 1000 2) ) ; expr_eol= None ; branch_expr ; break_end_branch= noop diff --git a/lib/Params.mli b/lib/Params.mli index 776ba51399..6c3ec7fb1b 100644 --- a/lib/Params.mli +++ b/lib/Params.mli @@ -221,6 +221,7 @@ type if_then_else = val get_if_then_else : Conf.t -> cmts_before_opt:(Location.t -> Fmt.t option) + -> has_cmts_before:(Location.t -> bool) -> pro:Fmt.t -> first:bool -> last:bool diff --git a/test/passing/refs.ahrefs/ite-compact.ml.ref b/test/passing/refs.ahrefs/ite-compact.ml.ref index 62816583fb..e649fbc206 100644 --- a/test/passing/refs.ahrefs/ite-compact.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact.ml.ref @@ -207,10 +207,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -230,3 +230,35 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref index 5325ce7382..ece1f0c637 100644 --- a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref @@ -226,10 +226,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -250,3 +250,36 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err index fc51770a03..c19dc1cebd 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:116 exceeds the margin Warning: ite-fit_or_vertical.ml:121 exceeds the margin Warning: ite-fit_or_vertical.ml:126 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:260 exceeds the margin +Warning: ite-fit_or_vertical.ml:257 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref index f6dbbe1bc9..86f381d59c 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -258,9 +255,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -273,3 +270,38 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + (match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err index 5fedffb9e3..357f0a1a12 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:257 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:270 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:267 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref index 568bde8b61..3f8bdccfd1 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref @@ -254,12 +254,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -268,9 +265,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f ) (* Comment before nested if in then branch - Compact mode oscillation *) @@ -284,3 +281,39 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + (match e with + | A -> a + | B -> b + ) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err index 9eff570afe..7a8b20a690 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:116 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:121 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:126 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref index f6dbbe1bc9..86f381d59c 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -258,9 +255,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -273,3 +270,38 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + (match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kr.ml.ref b/test/passing/refs.ahrefs/ite-kr.ml.ref index 40be4b4384..a86d5a549d 100644 --- a/test/passing/refs.ahrefs/ite-kr.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr.ml.ref @@ -283,9 +283,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -310,3 +310,39 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref index fdf791c892..540f41e3ad 100644 --- a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref @@ -290,9 +290,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -317,3 +317,39 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first.ml.ref b/test/passing/refs.ahrefs/ite-kw_first.ml.ref index 0dd5acf1bc..09b9ae024f 100644 --- a/test/passing/refs.ahrefs/ite-kw_first.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first.ml.ref @@ -239,10 +239,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -265,3 +265,38 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref index e0b9284f1d..157cadaacc 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref @@ -258,10 +258,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -285,3 +285,39 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref index 0dd5acf1bc..09b9ae024f 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref @@ -239,10 +239,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -265,3 +265,38 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref index 62816583fb..e649fbc206 100644 --- a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref @@ -207,10 +207,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -230,3 +230,35 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.err b/test/passing/refs.ahrefs/ite-vertical.ml.err index b2aa89ed3a..9e3cea0178 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:284 exceeds the margin -Warning: ite-vertical.ml:297 exceeds the margin +Warning: ite-vertical.ml:295 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.ref b/test/passing/refs.ahrefs/ite-vertical.ml.ref index 6d41adb8e8..476de3cbaa 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-vertical.ml.ref @@ -281,13 +281,11 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -310,3 +308,38 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite.ml.ref b/test/passing/refs.ahrefs/ite.ml.ref index 62816583fb..e649fbc206 100644 --- a/test/passing/refs.ahrefs/ite.ml.ref +++ b/test/passing/refs.ahrefs/ite.ml.ref @@ -207,10 +207,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -230,3 +230,35 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-compact.ml.ref b/test/passing/refs.default/ite-compact.ml.ref index 3672c44671..ec66086711 100644 --- a/test/passing/refs.default/ite-compact.ml.ref +++ b/test/passing/refs.default/ite-compact.ml.ref @@ -201,10 +201,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -223,3 +223,31 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-compact_closing.ml.ref b/test/passing/refs.default/ite-compact_closing.ml.ref index 8fc1245502..09e4a41458 100644 --- a/test/passing/refs.default/ite-compact_closing.ml.ref +++ b/test/passing/refs.default/ite-compact_closing.ml.ref @@ -216,10 +216,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -238,3 +238,31 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.err b/test/passing/refs.default/ite-fit_or_vertical.ml.err index 19b7a99c10..6dd85c4c82 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:115 exceeds the margin Warning: ite-fit_or_vertical.ml:120 exceeds the margin Warning: ite-fit_or_vertical.ml:125 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:260 exceeds the margin +Warning: ite-fit_or_vertical.ml:257 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.ref b/test/passing/refs.default/ite-fit_or_vertical.ml.ref index 4214040eeb..59312b943e 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -259,8 +256,8 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> f + match x with + | A -> f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -273,3 +270,36 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err index 126313710f..2be0bcc178 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:256 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:269 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:266 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref index 64810afbfe..5da15c44f3 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref @@ -253,12 +253,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -268,8 +265,8 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> f + match x with + | A -> f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -282,3 +279,36 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err index bef0700a1d..3700b779cf 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:125 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref index 4214040eeb..59312b943e 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -259,8 +256,8 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> f + match x with + | A -> f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -273,3 +270,36 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kr.ml.ref b/test/passing/refs.default/ite-kr.ml.ref index 0773c03e16..2b0434dfc3 100644 --- a/test/passing/refs.default/ite-kr.ml.ref +++ b/test/passing/refs.default/ite-kr.ml.ref @@ -280,9 +280,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -306,3 +306,33 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kr_closing.ml.ref b/test/passing/refs.default/ite-kr_closing.ml.ref index d16ca01a77..e952383e8d 100644 --- a/test/passing/refs.default/ite-kr_closing.ml.ref +++ b/test/passing/refs.default/ite-kr_closing.ml.ref @@ -287,9 +287,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -313,3 +313,33 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first.ml.ref b/test/passing/refs.default/ite-kw_first.ml.ref index a0941721b7..bedcc2f63e 100644 --- a/test/passing/refs.default/ite-kw_first.ml.ref +++ b/test/passing/refs.default/ite-kw_first.ml.ref @@ -233,10 +233,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -259,3 +259,36 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first_closing.ml.ref b/test/passing/refs.default/ite-kw_first_closing.ml.ref index 546b602f91..9a061ca15d 100644 --- a/test/passing/refs.default/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.default/ite-kw_first_closing.ml.ref @@ -248,10 +248,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -274,3 +274,36 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref index a0941721b7..bedcc2f63e 100644 --- a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref @@ -233,10 +233,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -259,3 +259,36 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-no_indicate.ml.ref b/test/passing/refs.default/ite-no_indicate.ml.ref index 3672c44671..ec66086711 100644 --- a/test/passing/refs.default/ite-no_indicate.ml.ref +++ b/test/passing/refs.default/ite-no_indicate.ml.ref @@ -201,10 +201,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -223,3 +223,31 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-vertical.ml.err b/test/passing/refs.default/ite-vertical.ml.err index 3a6f50f9a7..906b414ced 100644 --- a/test/passing/refs.default/ite-vertical.ml.err +++ b/test/passing/refs.default/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:286 exceeds the margin -Warning: ite-vertical.ml:299 exceeds the margin +Warning: ite-vertical.ml:297 exceeds the margin diff --git a/test/passing/refs.default/ite-vertical.ml.ref b/test/passing/refs.default/ite-vertical.ml.ref index 04eb6fbb61..e667a06c8b 100644 --- a/test/passing/refs.default/ite-vertical.ml.ref +++ b/test/passing/refs.default/ite-vertical.ml.ref @@ -283,13 +283,11 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -312,3 +310,36 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite.ml.ref b/test/passing/refs.default/ite.ml.ref index 3672c44671..ec66086711 100644 --- a/test/passing/refs.default/ite.ml.ref +++ b/test/passing/refs.default/ite.ml.ref @@ -201,10 +201,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -223,3 +223,31 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.janestreet/ite-compact.ml.ref b/test/passing/refs.janestreet/ite-compact.ml.ref index 02d22ac756..4648348f9f 100644 --- a/test/passing/refs.janestreet/ite-compact.ml.ref +++ b/test/passing/refs.janestreet/ite-compact.ml.ref @@ -235,3 +235,36 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-compact_closing.ml.ref b/test/passing/refs.janestreet/ite-compact_closing.ml.ref index e98406e08f..b5c5cd3afc 100644 --- a/test/passing/refs.janestreet/ite-compact_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-compact_closing.ml.ref @@ -250,3 +250,39 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref index 35c0fdedf6..908b7c640f 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref @@ -271,9 +271,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) ;; (* Comment before nested if in then branch - Compact mode oscillation *) @@ -288,3 +288,39 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + (match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + (match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref index 97b3d2aca5..22664483fc 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref @@ -282,9 +282,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f ) ;; @@ -300,3 +300,42 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + (match e with + | A -> a + | B -> b + ) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + (match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref index 35c0fdedf6..908b7c640f 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref @@ -271,9 +271,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) ;; (* Comment before nested if in then branch - Compact mode oscillation *) @@ -288,3 +288,39 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + (match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + (match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kr.ml.ref b/test/passing/refs.janestreet/ite-kr.ml.ref index 20a2ed5f27..2870979727 100644 --- a/test/passing/refs.janestreet/ite-kr.ml.ref +++ b/test/passing/refs.janestreet/ite-kr.ml.ref @@ -336,3 +336,42 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kr_closing.ml.ref b/test/passing/refs.janestreet/ite-kr_closing.ml.ref index 0bcf83e649..bfe303577a 100644 --- a/test/passing/refs.janestreet/ite-kr_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kr_closing.ml.ref @@ -343,3 +343,42 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first.ml.ref b/test/passing/refs.janestreet/ite-kw_first.ml.ref index 2b16944d25..e9b034405b 100644 --- a/test/passing/refs.janestreet/ite-kw_first.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first.ml.ref @@ -269,3 +269,39 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref index 3111239793..e203a272fe 100644 --- a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref @@ -284,3 +284,42 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref index 2b16944d25..e9b034405b 100644 --- a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref @@ -269,3 +269,39 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-no_indicate.ml.ref b/test/passing/refs.janestreet/ite-no_indicate.ml.ref index 02d22ac756..4648348f9f 100644 --- a/test/passing/refs.janestreet/ite-no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-no_indicate.ml.ref @@ -235,3 +235,36 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-vertical.ml.ref b/test/passing/refs.janestreet/ite-vertical.ml.ref index d99e8aad56..74865e32b4 100644 --- a/test/passing/refs.janestreet/ite-vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-vertical.ml.ref @@ -333,3 +333,39 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite.ml.ref b/test/passing/refs.janestreet/ite.ml.ref index 02d22ac756..4648348f9f 100644 --- a/test/passing/refs.janestreet/ite.ml.ref +++ b/test/passing/refs.janestreet/ite.ml.ref @@ -235,3 +235,36 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.ocamlformat/ite-compact.ml.ref b/test/passing/refs.ocamlformat/ite-compact.ml.ref index 4860d9f001..0138bd452d 100644 --- a/test/passing/refs.ocamlformat/ite-compact.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact.ml.ref @@ -200,10 +200,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -222,3 +222,33 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref index d7fb7bea79..8b3bfca819 100644 --- a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref @@ -210,10 +210,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -232,3 +232,33 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err index 35c4dd8d0a..65da7bfbf6 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical.ml:250 exceeds the margin -Warning: ite-fit_or_vertical.ml:263 exceeds the margin +Warning: ite-fit_or_vertical.ml:260 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref index dba064e102..465a451644 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref @@ -247,12 +247,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -262,9 +259,9 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> - f + match x with + | A -> + f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -277,3 +274,40 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err index 23c64dbaf7..7fd8ac1f7b 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:255 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:268 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:265 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref index fda9f31bfd..b964a93091 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref @@ -252,12 +252,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -267,9 +264,9 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> - f + match x with + | A -> + f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -282,3 +279,40 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err index 0ef658ec2b..55504ff751 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:110 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref index 5faeb08f42..41fa87983f 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -259,9 +256,9 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> - f + match x with + | A -> + f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -274,3 +271,40 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kr.ml.ref b/test/passing/refs.ocamlformat/ite-kr.ml.ref index 7a8ac0e004..3922823762 100644 --- a/test/passing/refs.ocamlformat/ite-kr.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr.ml.ref @@ -281,9 +281,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -308,3 +308,35 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref index ca04feee60..afbfcc262a 100644 --- a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref @@ -285,9 +285,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -312,3 +312,35 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref index df8130036d..d375c12b31 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref @@ -231,10 +231,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -258,3 +258,40 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> + a + | B -> + b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref index b10567c2e3..fbfca33277 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref @@ -241,10 +241,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -268,3 +268,40 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> + a + | B -> + b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref index 1644f1dd7d..e9eae18493 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref @@ -228,10 +228,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -255,3 +255,40 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> + a + | B -> + b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref index 8665872059..5512f98336 100644 --- a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref @@ -197,10 +197,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -219,3 +219,33 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.err b/test/passing/refs.ocamlformat/ite-vertical.ml.err index 6d93e7b45d..94ff935b4d 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-vertical.ml:291 exceeds the margin -Warning: ite-vertical.ml:304 exceeds the margin +Warning: ite-vertical.ml:302 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.ref b/test/passing/refs.ocamlformat/ite-vertical.ml.ref index 8108fa2e00..6bf6ca9f85 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.ref @@ -288,13 +288,11 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -318,3 +316,40 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite.ml.ref b/test/passing/refs.ocamlformat/ite.ml.ref index 4860d9f001..0138bd452d 100644 --- a/test/passing/refs.ocamlformat/ite.ml.ref +++ b/test/passing/refs.ocamlformat/ite.ml.ref @@ -200,10 +200,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -222,3 +222,33 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/tests/ite.ml b/test/passing/tests/ite.ml index 0bdab6413b..d324aa074d 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -227,3 +227,35 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with + | A -> a + | B -> b + +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else begin + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end