Skip to content

Commit

Permalink
Extract tests from the 5.2 compat PR (#2578)
Browse files Browse the repository at this point in the history
This will make the diffs more readable.
  • Loading branch information
Julow authored Sep 20, 2024
1 parent 923486c commit 8cf0db5
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/passing/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Empty file.
32 changes: 32 additions & 0 deletions test/passing/tests/fun_decl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 () )
6 changes: 6 additions & 0 deletions test/passing/tests/function_indent-never.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/passing/tests/function_indent.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/passing/tests/function_indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/passing/tests/issue289.ml.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--max-iter=3
1 change: 1 addition & 0 deletions test/passing/tests/let_binding-deindent-fun.ml.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: tests/let_binding.ml:265 exceeds the margin
1 change: 1 addition & 0 deletions test/passing/tests/let_binding-deindent-fun.ml.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--no-let-binding-deindent-fun
271 changes: 271 additions & 0 deletions test/passing/tests/let_binding-deindent-fun.ml.ref
Original file line number Diff line number Diff line change
@@ -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 _ -> ()
Loading

0 comments on commit 8cf0db5

Please sign in to comment.