From 8cf0db5a67c23201748d9ae14cc327b07e4db0cd Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 20 Sep 2024 17:36:54 +0200 Subject: [PATCH] Extract tests from the 5.2 compat PR (#2578) This will make the diffs more readable. --- test/passing/dune.inc | 20 +- test/passing/tests/attributes.ml.opts | 0 test/passing/tests/fun_decl.ml | 32 +++ .../tests/function_indent-never.ml.ref | 6 + test/passing/tests/function_indent.ml | 5 + test/passing/tests/function_indent.ml.ref | 6 + test/passing/tests/issue289.ml.opts | 1 + .../tests/let_binding-deindent-fun.ml.err | 1 + .../tests/let_binding-deindent-fun.ml.opts | 1 + .../tests/let_binding-deindent-fun.ml.ref | 271 ++++++++++++++++++ .../tests/let_binding-in_indent.ml.ref | 8 + test/passing/tests/let_binding-indent.ml.ref | 9 + test/passing/tests/let_binding.ml | 11 + test/passing/tests/let_binding.ml.ref | 8 + 14 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 test/passing/tests/attributes.ml.opts create mode 100644 test/passing/tests/issue289.ml.opts create mode 100644 test/passing/tests/let_binding-deindent-fun.ml.err create mode 100644 test/passing/tests/let_binding-deindent-fun.ml.opts create mode 100644 test/passing/tests/let_binding-deindent-fun.ml.ref diff --git a/test/passing/dune.inc b/test/passing/dune.inc index bb963092e2..1e38b8b886 100644 --- a/test/passing/dune.inc +++ b/test/passing/dune.inc @@ -2753,7 +2753,7 @@ (action (with-stdout-to issue289.ml.stdout (with-stderr-to issue289.ml.stderr - (run %{bin:ocamlformat} --margin-check %{dep:tests/issue289.ml}))))) + (run %{bin:ocamlformat} --margin-check --max-iter=3 %{dep:tests/issue289.ml}))))) (rule (alias runtest) @@ -3464,6 +3464,24 @@ (package ocamlformat) (action (diff tests/lazy.ml.err lazy.ml.stderr))) +(rule + (deps tests/.ocamlformat ) + (package ocamlformat) + (action + (with-stdout-to let_binding-deindent-fun.ml.stdout + (with-stderr-to let_binding-deindent-fun.ml.stderr + (run %{bin:ocamlformat} --margin-check --no-let-binding-deindent-fun %{dep:tests/let_binding.ml}))))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/let_binding-deindent-fun.ml.ref let_binding-deindent-fun.ml.stdout))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/let_binding-deindent-fun.ml.err let_binding-deindent-fun.ml.stderr))) + (rule (deps tests/.ocamlformat ) (package ocamlformat) diff --git a/test/passing/tests/attributes.ml.opts b/test/passing/tests/attributes.ml.opts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/passing/tests/fun_decl.ml b/test/passing/tests/fun_decl.ml index 8973cc2cdc..0e5933623d 100644 --- a/test/passing/tests/fun_decl.ml +++ b/test/passing/tests/fun_decl.ml @@ -14,6 +14,13 @@ let _ = fooooooooooooooooooooooooooo foooooooooooooo foooooooooo -> some_large_computation +let () = + fun x : int -> + fun r : int -> + fun u -> + foooooooooooooooooooooooooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooooooooooooooooooooooooooo + [@@@ocamlformat "wrap-fun-args=false"] let to_loc_trace @@ -70,3 +77,28 @@ let f ssssssssss = | '0' -> g accuuuuuuuuuum | '1' -> h accuuuuuuuuuum | _ -> i accuuuuuuuuuum ) + +let f ssssssssss = + String.fold ssssssssss ~init:innnnnnnnnnit ~f:(function + | '0' -> g accuuuuuuuuuum + | '1' -> h accuuuuuuuuuum + | _ -> i accuuuuuuuuuum ) + +let f _ = + let foooooooooooooooooooooooooooo = foooooooooooooooooooooooooooo in + fun x -> + let foooooooooooooooooooooooooooo = foooooooooooooooooooooooooooo in + x + +let f _ = + let foooooooooooooooooooooooooooo = foooooooooooooooooooooooooooo in + (* foo *) + fun x -> + let foooooooooooooooooooooooooooo = foooooooooooooooooooooooooooo in + x + +let space_break = + (* a stack is useless here, this would require adding a unit parameter *) + with_pp (fun fs -> + Box_debug.space_break fs ; + Format_.pp_print_space fs () ) diff --git a/test/passing/tests/function_indent-never.ml.ref b/test/passing/tests/function_indent-never.ml.ref index 729445cab6..de82a9280f 100644 --- a/test/passing/tests/function_indent-never.ml.ref +++ b/test/passing/tests/function_indent-never.ml.ref @@ -10,6 +10,12 @@ let foo = | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo ) +let foo = + fooooooooo foooooooo foooooooo foooooooo foooooooo foooooooo + ~foooooooo:(function + | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo + | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo ) + let foooooooo = if fooooooooooo then function | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo diff --git a/test/passing/tests/function_indent.ml b/test/passing/tests/function_indent.ml index 606fc3bc97..173574d8ba 100644 --- a/test/passing/tests/function_indent.ml +++ b/test/passing/tests/function_indent.ml @@ -10,6 +10,11 @@ let foo = | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo) +let foo = + fooooooooo foooooooo foooooooo foooooooo foooooooo foooooooo ~foooooooo:(function + | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo + | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo ) + let foooooooo = if fooooooooooo then function diff --git a/test/passing/tests/function_indent.ml.ref b/test/passing/tests/function_indent.ml.ref index ad1c0048cc..3c98e127ea 100644 --- a/test/passing/tests/function_indent.ml.ref +++ b/test/passing/tests/function_indent.ml.ref @@ -10,6 +10,12 @@ let foo = | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo ) +let foo = + fooooooooo foooooooo foooooooo foooooooo foooooooo foooooooo + ~foooooooo:(function + | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo + | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo ) + let foooooooo = if fooooooooooo then function | fooooooooooooooooooooooo -> foooooooooooooooooooooooooo diff --git a/test/passing/tests/issue289.ml.opts b/test/passing/tests/issue289.ml.opts new file mode 100644 index 0000000000..a2f04741b8 --- /dev/null +++ b/test/passing/tests/issue289.ml.opts @@ -0,0 +1 @@ +--max-iter=3 diff --git a/test/passing/tests/let_binding-deindent-fun.ml.err b/test/passing/tests/let_binding-deindent-fun.ml.err new file mode 100644 index 0000000000..b503ec1354 --- /dev/null +++ b/test/passing/tests/let_binding-deindent-fun.ml.err @@ -0,0 +1 @@ +Warning: tests/let_binding.ml:265 exceeds the margin diff --git a/test/passing/tests/let_binding-deindent-fun.ml.opts b/test/passing/tests/let_binding-deindent-fun.ml.opts new file mode 100644 index 0000000000..e67d267be8 --- /dev/null +++ b/test/passing/tests/let_binding-deindent-fun.ml.opts @@ -0,0 +1 @@ +--no-let-binding-deindent-fun \ No newline at end of file diff --git a/test/passing/tests/let_binding-deindent-fun.ml.ref b/test/passing/tests/let_binding-deindent-fun.ml.ref new file mode 100644 index 0000000000..33cef1365c --- /dev/null +++ b/test/passing/tests/let_binding-deindent-fun.ml.ref @@ -0,0 +1,271 @@ +(* Note that {[ let ident : typ = exp ]} is different from {[ let (ident : + typ) = exp ]}. The difference should be maintained *) + +let (_ : int) = x1 + +let (x : int) = x2 + +let (_ : int) = x3 + +let x : int = x4 + +let _ = + let (x : int) = x in + let x : int = x in + let (_ : int) = x in + let _ : int = x in + () + +let%ext (_ : int) = x1 + +let%ext (x : int) = x2 + +let%ext (_ : int) = x3 + +let%ext x : int = x4 + +let%ext _ = + let%ext (x : int) = x in + let%ext x : int = x in + let%ext (_ : int) = x in + let%ext (_ : int) = x in + () + +let [%ext let x = 3] = 2 + +let [%ext: [%exp let x = 3]] = 2 + +let f : 'a. 'a ty -> 'a = fun y -> g y + +let f (A _ | B | C) = () + +let f + ( AAAAAAAAAAAAAAAAAAAAAAAAAAAAa _ | BBBBBBBBBBBBBBBBBBBBBbb + | CCCCCCCCCCCCCCCCCCCCCCccccc ) = + () + +let f + ( AAAAAAAAAAAAAAAAAAAAAAAAAAAAa + ( EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEe | FFFFFFFFFFFFFFFFFFFFFFFFFFf + | GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGggggggggg ) + | BBBBBBBBBBBBBBBBBBBBBbb | CCCCCCCCCCCCCCCCCCCCCCccccc ) = + () + +let f (AAA (EEEEEEE | FFFFF | GGGGG) | BBBBBB | CCCCCCC) = () + +let f = function AAA (EEEEEEE | FFFFF | GGGGG) | BBBBBB | CCCCCCC -> () + +let f = function EEEEEEE | F | GGGGG | B | CCCCCCC -> () + +let f = function + | EEEEEEE | FFFFFFFFFFFFFFFFFFFFFFF | GGGGG + |BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbb | CCCCCCC -> + () + +let (_ : t -> t -> int) = (compare : int list -> int list -> int) + +let _ = + let[@test] rec f = x in + y + +module Let_and_compact = struct + [@@@ocamlformat "let-and=compact"] + + let x = 2 + + and y = 2 + + let _ = + let x = 2 and y = 2 in + 3 + + let _ = + let%ext x = 2 and y = 2 in + 3 +end + +module Let_and_sparse = struct + [@@@ocamlformat "let-and=sparse"] + + let x = 2 + + and y = 2 + + let _ = + let x = 2 + and y = 2 in + 3 + + let _ = + let%ext x = 2 + and y = 2 in + 3 +end + +let f aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccc + dddddddddddddddddd eeeeeeeeeeeeee = + () + +let _ = + fun aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccc + dddddddddddddddddd eeeeeeeeeeeeee -> + () + +let _ = + let (x : int) = x in + let x : int = x in + let (_ : int) = x in + let _ : int = x in + let%ext (x : int) = x in + let%ext x : int = x in + let%ext (_ : int) = x in + let%ext _ : int = x in + () + +let fooo = fooooooooooo [@@foo] + +let fooo = fooooooooooo [@@foo] + +and fooo = fooooooooooo [@@foo] +;; + +let foooo = fooooooooo [@@foo] in +fooooooooooooooooooooo + +let[@foo] fooo = fooooooooooo + +let[@foo] fooo = fooooooooooo + +and[@foo] fooo = fooooooooooo +;; + +let[@foo] foooo = fooooooooo in +fooooooooooooooooooooo + +let a : int = 0 + +let b = (0 : int) + +let _ = + let+ a = b in + c + +let _ = + let+ a = b and+ c = d in + e + +let _ = + if true then a + else + let+ a = b in + c + +let _ = + if true then + let+ a = b in + c + else d + +let _ = + match a with + | a -> ( + match a with + | a -> ( + let+ a = b in + match a with a -> a ) ) + +let _ = + match a with + | a -> ( + match a with + | a -> ( + let+ a = b in + match a with a -> a ) + | b -> c ) + +let _ = + let+ a b = c in + d + +let _ = + f + (let+ a b = c in + d ) + +let () = + let* x = 1 (* blah *) and* y = 2 in + () + +let x = () +(* after x *) + +let y = () + +let x = () +(* after x *) + +and y = () + +(** doc x *) +let x = () [@@foo] +(* after x *) + +(** doc y *) +let y = () [@@foo] +(* after y *) + +(** doc x *) +let x = () +(* after x *) + +(** doc y *) +and y = () [@@foo] +(* after y *) + +let _ = + let* () = + (* xxx *) + xxx + and* () = + (* yyy *) + yyy + in + zzz + +[@@@ocamlformat "let-binding-spacing=double-semicolon"] + +module A = struct + let f : int S.t ab -> float S.t ab -> string = + fun (l : int S.t ab) (r : float S.t ab) -> + match (l, r) with A, B -> "f A B" + ;; +end + +let (A (a, _, b) | B (b, a)) = A (1, 2, 3) + +let copy from ~into : unit = + let ({ pulse_captured_vars_length_contradictions + ; pulse_summaries_count + ; topl_reachable_calls + ; timeouts + ; timings } [@warning "+9"] ) = + () + in + () +;; + +let {x; y} : foo = bar + +let ({x; y} : foo) = bar + +let a, b = (raise Exit : int * int) + +let a, b = (raise Exit : int * int) + +let _ = + fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with _ -> () +;; + +fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with _ -> () diff --git a/test/passing/tests/let_binding-in_indent.ml.ref b/test/passing/tests/let_binding-in_indent.ml.ref index 496d0aef81..5563c1a853 100644 --- a/test/passing/tests/let_binding-in_indent.ml.ref +++ b/test/passing/tests/let_binding-in_indent.ml.ref @@ -261,3 +261,11 @@ let ({x; y} : foo) = bar let a, b = (raise Exit : int * int) let a, b = (raise Exit : int * int) + +let _ = + fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with _ -> () +;; + +fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with _ -> () diff --git a/test/passing/tests/let_binding-indent.ml.ref b/test/passing/tests/let_binding-indent.ml.ref index 5e07912e98..b52b28d7c1 100644 --- a/test/passing/tests/let_binding-indent.ml.ref +++ b/test/passing/tests/let_binding-indent.ml.ref @@ -261,3 +261,12 @@ let ({x; y} : foo) = bar let a, b = (raise Exit : int * int) let a, b = (raise Exit : int * int) + +let _ = + fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : + _ -> + match () with _ -> () +;; + +fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with _ -> () diff --git a/test/passing/tests/let_binding.ml b/test/passing/tests/let_binding.ml index d01ee58177..a1537a7729 100644 --- a/test/passing/tests/let_binding.ml +++ b/test/passing/tests/let_binding.ml @@ -249,3 +249,14 @@ let ({ x; y } : foo) = bar let a, b = (raise Exit : int * int) let (a, b) = (raise Exit : int * int) +;; + +let _ = + fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with + | _ -> () +;; + +fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with + | _ -> () diff --git a/test/passing/tests/let_binding.ml.ref b/test/passing/tests/let_binding.ml.ref index 1920f73453..0778a3f7ff 100644 --- a/test/passing/tests/let_binding.ml.ref +++ b/test/passing/tests/let_binding.ml.ref @@ -261,3 +261,11 @@ let ({x; y} : foo) = bar let a, b = (raise Exit : int * int) let a, b = (raise Exit : int * int) + +let _ = + fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with _ -> () +;; + +fun xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : _ -> + match () with _ -> ()