diff --git a/dune-project b/dune-project index ed5b69b4..d879c429 100644 --- a/dune-project +++ b/dune-project @@ -1,3 +1,3 @@ -(lang dune 1.0) +(lang dune 3.20) (name ocp-indent) (version 1.8.1) diff --git a/ocp-indent.opam b/ocp-indent.opam index 4786c421..63b7aa73 100644 --- a/ocp-indent.opam +++ b/ocp-indent.opam @@ -31,7 +31,7 @@ run-test: [ ] depends: [ "ocaml" {>= "4.08"} - "dune" {>= "1.0"} + "dune" {>= "3.20"} "cmdliner" {>= "1.3.0"} "ocamlfind" ] diff --git a/tests/failing-output/escaped-nl.ml b/tests/failing-output/escaped-nl.ml deleted file mode 100644 index 1c9821d5..00000000 --- a/tests/failing-output/escaped-nl.ml +++ /dev/null @@ -1,44 +0,0 @@ -let s1 = "No field 'install', but a field 'remove': install instructions \ - probably part of 'build'. Use the 'install' field or a .install \ - file" - -let x = - cond 40 `Warning - "Package uses flags that aren't recognised by earlier versions in \ - OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \ - instead for compatibility" - ~detail:alpha_flags - (alpha_flags <> []) - -let s2 = "bla bla - bli bli \ - blo" - -let s3 = "\ -" - -let s4 = " \ - " - -let s5 = " \ - \ - " - -let s6 = " -" - -let s7 = " -" - -let c1 = ' - ' - -let x1 = f x ' - ' y - z - -let zz = "\ - -s \ - \ - " diff --git a/tests/failing-output/indent-empty-numeric.ml b/tests/failing-output/indent-empty-numeric.ml deleted file mode 100644 index 4a1ad12a..00000000 --- a/tests/failing-output/indent-empty-numeric.ml +++ /dev/null @@ -1,10 +0,0 @@ -0 -0 -2 -2 -0 -0 -0 -0 -2 -15 diff --git a/tests/failing-output/js-args.ml b/tests/failing-output/js-args.ml deleted file mode 100644 index 729f7196..00000000 --- a/tests/failing-output/js-args.ml +++ /dev/null @@ -1,162 +0,0 @@ -let () = - foo.bar <- - f x - y z - -let should_check_can_sell_and_marking regulatory_regime = - match z with - | `foo - -> some_function - argument -(* The above typically occurs in a multi-pattern match clause, so the clause - expression is on a line by itself. This is the more typical way a long - single-pattern match clause would be written: *) -let should_check_can_sell_and_marking regulatory_regime = - match z with - | `foo -> - some_function - argument - -let f = fun x -> - ghi - x - -(* common *) -let x = - try x with - | a -> b - | c -> d -let x = try x with - | a -> b - | c -> d -let x = - try x - with - | a -> b - | c -> d - -let z = - some_function - argument - - - -let () = - f a b ~c:c - d - -let () = - f a b ~c:1. - d - -let () = - My_module.f a b ~c:c - d - -(* This last case is where Tuareg is inconsistent with the others. *) -let () = - My_module.f a b ~c:1. - d - - - -let () = - messages := - Message_store.create (Session_id.of_string "") - (* Tuareg indents these lines too far to the left. *) - "herd-retransmitter" - Message_store.Message_size.Byte - - - -let () = - raise (Bug ("foo" - (* In this and similar cases, we want the subsequent lines to - align with the first expression. *) - ^ "bar")); - raise (Bug ("foo" ^ "quux" - ^ "bar")); - raise (Bug (foo + quux - ^ "bar")); - raise (Bug ((foo + quux) - ^ "bar")) - -(* Except in specific cases, we want the argument indented relative to the - function being called. (Exceptions include "fun" arguments where the line - ends with "->" and subsequent lines beginning with operators, like above.) *) -let () = - Some (Message_store.create s - "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) - - - -(* We like the indentation of most arguments, but want to get back towards the - left margin in a few special cases: *) -let _ = - foo (bar (fun x -> (* special: "fun _ ->" at EOL *) - baz)) (* assume no more arguments to "bar" *) -let _ = - foo - ~a_long_field_name:(check (fun bar -> - baz)) -let _ = - foo ~a_long_field_name:(check (fun bar -> - baz)) -let _ = - foo (bar (quux (fnord (fun x -> (* any depth *) - baz)))) - -(* We also wanted to tweak the operator indentation, making operators like <= - not special cases in contexts like this: *) -let _ = - assert (foo (bar + baz - <= quux)) (* lined up under left argument to op, - sim. to ^ above *) -(* Sim. indentation of if conditions: *) -let _ = - if (a - <= b) - then () -let _ = - (* Comparisons are different than conditionals; we don't regard them as - conceptually part of the [if] expression. *) - if a - <= b - then () -let _ = - (* We regard the outermost condition terms as conceptually part of the [if] - expression and indent accordingly. Whether [&&] or [||], conditionals - effectively state lists of conditions for [then]. *) - if Edge_adjustment.is_zero arb.cfg.extra_edge - && 0. = sys.plugs.edge_backoff - && 0. = zero_acvol_edge_backoff - then 0. - else 1. -let _ = - if - Edge_adjustment.is_zero arb.cfg.extra_edge - && 0. = sys.plugs.edge_backoff - && 0. = zero_acvol_edge_backoff - then 0. - else 1. -let _ = - let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> - Pcre.pmatch ~pat ts.RQ.description - ) in - x - -(* combination of operator at BOL and -> at EOL: *) -let _ = - Shell.ssh_lines x - |! List.map ~f:(f (g (fun x -> - let name, path = String.lsplit2_exn ~on:'|' x in - String.strip name, String.strip path))) - -(* open paren ending line like begin *) -let _ = - if a (p ^/ "s") [ e ] = Ok () then `S ( - let label count = - sprintf "%d s" c ^ if c = 1 then ":" else "s" - in - x - ) diff --git a/tests/failing-output/js-begin.ml b/tests/failing-output/js-begin.ml deleted file mode 100644 index e679cc70..00000000 --- a/tests/failing-output/js-begin.ml +++ /dev/null @@ -1,17 +0,0 @@ -let f = function - | zoo -> begin - foo; - bar; - end -;; -let g = function - | zoo -> ( - foo; - bar; - ) -;; -let () = - begin match foo with - | Bar -> snoo - end -;; diff --git a/tests/failing-output/js-fun.ml b/tests/failing-output/js-fun.ml deleted file mode 100644 index df9810c5..00000000 --- a/tests/failing-output/js-fun.ml +++ /dev/null @@ -1,132 +0,0 @@ -(* preferred list style *) -let z = - f - [ y - ; foo ~f:(fun () -> - arg) - ] -;; -let z = - f - [ y - ; foo ~f:(fun () -> - arg - ) - ] -;; - -(* legacy list style *) -let _ = - [ f (fun x -> - x); - f (fun x -> - x); - f (fun x -> - x); - ] -let _ = - [ f (fun x -> - x - ); - f (fun x -> - x - ); - f (fun x -> - x - ); - ] -;; -let _ = - [f (fun x -> - x - ); - f (fun x -> - x - ); - f (fun x -> - x - ); - ] -;; - -let _ = - x - >>= fun x -> - (try x with _ -> ()) - >>= fun x -> - try x with _ -> () - >>= fun x -> - x -;; - -let () = - expr - >>| function - | x -> 3 - | y -> 4 -;; - -let () = - expr - >>| fun z -> match z with - | x -> 3 - | y -> 4 -;; - -let () = - expr - >>| fun z -> function - | x -> 3 - | y -> 4 -;; - -let () = - my_func () >>= function - | A -> 0 - | B -> 0 -;; - -let () = - my_func () >>= (function - | A -> 0 - | B -> 0) -;; - -let () = - expr - >>| function - | x -> 3 - | y -> 4 -;; - -let () = - expr - >>| (function - | x -> 3 - | y -> 4) -;; - - - -let f = - f >>= m (fun f -> - fun x -> - y); - z -;; - -let f = - f - |> m (fun f -> - fun x -> - y - ); - z -;; -let f = - f - |> m (fun f -> - fun x -> - y); - z -;; diff --git a/tests/failing-output/js-functor.ml b/tests/failing-output/js-functor.ml deleted file mode 100644 index 0d6aa696..00000000 --- a/tests/failing-output/js-functor.ml +++ /dev/null @@ -1,93 +0,0 @@ -module M = - Foo (G) - (H) - -module M = - Foo - (G) - (struct - let x - end) - (H) - -(* To me, this looks fine as it is. The rule seems fine as "indent arguments by - 2". To illustrate, with a case where the functor name is longer: *) -module M = - Functor (G) - (H) - (I) - - - -include Foo (struct - let x - end) (struct - let y - end) - -include - Foo (struct - let x - end) (struct - let y - end) - -include - Foo - (struct - let x - end) (struct - let y - end) - -include Persistent.Make - (struct let version = 1 end) - (Stable.Cr_soons_or_pending.V1) - -include Persistent.Make - (struct - let version = 1 - end) - (Stable.Cr_soons_or_pending.V1) - -include - Persistent.Make - (struct let version = 1 end) - (Stable.Cr_soons_or_pending.V1) - -include - Persistent.Make - (struct - let version = 1 - end) - (Stable.Cr_soons_or_pending.V1) - -module M = - Foo (struct - let x - end) (struct - let y - end) - -module M : S = - Make (M) -module M : S with type t := int = - Make (M) - - - -module Simple_command(Arg:sig - end) = struct end - -module Simple_command(Arg : sig - end) = struct end - -module Simple_command (Arg:sig - end) = struct end - -module Simple_command (Arg : sig - end) = struct end - -module Simple_command - (Arg : sig - end) = struct end diff --git a/tests/failing-output/js-pattern.ml b/tests/failing-output/js-pattern.ml deleted file mode 100644 index ea2211b1..00000000 --- a/tests/failing-output/js-pattern.ml +++ /dev/null @@ -1,51 +0,0 @@ -let f = function - | _ -> 0 -;; - -let f x = match x with - | _ -> 0 -;; - -let f = - function - | _ -> 0 -;; - -let f x = - match x with - | _ -> 0 -;; - -let f x = - begin match x with - | _ -> 0 - end -;; - -let check_price t = function - | { Exec. - trade_at_settlement = (None | Some false); - } -> () - -let check_price t = function - | simpler -> () - | other -> () - -(* Sometimes we like to write big alternations like this, in which case the - comment should typically align with the following clause. *) -let 0 = - match x with - | A - (* a *) - -> a -let 0 = - match x with - A - (* a *) - -> a - -let _ = - a - || match a with - | a -> true - | b -> false diff --git a/tests/failing-output/js-record.ml b/tests/failing-output/js-record.ml deleted file mode 100644 index d9af2bd3..00000000 --- a/tests/failing-output/js-record.ml +++ /dev/null @@ -1,103 +0,0 @@ -type x = - { foo : int - ; bar : int - } - -let x = - { x with - foo = 3 - ; bar = 5 - } - -let x = - { (* blah blah blah *) - foo = 3 - ; bar = 5 - } -;; - -let x = - [{ x with - foo = 3 - ; bar = 5 - }] - -let x = - [{ (* blah blah blah *) - foo = 3 - ; bar = 5 - }] -;; - -let x = - { M.x with - M. - foo = 3 - } -;; - -let x = - { x with - M. - foo = 3 - } -;; - -let x = - { M. - foo = 3 - } -;; - -let _ = - { foo with - Bar. - field1 = value1 - ; field2 = value2 - } -;; -let _ = - { foo - with Bar. - field1 = value1 - ; field2 = value2 - } -;; - -(* multicomponent record module pathname *) -let _ = - { A.B. - a = b - ; c = d - } -;; - -type t = - { a - : something_lengthy list list - [@default String.Map.empty] - } - -type t = - { a - : Something_lengthy.t list list - [@default String.Map.empty] - } - -type t = - { a - : something_lengthy list - list - } - -type t = - { a - : Something_lengthy.t list - list - } - -type t = - { a - : Something_lengthy.t - list - } diff --git a/tests/failing-output/js-syntax.ml b/tests/failing-output/js-syntax.ml deleted file mode 100644 index 14590d69..00000000 --- a/tests/failing-output/js-syntax.ml +++ /dev/null @@ -1,15 +0,0 @@ -(* s *) - -let _ = - [%raise_structural_sexp - "feature's tip is already an ancestor of new base" - { feature_tip = (old_tip : Rev.t) - ; new_base = (new_base : Rev.t) - }] - -let _ = - [%raise_structural_sexp "feature's tip is already an ancestor of new base" - { feature_tip = (old_tip : Rev.t) - ; new_base = (new_base : Rev.t) - } - ] diff --git a/tests/failing-output/js-to-do.ml b/tests/failing-output/js-to-do.ml deleted file mode 100644 index 24a989c4..00000000 --- a/tests/failing-output/js-to-do.ml +++ /dev/null @@ -1,69 +0,0 @@ -(* Indentation that Jane Street needs to think about and make precise. - - These are long term ideas, possibly even conflicting with other tests. *) - - - -(* js-args *) - -let _ = - let min_closing_backoff = - -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) - +. Hidden_float.expose (arb.cfg.base_edge @! Sell)) - in - 0 - - - -(* js-type *) - -(* The following tests incorporate several subtle and different indentation - ideas. Please consider this only a proposal for discussion, for now. - - First, notice the display treatment of "(,)" tuples, analogous to "[;]" - lists. While "(,)" is an intensional combination of "()" and ",", unlike - "[;]" lists, we believe "(,)" isn't too big a departure. Value expression - analogies are included in js-type.ml, (meant to be) consistent with the - proposed type indentation. - - Second, and more divergently, the proposed indentation of function types is - based on the idea of aligning the arguments, even the first argument, even - where that means automatically inserting spaces within lines. This applies - to the extra spaces in ":__unit" and "(____Config.Network.t" below. - - We believe this fits into a more general incorporation of alignment into - ocp-indent, to replace our internal alignment tool with a syntax-aware one. - We like to align things for readability, like big records, record types, - lists used to build tables, etc. - - The proposal also includes indenting "->" in the circumstances below relative - to the enclosing "()", by two spaces. In a sense, this happens first, and - then the first argument is aligned accordingly. So, there's no manual - indentation or spacing below. *) - -val instances - : unit - -> ( Config.Network.t - -> (App.t * Config.instance * Config.app) list - -> verbose:bool - -> 'm - , 'm - ) Command.Spec.t - -val instances - : unit - -> ( Config.Network.t - -> (App.t * Config.instance * Config.app) list - -> verbose:bool -> 'm - , 'm - ) Command.Spec.t - -(* presumed analog with stars *) -val instances : - unit - * ( Config.Network.t - * (App.t * Config.instance * Config.app) list - * bool - * 'm - , 'm - ) Command.Spec.t diff --git a/tests/failing-output/js-upon.ml b/tests/failing-output/js-upon.ml deleted file mode 100644 index d7db7199..00000000 --- a/tests/failing-output/js-upon.ml +++ /dev/null @@ -1,13 +0,0 @@ -let f x = - stop - (* We don't do this as a matter of style, but the indentation reveals a common - mistake. *) - >>> fun () -> don't_wait_for (close fd); - bind fd - -let f x = - stop - (* This is what was intended, which is indented correctly, although it's bad - style on my part. *) - >>> (fun () -> don't_wait_for (close fd)); - bind diff --git a/tests/failing-output/list_of_funs.ml b/tests/failing-output/list_of_funs.ml deleted file mode 100644 index 6398b684..00000000 --- a/tests/failing-output/list_of_funs.ml +++ /dev/null @@ -1,33 +0,0 @@ -let f x = - (fun x -> x [ (fun () -> 3) ; - (fun () -> 4) ]) - -let f x = (fun x -> x [ (fun () -> 3) ; - (fun () -> 4) ]) - -let f x = - x [ (fun () -> 3) ; - (fun () -> 4) ] - -let f x = - [ (fun () -> 3) ; - (fun () -> 4) ] - -let f x = - (fun x -> x [ (fun () -> - 3) ; - (fun () -> 4) ]) - -let f x = (fun x -> x [ (fun () -> - 3) ; - (fun () -> 4) ]) - -let f x = - x [ (fun () -> - 3) ; - (fun () -> 4) ] - -let f x = - [ (fun () -> - 3) ; - (fun () -> 4) ] diff --git a/tests/failing.html b/tests/failing.html deleted file mode 100644 index 271dab15..00000000 --- a/tests/failing.html +++ /dev/null @@ -1,820 +0,0 @@ - - - - Failing tests, ocp-indent version 1.8.1+5 (2019-10-23) - - - - -

Failing tests, ocp-indent version 1.8.1+5 (2019-10-23)

-
-

Differences in escaped-nl.ml.ref

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
let s1 = "No field 'install', but a field 'remove': install instructions \
let s1 = "No field 'install', but a field 'remove': install instructions \
1
          probably part of 'build'. Use the 'install' field or a .install \
          probably part of 'build'. Use the 'install' field or a .install \
2
          file"
          file"
3
4
let x =
let x =
5
  cond 40 `Warning
  cond 40 `Warning
6
    "Package uses flags that aren't recognised by earlier versions in \
    "Package uses flags that aren't recognised by earlier versions in \
7
     OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \
     OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \
8
     instead for compatibility"
     instead for compatibility"
9
    ~detail:alpha_flags
    ~detail:alpha_flags
10
    (alpha_flags <> [])
    (alpha_flags <> [])
11
12
let s2 = "bla bla
let s2 = "bla bla
13
 bli bli \
 bli bli \
14
          blo"
          blo"
15
16
let s3 = "\
let s3 = "\
17
"
"
18
19
let s4 = " \
let s4 = " \
20
         "
         "
21
22
let s5 = "  \
let s5 = "  \
23
          \
          \
24
         "
         "
25
26
let s6 = "
let s6 = "
27
"
"
28
29
let s7 = "  
let s7 = "  
30
"
"
31
32
let c1 = '
let c1 = '
33
'
···········'
34
35
let x1 = f x '
let x1 = f x '
36
'·y
···············'·y
37
    z
    z
38
39
let zz = "\
let zz = "\
40
41
s \
s \
42
 \
 \
43
 "
 "
-
-
-

Differences in js-args.ml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
let () =
let () =
1
  foo.bar <-
  foo.bar <-
2
    f x
    f x
3
      y z
      y z
4
5
let should_check_can_sell_and_marking regulatory_regime =
let should_check_can_sell_and_marking regulatory_regime =
6
  match z with
  match z with
7
  | `foo
  | `foo
8
    -> some_function
    -> some_function
9
         argument
         argument
10
(* The above typically occurs in a multi-pattern match clause, so the clause
(* The above typically occurs in a multi-pattern match clause, so the clause
11
   expression is on a line by itself.  This is the more typical way a long
   expression is on a line by itself.  This is the more typical way a long
12
   single-pattern match clause would be written: *)
   single-pattern match clause would be written: *)
13
let should_check_can_sell_and_marking regulatory_regime =
let should_check_can_sell_and_marking regulatory_regime =
14
  match z with
  match z with
15
  | `foo ->
  | `foo ->
16
    some_function
    some_function
17
      argument
      argument
18
19
let f = fun x ->
let f = fun x ->
20
  ghi
  ghi
21
    x
    x
22
23
(* common *)
(* common *)
24
let x =
let x =
25
  try x with
  try x with
26
  | a -> b
  | a -> b
27
  | c -> d
  | c -> d
28
let x = try x with
let x = try x with
29
  | a -> b
  | a -> b
30
  | c -> d
  | c -> d
31
let x =
let x =
32
  try x
  try x
33
  with
  with
34
  | a -> b
  | a -> b
35
  | c -> d
  | c -> d
36
37
let z =
let z =
38
  some_function
  some_function
39
    argument
    argument
40
41
42
43
let () =
let () =
44
  f a b ~c:c
  f a b ~c:c
45
    d
    d
46
47
let () =
let () =
48
  f a b ~c:1.
  f a b ~c:1.
49
    d
    d
50
51
let () =
let () =
52
  My_module.f a b ~c:c
  My_module.f a b ~c:c
53
    d
    d
54
55
(* This last case is where Tuareg is inconsistent with the others. *)
(* This last case is where Tuareg is inconsistent with the others. *)
56
let () =
let () =
57
  My_module.f a b ~c:1.
  My_module.f a b ~c:1.
58
    d
    d
59
60
61
62
let () =
let () =
63
  messages :=
  messages :=
64
    Message_store.create (Session_id.of_string "")
    Message_store.create (Session_id.of_string "")
65
      (* Tuareg indents these lines too far to the left. *)
      (* Tuareg indents these lines too far to the left. *)
66
      "herd-retransmitter"
      "herd-retransmitter"
67
      Message_store.Message_size.Byte
      Message_store.Message_size.Byte
68
69
70
71
let () =
let () =
72
  raise (Bug ("foo"
  raise (Bug ("foo"
73
              (* In this and similar cases, we want the subsequent lines to
              (* In this and similar cases, we want the subsequent lines to
74
                 align with the first expression. *)
                 align with the first expression. *)
75
              ^ "bar"));
              ^ "bar"));
76
  raise (Bug ("foo" ^ "quux"
  raise (Bug ("foo" ^ "quux"
77
              ^ "bar"));
              ^ "bar"));
78
  raise (Bug (foo + quux
  raise (Bug (foo + quux
79
              ^ "bar"));
              ^ "bar"));
80
  raise (Bug ((foo + quux)
  raise (Bug ((foo + quux)
81
              ^ "bar"))
              ^ "bar"))
82
83
(* Except in specific cases, we want the argument indented relative to the
(* Except in specific cases, we want the argument indented relative to the
84
   function being called.  (Exceptions include "fun" arguments where the line
   function being called.  (Exceptions include "fun" arguments where the line
85
   ends with "->" and subsequent lines beginning with operators, like above.) *)
   ends with "->" and subsequent lines beginning with operators, like above.) *)
86
let () =
let () =
87
  Some (Message_store.create s
  Some (Message_store.create s
88
          "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte)
          "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte)
89
90
91
92
(* We like the indentation of most arguments, but want to get back towards the
(* We like the indentation of most arguments, but want to get back towards the
93
   left margin in a few special cases: *)
   left margin in a few special cases: *)
94
let _ =
let _ =
95
  foo (bar (fun x ->                    (* special: "fun _ ->" at EOL *)
  foo (bar (fun x ->                    (* special: "fun _ ->" at EOL *)
96
    baz))                               (* assume no more arguments to "bar" *)
    baz))                               (* assume no more arguments to "bar" *)
97
let _ =
let _ =
98
  foo
  foo
99
    ~a_long_field_name:(check (fun bar ->
    ~a_long_field_name:(check (fun bar ->
100
      baz))
      baz))
101
let _ =
let _ =
102
  foo ~a_long_field_name:(check (fun bar ->
  foo ~a_long_field_name:(check (fun bar ->
103
    baz))
    baz))
104
let _ =
let _ =
105
  foo (bar (quux (fnord (fun x ->       (* any depth *)
  foo (bar (quux (fnord (fun x ->       (* any depth *)
106
    baz))))
    baz))))
107
108
(* We also wanted to tweak the operator indentation, making operators like <=
(* We also wanted to tweak the operator indentation, making operators like <=
109
   not special cases in contexts like this:  *)
   not special cases in contexts like this:  *)
110
let _ =
let _ =
111
  assert (foo (bar + baz
  assert (foo (bar + baz
112
               <= quux))                (* lined up under left argument to op,
               <= quux))                (* lined up under left argument to op,
113
                                           sim. to ^ above *)
                                           sim. to ^ above *)
114
(* Sim. indentation of if conditions: *)
(* Sim. indentation of if conditions: *)
115
let _ =
let _ =
116
  if (a
  if (a
117
      <= b)
      <= b)
118
  then ()
  then ()
119
let _ =
let _ =
120
  (* Comparisons are different than conditionals; we don't regard them as
  (* Comparisons are different than conditionals; we don't regard them as
121
     conceptually part of the [if] expression. *)
     conceptually part of the [if] expression. *)
122
  if a
  if a
123
     <= b
     <= b
124
  then ()
  then ()
125
let _ =
let _ =
126
  (* We regard the outermost condition terms as conceptually part of the [if]
  (* We regard the outermost condition terms as conceptually part of the [if]
127
     expression and indent accordingly.  Whether [&&] or [||], conditionals
     expression and indent accordingly.  Whether [&&] or [||], conditionals
128
     effectively state lists of conditions for [then]. *)
     effectively state lists of conditions for [then]. *)
129
  if Edge_adjustment.is_zero arb.cfg.extra_edge
  if Edge_adjustment.is_zero arb.cfg.extra_edge
130
  && 0. = sys.plugs.edge_backoff
  && 0. = sys.plugs.edge_backoff
131
  && 0. = zero_acvol_edge_backoff
  && 0. = zero_acvol_edge_backoff
132
  then 0.
  then 0.
133
  else 1.
  else 1.
134
let _ =
let _ =
135
  if
  if
136
    Edge_adjustment.is_zero arb.cfg.extra_edge
    Edge_adjustment.is_zero arb.cfg.extra_edge
137
    && 0. = sys.plugs.edge_backoff
    && 0. = sys.plugs.edge_backoff
138
    && 0. = zero_acvol_edge_backoff
    && 0. = zero_acvol_edge_backoff
139
  then 0.
  then 0.
140
  else 1.
  else 1.
141
let _ =
let _ =
142
  let entries = List.filter (Lazy.force transferstati) ~f:(fun ts ->
  let entries = List.filter (Lazy.force transferstati) ~f:(fun ts ->
143
    Pcre.pmatch ~pat ts.RQ.description
    Pcre.pmatch ~pat ts.RQ.description
144
  ) in
  ) in
145
  x
  x
146
147
(* combination of operator at BOL and -> at EOL: *)
(* combination of operator at BOL and -> at EOL: *)
148
let _ =
let _ =
149
  Shell.ssh_lines x
  Shell.ssh_lines x
150
  |! List.map ~f:(f (g (fun x ->
  |! List.map ~f:(f (g (fun x ->
151
·······let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in
····let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in
152
·······String.strip·name,·String.strip·path)))
····String.strip·name,·String.strip·path)))
153
154
(* open paren ending line like begin *)
(* open paren ending line like begin *)
155
let _ =
let _ =
156
  if a (p ^/ "s") [ e ] = Ok () then `S (
  if a (p ^/ "s") [ e ] = Ok () then `S (
157
    let label count =
    let label count =
158
      sprintf "%d s" c ^ if c = 1 then ":" else "s"
      sprintf "%d s" c ^ if c = 1 then ":" else "s"
159
    in
    in
160
    x
    x
161
  )
  )
-
-
-

Differences in js-begin.ml

- - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
let f = function
let f = function
1
  | zoo -> begin
  | zoo -> begin
2
      foo;
      foo;
3
      bar;
      bar;
4
    end
    end
5
;;
;;
6
let g = function
let g = function
7
  | zoo -> (
  | zoo -> (
8
      foo;
      foo;
9
      bar;
      bar;
10
    )
    )
11
;;
;;
12
let () =
let () =
13
  begin match foo with
  begin match foo with
14
········|·Bar·->·snoo
··|·Bar·->·snoo
15
  end
  end
16
;;
;;
-
-
-

Differences in js-fun.ml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
(* preferred list style *)
(* preferred list style *)
1
let z =
let z =
2
  f
  f
3
    [ y
    [ y
4
    ; foo ~f:(fun () ->
    ; foo ~f:(fun () ->
5
        arg)
        arg)
6
    ]
    ]
7
;;
;;
8
let z =
let z =
9
  f
  f
10
    [ y
    [ y
11
    ; foo ~f:(fun () ->
    ; foo ~f:(fun () ->
12
        arg
        arg
13
      )
      )
14
    ]
    ]
15
;;
;;
16
17
(* legacy list style *)
(* legacy list style *)
18
let _ =
let _ =
19
  [ f (fun x ->
  [ f (fun x ->
20
      x);
      x);
21
    f (fun x ->
    f (fun x ->
22
      x);
      x);
23
    f (fun x ->
    f (fun x ->
24
      x);
      x);
25
  ]
  ]
26
let _ =
let _ =
27
  [ f (fun x ->
  [ f (fun x ->
28
      x
      x
29
    );
    );
30
    f (fun x ->
    f (fun x ->
31
      x
      x
32
    );
    );
33
    f (fun x ->
    f (fun x ->
34
      x
      x
35
    );
    );
36
  ]
  ]
37
;;
;;
38
let _ =
let _ =
39
  [f (fun x ->
  [f (fun x ->
40
     x
     x
41
   );
   );
42
   f (fun x ->
   f (fun x ->
43
     x
     x
44
   );
   );
45
   f (fun x ->
   f (fun x ->
46
     x
     x
47
   );
   );
48
  ]
  ]
49
;;
;;
50
51
let _ =
let _ =
52
  x
  x
53
  >>= fun x ->
  >>= fun x ->
54
  (try x with _ -> ())
  (try x with _ -> ())
55
  >>= fun x ->
  >>= fun x ->
56
  try x with _ -> ()
  try x with _ -> ()
57
    >>= fun x ->
    >>= fun x ->
58
    x
    x
59
;;
;;
60
61
let () =
let () =
62
  expr
  expr
63
  >>| function
  >>| function
64
  | x -> 3
  | x -> 3
65
  | y -> 4
  | y -> 4
66
;;
;;
67
68
let () =
let () =
69
  expr
  expr
70
  >>| fun z -> match z with
  >>| fun z -> match z with
71
···············|·x·->·3
··|·x·->·3
72
···············|·y·->·4
··|·y·->·4
73
;;
;;
74
75
let () =
let () =
76
  expr
  expr
77
  >>| fun z -> function
  >>| fun z -> function
78
  | x -> 3
  | x -> 3
79
  | y -> 4
  | y -> 4
80
;;
;;
81
82
let () =
let () =
83
  my_func () >>= function
  my_func () >>= function
84
  | A -> 0
  | A -> 0
85
  | B -> 0
  | B -> 0
86
;;
;;
87
88
let () =
let () =
89
  my_func () >>= (function
  my_func () >>= (function
90
    | A -> 0
    | A -> 0
91
    | B -> 0)
    | B -> 0)
92
;;
;;
93
94
let () =
let () =
95
  expr
  expr
96
  >>| function
  >>| function
97
  | x -> 3
  | x -> 3
98
  | y -> 4
  | y -> 4
99
;;
;;
100
101
let () =
let () =
102
  expr
  expr
103
  >>| (function
  >>| (function
104
    | x -> 3
    | x -> 3
105
    | y -> 4)
    | y -> 4)
106
;;
;;
107
108
109
110
let f =
let f =
111
  f >>= m (fun f ->
  f >>= m (fun f ->
112
    fun x ->
    fun x ->
113
      y);
      y);
114
  z
  z
115
;;
;;
116
117
let f =
let f =
118
  f
  f
119
  |> m (fun f ->
  |> m (fun f ->
120
    fun x ->
    fun x ->
121
      y
      y
122
  );
  );
123
  z
  z
124
;;
;;
125
let f =
let f =
126
  f
  f
127
  |> m (fun f ->
  |> m (fun f ->
128
    fun x ->
    fun x ->
129
      y);
      y);
130
  z
  z
131
;;
;;
-
-
-

Differences in js-functor.ml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
module M =
module M =
1
  Foo (G)
  Foo (G)
2
    (H)
    (H)
3
4
module M =
module M =
5
  Foo
  Foo
6
    (G)
    (G)
7
    (struct
    (struct
8
      let x
      let x
9
    end)
    end)
10
    (H)
    (H)
11
12
(* To me, this looks fine as it is.  The rule seems fine as "indent arguments by
(* To me, this looks fine as it is.  The rule seems fine as "indent arguments by
13
   2".  To illustrate, with a case where the functor name is longer: *)
   2".  To illustrate, with a case where the functor name is longer: *)
14
module M =
module M =
15
  Functor (G)
  Functor (G)
16
    (H)
    (H)
17
    (I)
    (I)
18
19
20
21
include Foo (struct
include Foo (struct
22
    let x
    let x
23
  end) (struct
  end) (struct
24
    let y
    let y
25
  end)
  end)
26
27
include
include
28
  Foo (struct
  Foo (struct
29
······let·x
····let·x
30
····end)·(struct
··end)·(struct
31
······let·y
····let·y
32
····end)
··end)
33
34
include
include
35
  Foo
  Foo
36
    (struct
    (struct
37
      let x
      let x
38
    end) (struct
    end) (struct
39
······let·y
····let·y
40
····end)
··end)
41
42
include Persistent.Make
include Persistent.Make
43
··(struct·let·version·=·1·end)
····(struct·let·version·=·1·end)
44
··(Stable.Cr_soons_or_pending.V1)
····(Stable.Cr_soons_or_pending.V1)
45
46
include Persistent.Make
include Persistent.Make
47
··(struct
····(struct
48
····let·version·=·1
······let·version·=·1
49
··end)
····end)
50
··(Stable.Cr_soons_or_pending.V1)
····(Stable.Cr_soons_or_pending.V1)
51
52
include
include
53
  Persistent.Make
  Persistent.Make
54
    (struct let version = 1 end)
    (struct let version = 1 end)
55
    (Stable.Cr_soons_or_pending.V1)
    (Stable.Cr_soons_or_pending.V1)
56
57
include
include
58
  Persistent.Make
  Persistent.Make
59
    (struct
    (struct
60
      let version = 1
      let version = 1
61
    end)
    end)
62
    (Stable.Cr_soons_or_pending.V1)
    (Stable.Cr_soons_or_pending.V1)
63
64
module M =
module M =
65
  Foo (struct
  Foo (struct
66
······let·x
····let·x
67
····end)·(struct
··end)·(struct
68
······let·y
····let·y
69
····end)
··end)
70
71
module M : S =
module M : S =
72
  Make (M)
  Make (M)
73
module M : S with type t := int =
module M : S with type t := int =
74
  Make (M)
  Make (M)
75
76
77
78
module Simple_command(Arg:sig
module Simple_command(Arg:sig
79
  end) = struct end
  end) = struct end
80
81
module Simple_command(Arg : sig
module Simple_command(Arg : sig
82
  end) = struct end
  end) = struct end
83
84
module Simple_command (Arg:sig
module Simple_command (Arg:sig
85
  end) = struct end
  end) = struct end
86
87
module Simple_command (Arg : sig
module Simple_command (Arg : sig
88
  end) = struct end
  end) = struct end
89
90
module Simple_command
module Simple_command
91
··(Arg·:·sig
····(Arg·:·sig
92
···end)·=·struct·end
·····end)·=·struct·end
-
-
-

Differences in js-pattern.ml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
let f = function
let f = function
1
  | _ -> 0
  | _ -> 0
2
;;
;;
3
4
let f x = match x with
let f x = match x with
5
··········|·_·->·0
··|·_·->·0
6
;;
;;
7
8
let f =
let f =
9
  function
  function
10
  | _ -> 0
  | _ -> 0
11
;;
;;
12
13
let f x =
let f x =
14
  match x with
  match x with
15
  | _ -> 0
  | _ -> 0
16
;;
;;
17
18
let f x =
let f x =
19
  begin match x with
  begin match x with
20
········|·_·->·0
··|·_·->·0
21
  end
  end
22
;;
;;
23
24
let check_price t = function
let check_price t = function
25
  | { Exec.
  | { Exec.
26
      trade_at_settlement = (None | Some false);
      trade_at_settlement = (None | Some false);
27
    } -> ()
    } -> ()
28
29
let check_price t = function
let check_price t = function
30
  | simpler -> ()
  | simpler -> ()
31
  | other -> ()
  | other -> ()
32
33
(* Sometimes we like to write big alternations like this, in which case the
(* Sometimes we like to write big alternations like this, in which case the
34
   comment should typically align with the following clause. *)
   comment should typically align with the following clause. *)
35
let 0 =
let 0 =
36
  match x with
  match x with
37
  | A
  | A
38
    (* a *)
    (* a *)
39
    -> a
    -> a
40
let 0 =
let 0 =
41
  match x with
  match x with
42
    A
    A
43
    (* a *)
    (* a *)
44
    -> a
    -> a
45
46
let _ =
let _ =
47
  a
  a
48
  || match a with
  || match a with
49
·····|·a·->·true
··|·a·->·true
50
·····|·b·->·false
··|·b·->·false
-
-
-

Differences in js-record.ml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
type x =
type x =
1
  { foo : int
  { foo : int
2
  ; bar : int
  ; bar : int
3
  }
  }
4
5
let x =
let x =
6
  { x with
  { x with
7
    foo = 3
    foo = 3
8
  ; bar = 5
  ; bar = 5
9
  }
  }
10
11
let x =
let x =
12
  { (* blah blah blah *)
  { (* blah blah blah *)
13
    foo = 3
    foo = 3
14
  ; bar = 5
  ; bar = 5
15
  }
  }
16
;;
;;
17
18
let x =
let x =
19
  [{ x with
  [{ x with
20
     foo = 3
     foo = 3
21
   ; bar = 5
   ; bar = 5
22
   }]
   }]
23
24
let x =
let x =
25
  [{ (* blah blah blah *)
  [{ (* blah blah blah *)
26
·····foo·=·3
····foo·=·3
27
···;·bar·=·5
··;·bar·=·5
28
···}]
··}]
29
;;
;;
30
31
let x =
let x =
32
  { M.x with
  { M.x with
33
    M.
    M.
34
    foo = 3
    foo = 3
35
  }
  }
36
;;
;;
37
38
let x =
let x =
39
  { x with
  { x with
40
    M.
    M.
41
    foo = 3
    foo = 3
42
  }
  }
43
;;
;;
44
45
let x =
let x =
46
  { M.
  { M.
47
    foo = 3
    foo = 3
48
  }
  }
49
;;
;;
50
51
let _ =
let _ =
52
  { foo with
  { foo with
53
    Bar.
    Bar.
54
    field1 = value1
    field1 = value1
55
  ; field2 = value2
  ; field2 = value2
56
  }
  }
57
;;
;;
58
let _ =
let _ =
59
  { foo
  { foo
60
    with Bar.
    with Bar.
61
····field1·=·value1
······field1·=·value1
62
··;·field2·=·value2
····;·field2·=·value2
63
  }
  }
64
;;
;;
65
66
(* multicomponent record module pathname *)
(* multicomponent record module pathname *)
67
let _ =
let _ =
68
  { A.B.
  { A.B.
69
    a = b
    a = b
70
  ; c = d
  ; c = d
71
  }
  }
72
;;
;;
73
74
type t =
type t =
75
  { a
  { a
76
    : something_lengthy list list
    : something_lengthy list list
77
      [@default String.Map.empty]
      [@default String.Map.empty]
78
  }
  }
79
80
type t =
type t =
81
  { a
  { a
82
    : Something_lengthy.t list list
    : Something_lengthy.t list list
83
      [@default String.Map.empty]
      [@default String.Map.empty]
84
  }
  }
85
86
type t =
type t =
87
  { a
  { a
88
    : something_lengthy list
    : something_lengthy list
89
        list
        list
90
  }
  }
91
92
type t =
type t =
93
  { a
  { a
94
    : Something_lengthy.t list
    : Something_lengthy.t list
95
        list
        list
96
  }
  }
97
98
type t =
type t =
99
  { a
  { a
100
    : Something_lengthy.t
    : Something_lengthy.t
101
        list
        list
102
  }
  }
-
-
-

Differences in js-syntax.ml

- - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
(* s *)
(* s *)
1
2
let _ =
let _ =
3
  [%raise_structural_sexp
  [%raise_structural_sexp
4
    "feature's tip is already an ancestor of new base"
    "feature's tip is already an ancestor of new base"
5
····{·feature_tip·=·(old_tip·:·Rev.t)
······{·feature_tip·=·(old_tip·:·Rev.t)
6
····;·new_base····=·(new_base·:·Rev.t)
······;·new_base····=·(new_base·:·Rev.t)
7
····}]
······}]
8
9
let _ =
let _ =
10
  [%raise_structural_sexp "feature's tip is already an ancestor of new base"
  [%raise_structural_sexp "feature's tip is already an ancestor of new base"
11
····{·feature_tip·=·(old_tip·:·Rev.t)
····························{·feature_tip·=·(old_tip·:·Rev.t)
12
····;·new_base····=·(new_base·:·Rev.t)
····························;·new_base····=·(new_base·:·Rev.t)
13
····}
····························}
14
  ]
  ]
-
-
-

Differences in js-to-do.ml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
(* Indentation that Jane Street needs to think about and make precise.
(* Indentation that Jane Street needs to think about and make precise.
1
2
   These are long term ideas, possibly even conflicting with other tests. *)
   These are long term ideas, possibly even conflicting with other tests. *)
3
4
5
6
(* js-args *)
(* js-args *)
7
8
let _ =
let _ =
9
  let min_closing_backoff =
  let min_closing_backoff =
10
    -. (   Hidden_float.expose (arb.cfg.base_edge @! Buy)
    -. (   Hidden_float.expose (arb.cfg.base_edge @! Buy)
11
········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell))
···········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell))
12
  in
  in
13
  0
  0
14
15
16
17
(* js-type *)
(* js-type *)
18
19
(* The following tests incorporate several subtle and different indentation
(* The following tests incorporate several subtle and different indentation
20
   ideas.  Please consider this only a proposal for discussion, for now.
   ideas.  Please consider this only a proposal for discussion, for now.
21
22
   First, notice the display treatment of "(,)" tuples, analogous to "[;]"
   First, notice the display treatment of "(,)" tuples, analogous to "[;]"
23
   lists.  While "(,)" is an intensional combination of "()" and ",", unlike
   lists.  While "(,)" is an intensional combination of "()" and ",", unlike
24
   "[;]" lists, we believe "(,)" isn't too big a departure.  Value expression
   "[;]" lists, we believe "(,)" isn't too big a departure.  Value expression
25
   analogies are included in js-type.ml, (meant to be) consistent with the
   analogies are included in js-type.ml, (meant to be) consistent with the
26
   proposed type indentation.
   proposed type indentation.
27
28
   Second, and more divergently, the proposed indentation of function types is
   Second, and more divergently, the proposed indentation of function types is
29
   based on the idea of aligning the arguments, even the first argument, even
   based on the idea of aligning the arguments, even the first argument, even
30
   where that means automatically inserting spaces within lines.  This applies
   where that means automatically inserting spaces within lines.  This applies
31
   to the extra spaces in ":__unit" and "(____Config.Network.t" below.
   to the extra spaces in ":__unit" and "(____Config.Network.t" below.
32
33
   We believe this fits into a more general incorporation of alignment into
   We believe this fits into a more general incorporation of alignment into
34
   ocp-indent, to replace our internal alignment tool with a syntax-aware one.
   ocp-indent, to replace our internal alignment tool with a syntax-aware one.
35
   We like to align things for readability, like big records, record types,
   We like to align things for readability, like big records, record types,
36
   lists used to build tables, etc.
   lists used to build tables, etc.
37
38
   The proposal also includes indenting "->" in the circumstances below relative
   The proposal also includes indenting "->" in the circumstances below relative
39
   to the enclosing "()", by two spaces.  In a sense, this happens first, and
   to the enclosing "()", by two spaces.  In a sense, this happens first, and
40
   then the first argument is aligned accordingly.  So, there's no manual
   then the first argument is aligned accordingly.  So, there's no manual
41
   indentation or spacing below. *)
   indentation or spacing below. *)
42
43
val instances
val instances
44
  :  unit
  :  unit
45
  -> (    Config.Network.t
  -> (    Config.Network.t
46
·······->·(App.t·*·Config.instance·*·Config.app)·list
··········->·(App.t·*·Config.instance·*·Config.app)·list
47
·······->·verbose:bool
··········->·verbose:bool
48
·······->·'m
··········->·'m
49
     , 'm
     , 'm
50
     ) Command.Spec.t
     ) Command.Spec.t
51
52
val instances
val instances
53
  :  unit
  :  unit
54
  -> (    Config.Network.t
  -> (    Config.Network.t
55
·······->·(App.t·*·Config.instance·*·Config.app)·list
··········->·(App.t·*·Config.instance·*·Config.app)·list
56
·······->·verbose:bool·->·'m
··········->·verbose:bool·->·'m
57
     , 'm
     , 'm
58
     ) Command.Spec.t
     ) Command.Spec.t
59
60
(* presumed analog with stars *)
(* presumed analog with stars *)
61
val instances :
val instances :
62
  unit
  unit
63
  * (   Config.Network.t
  * (   Config.Network.t
64
······*·(App.t·*·Config.instance·*·Config.app)·list
········*·(App.t·*·Config.instance·*·Config.app)·list
65
······*·bool
········*·bool
66
······*·'m
········*·'m
67
    , 'm
    , 'm
68
    ) Command.Spec.t
    ) Command.Spec.t
-
-
-

Differences in js-upon.ml

- - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
let f x =
let f x =
1
  stop
  stop
2
  (* We don't do this as a matter of style, but the indentation reveals a common
  (* We don't do this as a matter of style, but the indentation reveals a common
3
     mistake. *)
     mistake. *)
4
  >>> fun () -> don't_wait_for (close fd);
  >>> fun () -> don't_wait_for (close fd);
5
················bind·fd
··bind·fd
6
7
let f x =
let f x =
8
  stop
  stop
9
  (* This is what was intended, which is indented correctly, although it's bad
  (* This is what was intended, which is indented correctly, although it's bad
10
     style on my part. *)
     style on my part. *)
11
  >>> (fun () -> don't_wait_for (close fd));
  >>> (fun () -> don't_wait_for (close fd));
12
  bind
  bind
-
-
-

Differences in list_of_funs.ml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpectedOcp-indent output
0
let f x =
let f x =
1
  (fun x -> x [ (fun () -> 3) ;
  (fun x -> x [ (fun () -> 3) ;
2
                (fun () -> 4) ])
                (fun () -> 4) ])
3
4
let f x = (fun x -> x [ (fun () -> 3) ;
let f x = (fun x -> x [ (fun () -> 3) ;
5
                        (fun () -> 4) ])
                        (fun () -> 4) ])
6
7
let f x =
let f x =
8
  x [ (fun () -> 3) ;
  x [ (fun () -> 3) ;
9
      (fun () -> 4) ]
      (fun () -> 4) ]
10
11
let f x =
let f x =
12
  [ (fun () -> 3) ;
  [ (fun () -> 3) ;
13
    (fun () -> 4) ]
    (fun () -> 4) ]
14
15
let f x =
let f x =
16
  (fun x -> x [ (fun () ->
  (fun x -> x [ (fun () ->
17
···················3)·;
·······3)·;
18
················(fun·()·->·4)·])
·······(fun·()·->·4)·])
19
20
let f x = (fun x -> x [ (fun () ->
let f x = (fun x -> x [ (fun () ->
21
···························3)·;
····3)·;
22
························(fun·()·->·4)·])
····(fun·()·->·4)·])
23
24
let f x =
let f x =
25
  x [ (fun () ->
  x [ (fun () ->
26
·········3)·;
······3)·;
27
      (fun () -> 4) ]
      (fun () -> 4) ]
28
29
let f x =
let f x =
30
  [ (fun () ->
  [ (fun () ->
31
·······3)·;
········3)·;
32
    (fun () -> 4) ]
    (fun () -> 4) ]
-
- - diff --git a/tests/failing/#js-default.ml# b/tests/failing/#js-default.ml# deleted file mode 100644 index 477b7236..00000000 --- a/tests/failing/#js-default.ml# +++ /dev/null @@ -1,10 +0,0 @@ -type t = - { last_trading : Week_date.Spec.t; - first_notice : Week_date.Spec.t option; - first_notice_exceptions : Date.t Year_month.Map.t - with default(Year_month.Map.empty); - offset : Week_date.Offset.t; - (* n > 0 *) - new_contract_expires_in_n_months : int - } - [@@deriving sexp, compare] diff --git a/tests/failing/README.md b/tests/failing/README.md new file mode 100644 index 00000000..28d6cd95 --- /dev/null +++ b/tests/failing/README.md @@ -0,0 +1,12 @@ +## Regression tests + +The tests in this folder document known bugs of ocp-indent and differ +from the rest of the test suite. + +Each test compares the output of ocp-indent to what we expect it should +be using `diff -u`. In most cases the expected output is the input file +itself but in some we provide the expected output separately. + +If the diff goes away, this means we'd have fixed the bug. If the output +of the diff changes though, that should be treated carefully as we don't +expect the rest of the formatting to change in most cases. diff --git a/tests/failing/dune b/tests/failing/dune new file mode 100644 index 00000000..2a531567 --- /dev/null +++ b/tests/failing/dune @@ -0,0 +1,4 @@ +(cram + (enabled_if (= %{os_type} "Unix")) + (deps + (package ocp-indent))) diff --git a/tests/failing/escaped-nl.ml b/tests/failing/escaped-nl.ml deleted file mode 100644 index 00ae4777..00000000 --- a/tests/failing/escaped-nl.ml +++ /dev/null @@ -1,44 +0,0 @@ -let s1 = "No field 'install', but a field 'remove': install instructions \ - probably part of 'build'. Use the 'install' field or a .install \ - file" - -let x = - cond 40 `Warning - "Package uses flags that aren't recognised by earlier versions in \ - OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \ - instead for compatibility" - ~detail:alpha_flags - (alpha_flags <> []) - -let s2 = "bla bla - bli bli \ -blo" - -let s3 = "\ -" - -let s4 = " \ -" - -let s5 = " \ -\ -" - -let s6 = " -" - -let s7 = " -" - -let c1 = ' -' - -let x1 = f x ' -' y -z - -let zz = "\ - -s \ - \ - " diff --git a/tests/failing/escaped-nl.ml.ref b/tests/failing/escaped-nl.ml.ref deleted file mode 100644 index 94662b6c..00000000 --- a/tests/failing/escaped-nl.ml.ref +++ /dev/null @@ -1,44 +0,0 @@ -let s1 = "No field 'install', but a field 'remove': install instructions \ - probably part of 'build'. Use the 'install' field or a .install \ - file" - -let x = - cond 40 `Warning - "Package uses flags that aren't recognised by earlier versions in \ - OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \ - instead for compatibility" - ~detail:alpha_flags - (alpha_flags <> []) - -let s2 = "bla bla - bli bli \ - blo" - -let s3 = "\ -" - -let s4 = " \ - " - -let s5 = " \ - \ - " - -let s6 = " -" - -let s7 = " -" - -let c1 = ' -' - -let x1 = f x ' -' y - z - -let zz = "\ - -s \ - \ - " diff --git a/tests/failing/escaped-nl.t b/tests/failing/escaped-nl.t new file mode 100644 index 00000000..f716b837 --- /dev/null +++ b/tests/failing/escaped-nl.t @@ -0,0 +1,112 @@ + + $ cat > escaped-nl.ml << "EOF" + > let s1 = "No field 'install', but a field 'remove': install instructions \ + > probably part of 'build'. Use the 'install' field or a .install \ + > file" + > + > let x = + > cond 40 `Warning + > "Package uses flags that aren't recognised by earlier versions in \ + > OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \ + > instead for compatibility" + > ~detail:alpha_flags + > (alpha_flags <> []) + > + > let s2 = "bla bla + > bli bli \ + > blo" + > + > let s3 = "\ + > " + > + > let s4 = " \ + > " + > + > let s5 = " \ + > \ + > " + > + > let s6 = " + > " + > + > let s7 = " + > " + > + > let c1 = ' + > ' + > + > let x1 = f x ' + > ' y + > z + > + > let zz = "\ + > + > s \ + > \ + > " + > EOF + +The expected output should be: + + $ cat > escaped-nl.ml.expected << "EOF" + > let s1 = "No field 'install', but a field 'remove': install instructions \ + > probably part of 'build'. Use the 'install' field or a .install \ + > file" + > + > let x = + > cond 40 `Warning + > "Package uses flags that aren't recognised by earlier versions in \ + > OPAM 1.2 branch. At the moment, you should use a tag \"flags:foo\" \ + > instead for compatibility" + > ~detail:alpha_flags + > (alpha_flags <> []) + > + > let s2 = "bla bla + > bli bli \ + > blo" + > + > let s3 = "\ + > " + > + > let s4 = " \ + > " + > + > let s5 = " \ + > \ + > " + > + > let s6 = " + > " + > + > let s7 = " + > " + > + > let c1 = ' + > ' + > + > let x1 = f x ' + > ' y + > z + > + > let zz = "\ + > + > s \ + > \ + > " + > EOF + + $ ocp-indent escaped-nl.ml -o escaped-nl.ml.actual + $ diff -u escaped-nl.ml.expected escaped-nl.ml.actual | sed '1,2d' + @@ -31,10 +31,10 @@ + " + + let c1 = ' + -' + + ' + + let x1 = f x ' + -' y + + ' y + z + + let zz = "\ diff --git a/tests/failing/js-args.ml b/tests/failing/js-args.ml deleted file mode 100644 index 99904b1b..00000000 --- a/tests/failing/js-args.ml +++ /dev/null @@ -1,162 +0,0 @@ -let () = - foo.bar <- - f x - y z - -let should_check_can_sell_and_marking regulatory_regime = - match z with - | `foo - -> some_function - argument -(* The above typically occurs in a multi-pattern match clause, so the clause - expression is on a line by itself. This is the more typical way a long - single-pattern match clause would be written: *) -let should_check_can_sell_and_marking regulatory_regime = - match z with - | `foo -> - some_function - argument - -let f = fun x -> - ghi - x - -(* common *) -let x = - try x with - | a -> b - | c -> d -let x = try x with - | a -> b - | c -> d -let x = - try x - with - | a -> b - | c -> d - -let z = - some_function - argument - - - -let () = - f a b ~c:c - d - -let () = - f a b ~c:1. - d - -let () = - My_module.f a b ~c:c - d - -(* This last case is where Tuareg is inconsistent with the others. *) -let () = - My_module.f a b ~c:1. - d - - - -let () = - messages := - Message_store.create (Session_id.of_string "") - (* Tuareg indents these lines too far to the left. *) - "herd-retransmitter" - Message_store.Message_size.Byte - - - -let () = - raise (Bug ("foo" - (* In this and similar cases, we want the subsequent lines to - align with the first expression. *) - ^ "bar")); - raise (Bug ("foo" ^ "quux" - ^ "bar")); - raise (Bug (foo + quux - ^ "bar")); - raise (Bug ((foo + quux) - ^ "bar")) - -(* Except in specific cases, we want the argument indented relative to the - function being called. (Exceptions include "fun" arguments where the line - ends with "->" and subsequent lines beginning with operators, like above.) *) -let () = - Some (Message_store.create s - "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) - - - -(* We like the indentation of most arguments, but want to get back towards the - left margin in a few special cases: *) -let _ = - foo (bar (fun x -> (* special: "fun _ ->" at EOL *) - baz)) (* assume no more arguments to "bar" *) -let _ = - foo - ~a_long_field_name:(check (fun bar -> - baz)) -let _ = - foo ~a_long_field_name:(check (fun bar -> - baz)) -let _ = - foo (bar (quux (fnord (fun x -> (* any depth *) - baz)))) - -(* We also wanted to tweak the operator indentation, making operators like <= - not special cases in contexts like this: *) -let _ = - assert (foo (bar + baz - <= quux)) (* lined up under left argument to op, - sim. to ^ above *) -(* Sim. indentation of if conditions: *) -let _ = - if (a - <= b) - then () -let _ = - (* Comparisons are different than conditionals; we don't regard them as - conceptually part of the [if] expression. *) - if a - <= b - then () -let _ = - (* We regard the outermost condition terms as conceptually part of the [if] - expression and indent accordingly. Whether [&&] or [||], conditionals - effectively state lists of conditions for [then]. *) - if Edge_adjustment.is_zero arb.cfg.extra_edge - && 0. = sys.plugs.edge_backoff - && 0. = zero_acvol_edge_backoff - then 0. - else 1. -let _ = - if - Edge_adjustment.is_zero arb.cfg.extra_edge - && 0. = sys.plugs.edge_backoff - && 0. = zero_acvol_edge_backoff - then 0. - else 1. -let _ = - let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> - Pcre.pmatch ~pat ts.RQ.description - ) in - x - -(* combination of operator at BOL and -> at EOL: *) -let _ = - Shell.ssh_lines x - |! List.map ~f:(f (g (fun x -> - let name, path = String.lsplit2_exn ~on:'|' x in - String.strip name, String.strip path))) - -(* open paren ending line like begin *) -let _ = - if a (p ^/ "s") [ e ] = Ok () then `S ( - let label count = - sprintf "%d s" c ^ if c = 1 then ":" else "s" - in - x - ) diff --git a/tests/failing/js-args.ml.opts b/tests/failing/js-args.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-args.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-args.t b/tests/failing/js-args.t new file mode 100644 index 00000000..4385741c --- /dev/null +++ b/tests/failing/js-args.t @@ -0,0 +1,179 @@ + + $ cat > js-args.ml << "EOF" + > let () = + > foo.bar <- + > f x + > y z + > + > let should_check_can_sell_and_marking regulatory_regime = + > match z with + > | `foo + > -> some_function + > argument + > (* The above typically occurs in a multi-pattern match clause, so the clause + > expression is on a line by itself. This is the more typical way a long + > single-pattern match clause would be written: *) + > let should_check_can_sell_and_marking regulatory_regime = + > match z with + > | `foo -> + > some_function + > argument + > + > let f = fun x -> + > ghi + > x + > + > (* common *) + > let x = + > try x with + > | a -> b + > | c -> d + > let x = try x with + > | a -> b + > | c -> d + > let x = + > try x + > with + > | a -> b + > | c -> d + > + > let z = + > some_function + > argument + > + > + > + > let () = + > f a b ~c:c + > d + > + > let () = + > f a b ~c:1. + > d + > + > let () = + > My_module.f a b ~c:c + > d + > + > (* This last case is where Tuareg is inconsistent with the others. *) + > let () = + > My_module.f a b ~c:1. + > d + > + > + > + > let () = + > messages := + > Message_store.create (Session_id.of_string "") + > (* Tuareg indents these lines too far to the left. *) + > "herd-retransmitter" + > Message_store.Message_size.Byte + > + > + > + > let () = + > raise (Bug ("foo" + > (* In this and similar cases, we want the subsequent lines to + > align with the first expression. *) + > ^ "bar")); + > raise (Bug ("foo" ^ "quux" + > ^ "bar")); + > raise (Bug (foo + quux + > ^ "bar")); + > raise (Bug ((foo + quux) + > ^ "bar")) + > + > (* Except in specific cases, we want the argument indented relative to the + > function being called. (Exceptions include "fun" arguments where the line + > ends with "->" and subsequent lines beginning with operators, like above.) *) + > let () = + > Some (Message_store.create s + > "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) + > + > + > + > (* We like the indentation of most arguments, but want to get back towards the + > left margin in a few special cases: *) + > let _ = + > foo (bar (fun x -> (* special: "fun _ ->" at EOL *) + > baz)) (* assume no more arguments to "bar" *) + > let _ = + > foo + > ~a_long_field_name:(check (fun bar -> + > baz)) + > let _ = + > foo ~a_long_field_name:(check (fun bar -> + > baz)) + > let _ = + > foo (bar (quux (fnord (fun x -> (* any depth *) + > baz)))) + > + > (* We also wanted to tweak the operator indentation, making operators like <= + > not special cases in contexts like this: *) + > let _ = + > assert (foo (bar + baz + > <= quux)) (* lined up under left argument to op, + > sim. to ^ above *) + > (* Sim. indentation of if conditions: *) + > let _ = + > if (a + > <= b) + > then () + > let _ = + > (* Comparisons are different than conditionals; we don't regard them as + > conceptually part of the [if] expression. *) + > if a + > <= b + > then () + > let _ = + > (* We regard the outermost condition terms as conceptually part of the [if] + > expression and indent accordingly. Whether [&&] or [||], conditionals + > effectively state lists of conditions for [then]. *) + > if Edge_adjustment.is_zero arb.cfg.extra_edge + > && 0. = sys.plugs.edge_backoff + > && 0. = zero_acvol_edge_backoff + > then 0. + > else 1. + > let _ = + > if + > Edge_adjustment.is_zero arb.cfg.extra_edge + > && 0. = sys.plugs.edge_backoff + > && 0. = zero_acvol_edge_backoff + > then 0. + > else 1. + > let _ = + > let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> + > Pcre.pmatch ~pat ts.RQ.description + > ) in + > x + > + > (* combination of operator at BOL and -> at EOL: *) + > let _ = + > Shell.ssh_lines x + > |! List.map ~f:(f (g (fun x -> + > let name, path = String.lsplit2_exn ~on:'|' x in + > String.strip name, String.strip path))) + > + > (* open paren ending line like begin *) + > let _ = + > if a (p ^/ "s") [ e ] = Ok () then `S ( + > let label count = + > sprintf "%d s" c ^ if c = 1 then ":" else "s" + > in + > x + > ) + > EOF + + $ ocp-indent -c JaneStreet js-args.ml -o js-args.ml.actual + $ diff -u js-args.ml js-args.ml.actual | sed '1,2d' + @@ -149,8 +149,8 @@ + let _ = + Shell.ssh_lines x + |! List.map ~f:(f (g (fun x -> + - let name, path = String.lsplit2_exn ~on:'|' x in + - String.strip name, String.strip path))) + + let name, path = String.lsplit2_exn ~on:'|' x in + + String.strip name, String.strip path))) + + (* open paren ending line like begin *) + let _ = diff --git a/tests/failing/js-begin.ml b/tests/failing/js-begin.ml deleted file mode 100644 index abb6b308..00000000 --- a/tests/failing/js-begin.ml +++ /dev/null @@ -1,17 +0,0 @@ -let f = function - | zoo -> begin - foo; - bar; - end -;; -let g = function - | zoo -> ( - foo; - bar; - ) -;; -let () = - begin match foo with - | Bar -> snoo - end -;; diff --git a/tests/failing/js-begin.ml.opts b/tests/failing/js-begin.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-begin.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-begin.t b/tests/failing/js-begin.t new file mode 100644 index 00000000..6bfcbd5f --- /dev/null +++ b/tests/failing/js-begin.t @@ -0,0 +1,31 @@ + + $ cat > js-begin.ml << "EOF" + > let f = function + > | zoo -> begin + > foo; + > bar; + > end + > ;; + > let g = function + > | zoo -> ( + > foo; + > bar; + > ) + > ;; + > let () = + > begin match foo with + > | Bar -> snoo + > end + > ;; + > EOF + + $ ocp-indent -c JaneStreet js-begin.ml -o js-begin.ml.actual + $ diff -u js-begin.ml js-begin.ml.actual | sed '1,2d' + @@ -12,6 +12,6 @@ + ;; + let () = + begin match foo with + - | Bar -> snoo + + | Bar -> snoo + end + ;; diff --git a/tests/failing/js-fun.ml b/tests/failing/js-fun.ml deleted file mode 100644 index 40fc055d..00000000 --- a/tests/failing/js-fun.ml +++ /dev/null @@ -1,132 +0,0 @@ -(* preferred list style *) -let z = - f - [ y - ; foo ~f:(fun () -> - arg) - ] -;; -let z = - f - [ y - ; foo ~f:(fun () -> - arg - ) - ] -;; - -(* legacy list style *) -let _ = - [ f (fun x -> - x); - f (fun x -> - x); - f (fun x -> - x); - ] -let _ = - [ f (fun x -> - x - ); - f (fun x -> - x - ); - f (fun x -> - x - ); - ] -;; -let _ = - [f (fun x -> - x - ); - f (fun x -> - x - ); - f (fun x -> - x - ); - ] -;; - -let _ = - x - >>= fun x -> - (try x with _ -> ()) - >>= fun x -> - try x with _ -> () - >>= fun x -> - x -;; - -let () = - expr - >>| function - | x -> 3 - | y -> 4 -;; - -let () = - expr - >>| fun z -> match z with - | x -> 3 - | y -> 4 -;; - -let () = - expr - >>| fun z -> function - | x -> 3 - | y -> 4 -;; - -let () = - my_func () >>= function - | A -> 0 - | B -> 0 -;; - -let () = - my_func () >>= (function - | A -> 0 - | B -> 0) -;; - -let () = - expr - >>| function - | x -> 3 - | y -> 4 -;; - -let () = - expr - >>| (function - | x -> 3 - | y -> 4) -;; - - - -let f = - f >>= m (fun f -> - fun x -> - y); - z -;; - -let f = - f - |> m (fun f -> - fun x -> - y - ); - z -;; -let f = - f - |> m (fun f -> - fun x -> - y); - z -;; diff --git a/tests/failing/js-fun.ml.opts b/tests/failing/js-fun.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-fun.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-fun.t b/tests/failing/js-fun.t new file mode 100644 index 00000000..8cbf5fe5 --- /dev/null +++ b/tests/failing/js-fun.t @@ -0,0 +1,149 @@ + + $ cat > js-fun.ml << "EOF" + > (* preferred list style *) + > let z = + > f + > [ y + > ; foo ~f:(fun () -> + > arg) + > ] + > ;; + > let z = + > f + > [ y + > ; foo ~f:(fun () -> + > arg + > ) + > ] + > ;; + > + > (* legacy list style *) + > let _ = + > [ f (fun x -> + > x); + > f (fun x -> + > x); + > f (fun x -> + > x); + > ] + > let _ = + > [ f (fun x -> + > x + > ); + > f (fun x -> + > x + > ); + > f (fun x -> + > x + > ); + > ] + > ;; + > let _ = + > [f (fun x -> + > x + > ); + > f (fun x -> + > x + > ); + > f (fun x -> + > x + > ); + > ] + > ;; + > + > let _ = + > x + > >>= fun x -> + > (try x with _ -> ()) + > >>= fun x -> + > try x with _ -> () + > >>= fun x -> + > x + > ;; + > + > let () = + > expr + > >>| function + > | x -> 3 + > | y -> 4 + > ;; + > + > let () = + > expr + > >>| fun z -> match z with + > | x -> 3 + > | y -> 4 + > ;; + > + > let () = + > expr + > >>| fun z -> function + > | x -> 3 + > | y -> 4 + > ;; + > + > let () = + > my_func () >>= function + > | A -> 0 + > | B -> 0 + > ;; + > + > let () = + > my_func () >>= (function + > | A -> 0 + > | B -> 0) + > ;; + > + > let () = + > expr + > >>| function + > | x -> 3 + > | y -> 4 + > ;; + > + > let () = + > expr + > >>| (function + > | x -> 3 + > | y -> 4) + > ;; + > + > + > + > let f = + > f >>= m (fun f -> + > fun x -> + > y); + > z + > ;; + > + > let f = + > f + > |> m (fun f -> + > fun x -> + > y + > ); + > z + > ;; + > let f = + > f + > |> m (fun f -> + > fun x -> + > y); + > z + > ;; + > EOF + + $ ocp-indent -c JaneStreet js-fun.ml -o js-fun.ml.actual + $ diff -u js-fun.ml js-fun.ml.actual | sed '1,2d' + @@ -69,8 +69,8 @@ + let () = + expr + >>| fun z -> match z with + - | x -> 3 + - | y -> 4 + + | x -> 3 + + | y -> 4 + ;; + + let () = diff --git a/tests/failing/js-functor.ml b/tests/failing/js-functor.ml deleted file mode 100644 index 1f12ed8a..00000000 --- a/tests/failing/js-functor.ml +++ /dev/null @@ -1,93 +0,0 @@ -module M = - Foo (G) - (H) - -module M = - Foo - (G) - (struct - let x - end) - (H) - -(* To me, this looks fine as it is. The rule seems fine as "indent arguments by - 2". To illustrate, with a case where the functor name is longer: *) -module M = - Functor (G) - (H) - (I) - - - -include Foo (struct - let x - end) (struct - let y - end) - -include - Foo (struct - let x - end) (struct - let y - end) - -include - Foo - (struct - let x - end) (struct - let y - end) - -include Persistent.Make - (struct let version = 1 end) - (Stable.Cr_soons_or_pending.V1) - -include Persistent.Make - (struct - let version = 1 - end) - (Stable.Cr_soons_or_pending.V1) - -include - Persistent.Make - (struct let version = 1 end) - (Stable.Cr_soons_or_pending.V1) - -include - Persistent.Make - (struct - let version = 1 - end) - (Stable.Cr_soons_or_pending.V1) - -module M = - Foo (struct - let x - end) (struct - let y - end) - -module M : S = - Make (M) -module M : S with type t := int = - Make (M) - - - -module Simple_command(Arg:sig - end) = struct end - -module Simple_command(Arg : sig - end) = struct end - -module Simple_command (Arg:sig - end) = struct end - -module Simple_command (Arg : sig - end) = struct end - -module Simple_command - (Arg : sig - end) = struct end diff --git a/tests/failing/js-functor.ml.opts b/tests/failing/js-functor.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-functor.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-functor.t b/tests/failing/js-functor.t new file mode 100644 index 00000000..348746c5 --- /dev/null +++ b/tests/failing/js-functor.t @@ -0,0 +1,163 @@ + + $ cat > js-functor.ml << "EOF" + > module M = + > Foo (G) + > (H) + > + > module M = + > Foo + > (G) + > (struct + > let x + > end) + > (H) + > + > (* To me, this looks fine as it is. The rule seems fine as "indent arguments by + > 2". To illustrate, with a case where the functor name is longer: *) + > module M = + > Functor (G) + > (H) + > (I) + > + > + > + > include Foo (struct + > let x + > end) (struct + > let y + > end) + > + > include + > Foo (struct + > let x + > end) (struct + > let y + > end) + > + > include + > Foo + > (struct + > let x + > end) (struct + > let y + > end) + > + > include Persistent.Make + > (struct let version = 1 end) + > (Stable.Cr_soons_or_pending.V1) + > + > include Persistent.Make + > (struct + > let version = 1 + > end) + > (Stable.Cr_soons_or_pending.V1) + > + > include + > Persistent.Make + > (struct let version = 1 end) + > (Stable.Cr_soons_or_pending.V1) + > + > include + > Persistent.Make + > (struct + > let version = 1 + > end) + > (Stable.Cr_soons_or_pending.V1) + > + > module M = + > Foo (struct + > let x + > end) (struct + > let y + > end) + > + > module M : S = + > Make (M) + > module M : S with type t := int = + > Make (M) + > + > + > + > module Simple_command(Arg:sig + > end) = struct end + > + > module Simple_command(Arg : sig + > end) = struct end + > + > module Simple_command (Arg:sig + > end) = struct end + > + > module Simple_command (Arg : sig + > end) = struct end + > + > module Simple_command + > (Arg : sig + > end) = struct end + > EOF + + $ ocp-indent -c JaneStreet js-functor.ml -o js-functor.ml.actual + $ diff -u js-functor.ml js-functor.ml.actual | sed '1,2d' + @@ -27,28 +27,28 @@ + + include + Foo (struct + - let x + - end) (struct + - let y + - end) + + let x + + end) (struct + + let y + + end) + + include + Foo + (struct + let x + end) (struct + - let y + - end) + + let y + + end) + + include Persistent.Make + - (struct let version = 1 end) + - (Stable.Cr_soons_or_pending.V1) + + (struct let version = 1 end) + + (Stable.Cr_soons_or_pending.V1) + + include Persistent.Make + - (struct + - let version = 1 + - end) + - (Stable.Cr_soons_or_pending.V1) + + (struct + + let version = 1 + + end) + + (Stable.Cr_soons_or_pending.V1) + + include + Persistent.Make + @@ -64,10 +64,10 @@ + + module M = + Foo (struct + - let x + - end) (struct + - let y + - end) + + let x + + end) (struct + + let y + + end) + + module M : S = + Make (M) + @@ -89,5 +89,5 @@ + end) = struct end + + module Simple_command + - (Arg : sig + - end) = struct end + + (Arg : sig + + end) = struct end diff --git a/tests/failing/js-pattern.ml b/tests/failing/js-pattern.ml deleted file mode 100644 index c75d707d..00000000 --- a/tests/failing/js-pattern.ml +++ /dev/null @@ -1,51 +0,0 @@ -let f = function - | _ -> 0 -;; - -let f x = match x with - | _ -> 0 -;; - -let f = - function - | _ -> 0 -;; - -let f x = - match x with - | _ -> 0 -;; - -let f x = - begin match x with - | _ -> 0 - end -;; - -let check_price t = function - | { Exec. - trade_at_settlement = (None | Some false); - } -> () - -let check_price t = function - | simpler -> () - | other -> () - -(* Sometimes we like to write big alternations like this, in which case the - comment should typically align with the following clause. *) -let 0 = - match x with - | A - (* a *) - -> a -let 0 = - match x with - A - (* a *) - -> a - -let _ = - a - || match a with - | a -> true - | b -> false diff --git a/tests/failing/js-pattern.ml.opts b/tests/failing/js-pattern.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-pattern.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-pattern.t b/tests/failing/js-pattern.t new file mode 100644 index 00000000..3e0de51d --- /dev/null +++ b/tests/failing/js-pattern.t @@ -0,0 +1,83 @@ + + $ cat > js-pattern.ml << "EOF" + > let f = function + > | _ -> 0 + > ;; + > + > let f x = match x with + > | _ -> 0 + > ;; + > + > let f = + > function + > | _ -> 0 + > ;; + > + > let f x = + > match x with + > | _ -> 0 + > ;; + > + > let f x = + > begin match x with + > | _ -> 0 + > end + > ;; + > + > let check_price t = function + > | { Exec. + > trade_at_settlement = (None | Some false); + > } -> () + > + > let check_price t = function + > | simpler -> () + > | other -> () + > + > (* Sometimes we like to write big alternations like this, in which case the + > comment should typically align with the following clause. *) + > let 0 = + > match x with + > | A + > (* a *) + > -> a + > let 0 = + > match x with + > A + > (* a *) + > -> a + > + > let _ = + > a + > || match a with + > | a -> true + > | b -> false + > EOF + + $ ocp-indent -c JaneStreet js-pattern.ml -o js-pattern.ml.actual + $ diff -u js-pattern.ml js-pattern.ml.actual | sed '1,2d' + @@ -3,7 +3,7 @@ + ;; + + let f x = match x with + - | _ -> 0 + + | _ -> 0 + ;; + + let f = + @@ -18,7 +18,7 @@ + + let f x = + begin match x with + - | _ -> 0 + + | _ -> 0 + end + ;; + + @@ -47,5 +47,5 @@ + let _ = + a + || match a with + - | a -> true + - | b -> false + + | a -> true + + | b -> false diff --git a/tests/failing/js-record.ml b/tests/failing/js-record.ml deleted file mode 100644 index 734307b8..00000000 --- a/tests/failing/js-record.ml +++ /dev/null @@ -1,103 +0,0 @@ -type x = - { foo : int - ; bar : int - } - -let x = - { x with - foo = 3 - ; bar = 5 - } - -let x = - { (* blah blah blah *) - foo = 3 - ; bar = 5 - } -;; - -let x = - [{ x with - foo = 3 - ; bar = 5 - }] - -let x = - [{ (* blah blah blah *) - foo = 3 - ; bar = 5 - }] -;; - -let x = - { M.x with - M. - foo = 3 - } -;; - -let x = - { x with - M. - foo = 3 - } -;; - -let x = - { M. - foo = 3 - } -;; - -let _ = - { foo with - Bar. - field1 = value1 - ; field2 = value2 - } -;; -let _ = - { foo - with Bar. - field1 = value1 - ; field2 = value2 - } -;; - -(* multicomponent record module pathname *) -let _ = - { A.B. - a = b - ; c = d - } -;; - -type t = - { a - : something_lengthy list list - [@default String.Map.empty] - } - -type t = - { a - : Something_lengthy.t list list - [@default String.Map.empty] - } - -type t = - { a - : something_lengthy list - list - } - -type t = - { a - : Something_lengthy.t list - list - } - -type t = - { a - : Something_lengthy.t - list - } diff --git a/tests/failing/js-record.ml.opts b/tests/failing/js-record.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-record.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-record.t b/tests/failing/js-record.t new file mode 100644 index 00000000..0a5d5b68 --- /dev/null +++ b/tests/failing/js-record.t @@ -0,0 +1,133 @@ + + $ cat > js-record.ml << "EOF" + > type x = + > { foo : int + > ; bar : int + > } + > + > let x = + > { x with + > foo = 3 + > ; bar = 5 + > } + > + > let x = + > { (* blah blah blah *) + > foo = 3 + > ; bar = 5 + > } + > ;; + > + > let x = + > [{ x with + > foo = 3 + > ; bar = 5 + > }] + > + > let x = + > [{ (* blah blah blah *) + > foo = 3 + > ; bar = 5 + > }] + > ;; + > + > let x = + > { M.x with + > M. + > foo = 3 + > } + > ;; + > + > let x = + > { x with + > M. + > foo = 3 + > } + > ;; + > + > let x = + > { M. + > foo = 3 + > } + > ;; + > + > let _ = + > { foo with + > Bar. + > field1 = value1 + > ; field2 = value2 + > } + > ;; + > let _ = + > { foo + > with Bar. + > field1 = value1 + > ; field2 = value2 + > } + > ;; + > + > (* multicomponent record module pathname *) + > let _ = + > { A.B. + > a = b + > ; c = d + > } + > ;; + > + > type t = + > { a + > : something_lengthy list list + > [@default String.Map.empty] + > } + > + > type t = + > { a + > : Something_lengthy.t list list + > [@default String.Map.empty] + > } + > + > type t = + > { a + > : something_lengthy list + > list + > } + > + > type t = + > { a + > : Something_lengthy.t list + > list + > } + > + > type t = + > { a + > : Something_lengthy.t + > list + > } + > EOF + + $ ocp-indent -c JaneStreet js-record.ml -o js-record.ml.actual + $ diff -u js-record.ml js-record.ml.actual | sed '1,2d' + @@ -24,9 +24,9 @@ + + let x = + [{ (* blah blah blah *) + - foo = 3 + - ; bar = 5 + - }] + + foo = 3 + + ; bar = 5 + + }] + ;; + + let x = + @@ -59,8 +59,8 @@ + let _ = + { foo + with Bar. + - field1 = value1 + - ; field2 = value2 + + field1 = value1 + + ; field2 = value2 + } + ;; + diff --git a/tests/failing/js-syntax.ml b/tests/failing/js-syntax.ml deleted file mode 100644 index 16640fa3..00000000 --- a/tests/failing/js-syntax.ml +++ /dev/null @@ -1,15 +0,0 @@ -(* s *) - -let _ = - [%raise_structural_sexp - "feature's tip is already an ancestor of new base" - { feature_tip = (old_tip : Rev.t) - ; new_base = (new_base : Rev.t) - }] - -let _ = - [%raise_structural_sexp "feature's tip is already an ancestor of new base" - { feature_tip = (old_tip : Rev.t) - ; new_base = (new_base : Rev.t) - } - ] diff --git a/tests/failing/js-syntax.ml.opts b/tests/failing/js-syntax.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-syntax.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-syntax.t b/tests/failing/js-syntax.t new file mode 100644 index 00000000..ca55c3cf --- /dev/null +++ b/tests/failing/js-syntax.t @@ -0,0 +1,41 @@ + + $ cat > js-syntax.ml << "EOF" + > (* s *) + > + > let _ = + > [%raise_structural_sexp + > "feature's tip is already an ancestor of new base" + > { feature_tip = (old_tip : Rev.t) + > ; new_base = (new_base : Rev.t) + > }] + > + > let _ = + > [%raise_structural_sexp "feature's tip is already an ancestor of new base" + > { feature_tip = (old_tip : Rev.t) + > ; new_base = (new_base : Rev.t) + > } + > ] + > EOF + + $ ocp-indent -c JaneStreet js-syntax.ml -o js-syntax.ml.actual + $ diff -u js-syntax.ml js-syntax.ml.actual | sed '1,2d' + @@ -3,13 +3,13 @@ + let _ = + [%raise_structural_sexp + "feature's tip is already an ancestor of new base" + - { feature_tip = (old_tip : Rev.t) + - ; new_base = (new_base : Rev.t) + - }] + + { feature_tip = (old_tip : Rev.t) + + ; new_base = (new_base : Rev.t) + + }] + + let _ = + [%raise_structural_sexp "feature's tip is already an ancestor of new base" + - { feature_tip = (old_tip : Rev.t) + - ; new_base = (new_base : Rev.t) + - } + + { feature_tip = (old_tip : Rev.t) + + ; new_base = (new_base : Rev.t) + + } + ] diff --git a/tests/failing/js-to-do.ml b/tests/failing/js-to-do.ml deleted file mode 100644 index 9b3e7ff5..00000000 --- a/tests/failing/js-to-do.ml +++ /dev/null @@ -1,69 +0,0 @@ -(* Indentation that Jane Street needs to think about and make precise. - - These are long term ideas, possibly even conflicting with other tests. *) - - - -(* js-args *) - -let _ = - let min_closing_backoff = - -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) - +. Hidden_float.expose (arb.cfg.base_edge @! Sell)) - in - 0 - - - -(* js-type *) - -(* The following tests incorporate several subtle and different indentation - ideas. Please consider this only a proposal for discussion, for now. - - First, notice the display treatment of "(,)" tuples, analogous to "[;]" - lists. While "(,)" is an intensional combination of "()" and ",", unlike - "[;]" lists, we believe "(,)" isn't too big a departure. Value expression - analogies are included in js-type.ml, (meant to be) consistent with the - proposed type indentation. - - Second, and more divergently, the proposed indentation of function types is - based on the idea of aligning the arguments, even the first argument, even - where that means automatically inserting spaces within lines. This applies - to the extra spaces in ":__unit" and "(____Config.Network.t" below. - - We believe this fits into a more general incorporation of alignment into - ocp-indent, to replace our internal alignment tool with a syntax-aware one. - We like to align things for readability, like big records, record types, - lists used to build tables, etc. - - The proposal also includes indenting "->" in the circumstances below relative - to the enclosing "()", by two spaces. In a sense, this happens first, and - then the first argument is aligned accordingly. So, there's no manual - indentation or spacing below. *) - -val instances - : unit - -> ( Config.Network.t - -> (App.t * Config.instance * Config.app) list - -> verbose:bool - -> 'm - , 'm - ) Command.Spec.t - -val instances - : unit - -> ( Config.Network.t - -> (App.t * Config.instance * Config.app) list - -> verbose:bool -> 'm - , 'm - ) Command.Spec.t - -(* presumed analog with stars *) -val instances : - unit - * ( Config.Network.t - * (App.t * Config.instance * Config.app) list - * bool - * 'm - , 'm - ) Command.Spec.t diff --git a/tests/failing/js-to-do.ml.opts b/tests/failing/js-to-do.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-to-do.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-to-do.t b/tests/failing/js-to-do.t new file mode 100644 index 00000000..3cf6c017 --- /dev/null +++ b/tests/failing/js-to-do.t @@ -0,0 +1,119 @@ + + $ cat > js-to-do.ml << "EOF" + > (* Indentation that Jane Street needs to think about and make precise. + > + > These are long term ideas, possibly even conflicting with other tests. *) + > + > + > + > (* js-args *) + > + > let _ = + > let min_closing_backoff = + > -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) + > +. Hidden_float.expose (arb.cfg.base_edge @! Sell)) + > in + > 0 + > + > + > + > (* js-type *) + > + > (* The following tests incorporate several subtle and different indentation + > ideas. Please consider this only a proposal for discussion, for now. + > + > First, notice the display treatment of "(,)" tuples, analogous to "[;]" + > lists. While "(,)" is an intensional combination of "()" and ",", unlike + > "[;]" lists, we believe "(,)" isn't too big a departure. Value expression + > analogies are included in js-type.ml, (meant to be) consistent with the + > proposed type indentation. + > + > Second, and more divergently, the proposed indentation of function types is + > based on the idea of aligning the arguments, even the first argument, even + > where that means automatically inserting spaces within lines. This applies + > to the extra spaces in ":__unit" and "(____Config.Network.t" below. + > + > We believe this fits into a more general incorporation of alignment into + > ocp-indent, to replace our internal alignment tool with a syntax-aware one. + > We like to align things for readability, like big records, record types, + > lists used to build tables, etc. + > + > The proposal also includes indenting "->" in the circumstances below relative + > to the enclosing "()", by two spaces. In a sense, this happens first, and + > then the first argument is aligned accordingly. So, there's no manual + > indentation or spacing below. *) + > + > val instances + > : unit + > -> ( Config.Network.t + > -> (App.t * Config.instance * Config.app) list + > -> verbose:bool + > -> 'm + > , 'm + > ) Command.Spec.t + > + > val instances + > : unit + > -> ( Config.Network.t + > -> (App.t * Config.instance * Config.app) list + > -> verbose:bool -> 'm + > , 'm + > ) Command.Spec.t + > + > (* presumed analog with stars *) + > val instances : + > unit + > * ( Config.Network.t + > * (App.t * Config.instance * Config.app) list + > * bool + > * 'm + > , 'm + > ) Command.Spec.t + > EOF + + $ ocp-indent -c JaneStreet js-to-do.ml -o js-to-do.ml.actual + $ diff -u js-to-do.ml js-to-do.ml.actual | sed '1,2d' + @@ -9,7 +9,7 @@ + let _ = + let min_closing_backoff = + -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) + - +. Hidden_float.expose (arb.cfg.base_edge @! Sell)) + + +. Hidden_float.expose (arb.cfg.base_edge @! Sell)) + in + 0 + + @@ -44,17 +44,17 @@ + val instances + : unit + -> ( Config.Network.t + - -> (App.t * Config.instance * Config.app) list + - -> verbose:bool + - -> 'm + + -> (App.t * Config.instance * Config.app) list + + -> verbose:bool + + -> 'm + , 'm + ) Command.Spec.t + + val instances + : unit + -> ( Config.Network.t + - -> (App.t * Config.instance * Config.app) list + - -> verbose:bool -> 'm + + -> (App.t * Config.instance * Config.app) list + + -> verbose:bool -> 'm + , 'm + ) Command.Spec.t + + @@ -62,8 +62,8 @@ + val instances : + unit + * ( Config.Network.t + - * (App.t * Config.instance * Config.app) list + - * bool + - * 'm + + * (App.t * Config.instance * Config.app) list + + * bool + + * 'm + , 'm + ) Command.Spec.t diff --git a/tests/failing/js-upon.ml b/tests/failing/js-upon.ml deleted file mode 100644 index 3a6841d8..00000000 --- a/tests/failing/js-upon.ml +++ /dev/null @@ -1,13 +0,0 @@ -let f x = - stop - (* We don't do this as a matter of style, but the indentation reveals a common - mistake. *) - >>> fun () -> don't_wait_for (close fd); - bind fd - -let f x = - stop - (* This is what was intended, which is indented correctly, although it's bad - style on my part. *) - >>> (fun () -> don't_wait_for (close fd)); - bind diff --git a/tests/failing/js-upon.ml.opts b/tests/failing/js-upon.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/failing/js-upon.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/failing/js-upon.t b/tests/failing/js-upon.t new file mode 100644 index 00000000..8ef690a1 --- /dev/null +++ b/tests/failing/js-upon.t @@ -0,0 +1,28 @@ + + $ cat > js-upon.ml << "EOF" + > let f x = + > stop + > (* We don't do this as a matter of style, but the indentation reveals a common + > mistake. *) + > >>> fun () -> don't_wait_for (close fd); + > bind fd + > + > let f x = + > stop + > (* This is what was intended, which is indented correctly, although it's bad + > style on my part. *) + > >>> (fun () -> don't_wait_for (close fd)); + > bind + > EOF + + $ ocp-indent -c JaneStreet js-upon.ml -o js-upon.ml.actual + $ diff -u js-upon.ml js-upon.ml.actual | sed '1,2d' + @@ -3,7 +3,7 @@ + (* We don't do this as a matter of style, but the indentation reveals a common + mistake. *) + >>> fun () -> don't_wait_for (close fd); + - bind fd + + bind fd + + let f x = + stop diff --git a/tests/failing/list_of_funs.ml b/tests/failing/list_of_funs.ml deleted file mode 100644 index e8f5765d..00000000 --- a/tests/failing/list_of_funs.ml +++ /dev/null @@ -1,33 +0,0 @@ -let f x = - (fun x -> x [ (fun () -> 3) ; - (fun () -> 4) ]) - -let f x = (fun x -> x [ (fun () -> 3) ; - (fun () -> 4) ]) - -let f x = - x [ (fun () -> 3) ; - (fun () -> 4) ] - -let f x = - [ (fun () -> 3) ; - (fun () -> 4) ] - -let f x = - (fun x -> x [ (fun () -> - 3) ; - (fun () -> 4) ]) - -let f x = (fun x -> x [ (fun () -> - 3) ; - (fun () -> 4) ]) - -let f x = - x [ (fun () -> - 3) ; - (fun () -> 4) ] - -let f x = - [ (fun () -> - 3) ; - (fun () -> 4) ] diff --git a/tests/failing/list_of_funs.t b/tests/failing/list_of_funs.t new file mode 100644 index 00000000..38626752 --- /dev/null +++ b/tests/failing/list_of_funs.t @@ -0,0 +1,66 @@ + + $ cat > list_of_funs.ml << "EOF" + > let f x = + > (fun x -> x [ (fun () -> 3) ; + > (fun () -> 4) ]) + > + > let f x = (fun x -> x [ (fun () -> 3) ; + > (fun () -> 4) ]) + > + > let f x = + > x [ (fun () -> 3) ; + > (fun () -> 4) ] + > + > let f x = + > [ (fun () -> 3) ; + > (fun () -> 4) ] + > + > let f x = + > (fun x -> x [ (fun () -> + > 3) ; + > (fun () -> 4) ]) + > + > let f x = (fun x -> x [ (fun () -> + > 3) ; + > (fun () -> 4) ]) + > + > let f x = + > x [ (fun () -> + > 3) ; + > (fun () -> 4) ] + > + > let f x = + > [ (fun () -> + > 3) ; + > (fun () -> 4) ] + > EOF + + $ ocp-indent -c JaneStreet list_of_funs.ml -o list_of_funs.ml.actual + $ diff -u list_of_funs.ml list_of_funs.ml.actual | sed '1,2d' + @@ -15,19 +15,19 @@ + + let f x = + (fun x -> x [ (fun () -> + - 3) ; + - (fun () -> 4) ]) + + 3) ; + + (fun () -> 4) ]) + + let f x = (fun x -> x [ (fun () -> + - 3) ; + - (fun () -> 4) ]) + + 3) ; + + (fun () -> 4) ]) + + let f x = + x [ (fun () -> + - 3) ; + - (fun () -> 4) ] + + 3) ; + + (fun () -> 4) ] + + let f x = + [ (fun () -> + - 3) ; + + 3) ; + (fun () -> 4) ] diff --git a/tests/inplace/dune b/tests/inplace/dune new file mode 100644 index 00000000..2a531567 --- /dev/null +++ b/tests/inplace/dune @@ -0,0 +1,4 @@ +(cram + (enabled_if (= %{os_type} "Unix")) + (deps + (package ocp-indent))) diff --git a/tests/inplace/executable.ml b/tests/inplace/executable.ml deleted file mode 100755 index e69de29b..00000000 diff --git a/tests/inplace/link.ml b/tests/inplace/link.ml deleted file mode 120000 index 4d752eec..00000000 --- a/tests/inplace/link.ml +++ /dev/null @@ -1 +0,0 @@ -otherfile.ml \ No newline at end of file diff --git a/tests/inplace/link2.ml b/tests/inplace/link2.ml deleted file mode 120000 index 8cef0798..00000000 --- a/tests/inplace/link2.ml +++ /dev/null @@ -1 +0,0 @@ -link.ml \ No newline at end of file diff --git a/tests/inplace/otherfile.ml b/tests/inplace/otherfile.ml deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/inplace/run.t b/tests/inplace/run.t new file mode 100644 index 00000000..34325b85 --- /dev/null +++ b/tests/inplace/run.t @@ -0,0 +1,84 @@ +Let's consider the following .ml file + + $ cat > unindented.ml << "EOF" + > let x = + > y + > EOF + $ cp unindented.ml target.ml + +The permissions of a file should be preserved when formatted with +ocp-indent -i: + + $ chmod +x target.ml + $ ls -l target.ml | awk '{print $1}' + -rwxr-xr-x + + $ ocp-indent -i target.ml + + $ ls -l target.ml | awk '{print $1}' + -rwxr-xr-x + + $ cat target.ml + let x = + y + +As we can see, the file was properly formatted and the permissions +untouched. + +Let's reset the target file: + + $ chmod -x target.ml + $ cp unindented.ml target.ml + +Let's create a symlink to that file: + + $ ln -s target.ml link.ml + +Now, running ocp-indent -i on the symlink should not write the result +to link.ml but to the link target and both file should have their permissions +preserved: + + $ ls -l link.ml | awk '{print $1, $(NF-2), $(NF-1), $NF}' + lrwxrwxrwx link.ml -> target.ml + $ ls -l target.ml | awk '{print $1, $NF}' + -rw-r--r-- target.ml + + $ ocp-indent -i link.ml + + $ ls -l link.ml | awk '{print $1, $(NF-2), $(NF-1), $NF}' + lrwxrwxrwx link.ml -> target.ml + $ ls -l target.ml | awk '{print $1, $NF}' + -rw-r--r-- target.ml + + $ cat target.ml + let x = + y + +As we can see here, the link and permissions are preserved and the target +file was properly indented. + +Let's reset the target file: + + $ cp unindented.ml target.ml + +The above properties should hold, no matter the size of the symlink chain: + + $ ln -s link.ml link2.ml + + $ ls -l link*.ml | awk '{print $1, $(NF-2), $(NF-1), $NF}' + lrwxrwxrwx link.ml -> target.ml + lrwxrwxrwx link2.ml -> link.ml + $ ls -l target.ml | awk '{print $1, $NF}' + -rw-r--r-- target.ml + + $ ocp-indent -i link2.ml + + $ ls -l link*.ml | awk '{print $1, $(NF-2), $(NF-1), $NF}' + lrwxrwxrwx link.ml -> target.ml + lrwxrwxrwx link2.ml -> link.ml + $ ls -l target.ml | awk '{print $1, $NF}' + -rw-r--r-- target.ml + + $ cat target.ml + let x = + y diff --git a/tests/passing/alignment.ml b/tests/passing/alignment.ml deleted file mode 100644 index a962d7ba..00000000 --- a/tests/passing/alignment.ml +++ /dev/null @@ -1,43 +0,0 @@ -let file_contents = [ -] - @ [ - foo - ] @ [ - bar - ] - -let _ = - match s.src with - | None -> [ - zz - ] + 2 - | Some s -> [ Variable ( - s_src, - OpamFormat.make_string (OpamFilename.to_string s) - ); - yy ]; - foo - | Some s -> { - fww = - s_src, - OpamFormat.make_string (OpamFilename.to_string s) - ; gdd = - yy - } - -let _ = - [ x; - y ] - @ z - -let _ = - [ - x; - y ] - @ z - -let _ = [ - x; - y -] - @ z diff --git a/tests/passing/alignment.t b/tests/passing/alignment.t new file mode 100644 index 00000000..7e835161 --- /dev/null +++ b/tests/passing/alignment.t @@ -0,0 +1,91 @@ + + $ cat > alignment.ml << "EOF" + > let file_contents = [ + > ] + > @ [ + > foo + > ] @ [ + > bar + > ] + > + > let _ = + > match s.src with + > | None -> [ + > zz + > ] + 2 + > | Some s -> [ Variable ( + > s_src, + > OpamFormat.make_string (OpamFilename.to_string s) + > ); + > yy ]; + > foo + > | Some s -> { + > fww = + > s_src, + > OpamFormat.make_string (OpamFilename.to_string s) + > ; gdd = + > yy + > } + > + > let _ = + > [ x; + > y ] + > @ z + > + > let _ = + > [ + > x; + > y ] + > @ z + > + > let _ = [ + > x; + > y + > ] + > @ z + > EOF + + $ ocp-indent alignment.ml + let file_contents = [ + ] + @ [ + foo + ] @ [ + bar + ] + + let _ = + match s.src with + | None -> [ + zz + ] + 2 + | Some s -> [ Variable ( + s_src, + OpamFormat.make_string (OpamFilename.to_string s) + ); + yy ]; + foo + | Some s -> { + fww = + s_src, + OpamFormat.make_string (OpamFilename.to_string s) + ; gdd = + yy + } + + let _ = + [ x; + y ] + @ z + + let _ = + [ + x; + y ] + @ z + + let _ = [ + x; + y + ] + @ z diff --git a/tests/passing/bracket.ml b/tests/passing/bracket.ml deleted file mode 100644 index cc3ff5f7..00000000 --- a/tests/passing/bracket.ml +++ /dev/null @@ -1,14 +0,0 @@ -let _ = - match a with - | b -> - cccccc [ - d [ - e - ] - ] - | b' -> - (ccccc' [ - d' [ - e' - ] - ]) diff --git a/tests/passing/bracket.t b/tests/passing/bracket.t new file mode 100644 index 00000000..312a27ef --- /dev/null +++ b/tests/passing/bracket.t @@ -0,0 +1,33 @@ + + $ cat > bracket.ml << "EOF" + > let _ = + > match a with + > | b -> + > cccccc [ + > d [ + > e + > ] + > ] + > | b' -> + > (ccccc' [ + > d' [ + > e' + > ] + > ]) + > EOF + + $ ocp-indent bracket.ml + let _ = + match a with + | b -> + cccccc [ + d [ + e + ] + ] + | b' -> + (ccccc' [ + d' [ + e' + ] + ]) diff --git a/tests/passing/cinaps.ml b/tests/passing/cinaps.ml deleted file mode 100644 index cb466d18..00000000 --- a/tests/passing/cinaps.ml +++ /dev/null @@ -1,96 +0,0 @@ -(*$ open Bin_prot_cinaps $*) - -let bin_read_nat0 buf ~pos_ref = - let pos = safe_get_pos buf pos_ref in - assert_pos pos; - match unsafe_get buf pos with - | '\x00'..'\x7f' as ch -> - pos_ref := pos + 1; - Nat0.unsafe_of_int (Char.code ch) - | (*$ Code.char INT16 *)'\xfe'(*$*) -> - safe_bin_read_nat0_16 buf ~pos_ref ~pos:(pos + 1) - | (*$ Code.char INT32 *)'\xfd'(*$*) -> - safe_bin_read_nat0_32 buf ~pos_ref ~pos:(pos + 1) - | (*$ Code.char INT64 *)'\xfc'(*$*) -> - if arch_sixtyfour then - safe_bin_read_nat0_64 buf ~pos_ref ~pos:(pos + 1) - else - raise_read_error ReadError.Nat0_overflow pos - | _ -> - raise_read_error ReadError.Nat0_code pos -[@@ocamlformat "disable"] - -let bin_read_int buf ~pos_ref = - let pos = safe_get_pos buf pos_ref in - assert_pos pos; - match unsafe_get buf pos with - | '\x00'..'\x7f' as ch -> - pos_ref := pos + 1; - Char.code ch - | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> - safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1) - | (*$ Code.char INT16 *)'\xfe'(*$*) -> - safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1) - | (*$ Code.char INT32 *)'\xfd'(*$*) -> - safe_bin_read_int32_as_int buf ~pos_ref ~pos:(pos + 1) - | (*$ Code.char INT64 *)'\xfc'(*$*) -> - if arch_sixtyfour then - safe_bin_read_int64_as_int buf ~pos_ref ~pos:(pos + 1) - else - raise_read_error ReadError.Int_overflow pos - | _ -> - raise_read_error ReadError.Int_code pos -[@@ocamlformat "disable"] - -let bin_read_float buf ~pos_ref = - let pos = safe_get_pos buf pos_ref in - assert_pos pos; - let next = pos + 8 in - check_next buf next; - pos_ref := next; - (* No error possible either. *) - Int64.float_of_bits (unsafe_get64le buf pos) -;; - -let bin_read_int32 buf ~pos_ref = - let pos = safe_get_pos buf pos_ref in - assert_pos pos; - match unsafe_get buf pos with - | '\x00'..'\x7f' as ch -> - pos_ref := pos + 1; - Int32.of_int (Char.code ch) - | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> - Int32.of_int (safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1)) - | (*$ Code.char INT16 *)'\xfe'(*$*) -> - Int32.of_int (safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1)) - | (*$ Code.char INT32 *)'\xfd'(*$*) -> - safe_bin_read_int32 buf ~pos_ref ~pos:(pos + 1) - | _ -> - raise_read_error ReadError.Int32_code pos -[@@ocamlformat "disable"] - -let bin_read_int64 buf ~pos_ref = - let pos = safe_get_pos buf pos_ref in - assert_pos pos; - match unsafe_get buf pos with - | '\x00'..'\x7f' as ch -> - pos_ref := pos + 1; - Int64.of_int (Char.code ch) - | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> - Int64.of_int (safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1)) - | (*$ Code.char INT16 *)'\xfe'(*$*) -> - Int64.of_int (safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1)) - | (*$ Code.char INT32 *)'\xfd'(*$*) -> - safe_bin_read_int32_as_int64 buf ~pos_ref ~pos:(pos + 1) - | (*$ Code.char INT64 *)'\xfc'(*$*) -> - safe_bin_read_int64 buf ~pos_ref ~pos:(pos + 1) - | _ -> - raise_read_error ReadError.Int64_code pos -[@@ocamlformat "disable"] - -let _ = - (*$ - {x=[]}; - () - *) - (*$*) diff --git a/tests/passing/cinaps.t b/tests/passing/cinaps.t new file mode 100644 index 00000000..3ff44524 --- /dev/null +++ b/tests/passing/cinaps.t @@ -0,0 +1,197 @@ + + $ cat > cinaps.ml << "EOF" + > (*$ open Bin_prot_cinaps $*) + > + > let bin_read_nat0 buf ~pos_ref = + > let pos = safe_get_pos buf pos_ref in + > assert_pos pos; + > match unsafe_get buf pos with + > | '\x00'..'\x7f' as ch -> + > pos_ref := pos + 1; + > Nat0.unsafe_of_int (Char.code ch) + > | (*$ Code.char INT16 *)'\xfe'(*$*) -> + > safe_bin_read_nat0_16 buf ~pos_ref ~pos:(pos + 1) + > | (*$ Code.char INT32 *)'\xfd'(*$*) -> + > safe_bin_read_nat0_32 buf ~pos_ref ~pos:(pos + 1) + > | (*$ Code.char INT64 *)'\xfc'(*$*) -> + > if arch_sixtyfour then + > safe_bin_read_nat0_64 buf ~pos_ref ~pos:(pos + 1) + > else + > raise_read_error ReadError.Nat0_overflow pos + > | _ -> + > raise_read_error ReadError.Nat0_code pos + > [@@ocamlformat "disable"] + > + > let bin_read_int buf ~pos_ref = + > let pos = safe_get_pos buf pos_ref in + > assert_pos pos; + > match unsafe_get buf pos with + > | '\x00'..'\x7f' as ch -> + > pos_ref := pos + 1; + > Char.code ch + > | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> + > safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1) + > | (*$ Code.char INT16 *)'\xfe'(*$*) -> + > safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1) + > | (*$ Code.char INT32 *)'\xfd'(*$*) -> + > safe_bin_read_int32_as_int buf ~pos_ref ~pos:(pos + 1) + > | (*$ Code.char INT64 *)'\xfc'(*$*) -> + > if arch_sixtyfour then + > safe_bin_read_int64_as_int buf ~pos_ref ~pos:(pos + 1) + > else + > raise_read_error ReadError.Int_overflow pos + > | _ -> + > raise_read_error ReadError.Int_code pos + > [@@ocamlformat "disable"] + > + > let bin_read_float buf ~pos_ref = + > let pos = safe_get_pos buf pos_ref in + > assert_pos pos; + > let next = pos + 8 in + > check_next buf next; + > pos_ref := next; + > (* No error possible either. *) + > Int64.float_of_bits (unsafe_get64le buf pos) + > ;; + > + > let bin_read_int32 buf ~pos_ref = + > let pos = safe_get_pos buf pos_ref in + > assert_pos pos; + > match unsafe_get buf pos with + > | '\x00'..'\x7f' as ch -> + > pos_ref := pos + 1; + > Int32.of_int (Char.code ch) + > | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> + > Int32.of_int (safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1)) + > | (*$ Code.char INT16 *)'\xfe'(*$*) -> + > Int32.of_int (safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1)) + > | (*$ Code.char INT32 *)'\xfd'(*$*) -> + > safe_bin_read_int32 buf ~pos_ref ~pos:(pos + 1) + > | _ -> + > raise_read_error ReadError.Int32_code pos + > [@@ocamlformat "disable"] + > + > let bin_read_int64 buf ~pos_ref = + > let pos = safe_get_pos buf pos_ref in + > assert_pos pos; + > match unsafe_get buf pos with + > | '\x00'..'\x7f' as ch -> + > pos_ref := pos + 1; + > Int64.of_int (Char.code ch) + > | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> + > Int64.of_int (safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1)) + > | (*$ Code.char INT16 *)'\xfe'(*$*) -> + > Int64.of_int (safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1)) + > | (*$ Code.char INT32 *)'\xfd'(*$*) -> + > safe_bin_read_int32_as_int64 buf ~pos_ref ~pos:(pos + 1) + > | (*$ Code.char INT64 *)'\xfc'(*$*) -> + > safe_bin_read_int64 buf ~pos_ref ~pos:(pos + 1) + > | _ -> + > raise_read_error ReadError.Int64_code pos + > [@@ocamlformat "disable"] + > + > let _ = + > (*$ + > {x=[]}; + > () + > *) + > (*$*) + > EOF + + $ ocp-indent cinaps.ml + (*$ open Bin_prot_cinaps $*) + + let bin_read_nat0 buf ~pos_ref = + let pos = safe_get_pos buf pos_ref in + assert_pos pos; + match unsafe_get buf pos with + | '\x00'..'\x7f' as ch -> + pos_ref := pos + 1; + Nat0.unsafe_of_int (Char.code ch) + | (*$ Code.char INT16 *)'\xfe'(*$*) -> + safe_bin_read_nat0_16 buf ~pos_ref ~pos:(pos + 1) + | (*$ Code.char INT32 *)'\xfd'(*$*) -> + safe_bin_read_nat0_32 buf ~pos_ref ~pos:(pos + 1) + | (*$ Code.char INT64 *)'\xfc'(*$*) -> + if arch_sixtyfour then + safe_bin_read_nat0_64 buf ~pos_ref ~pos:(pos + 1) + else + raise_read_error ReadError.Nat0_overflow pos + | _ -> + raise_read_error ReadError.Nat0_code pos + [@@ocamlformat "disable"] + + let bin_read_int buf ~pos_ref = + let pos = safe_get_pos buf pos_ref in + assert_pos pos; + match unsafe_get buf pos with + | '\x00'..'\x7f' as ch -> + pos_ref := pos + 1; + Char.code ch + | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> + safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1) + | (*$ Code.char INT16 *)'\xfe'(*$*) -> + safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1) + | (*$ Code.char INT32 *)'\xfd'(*$*) -> + safe_bin_read_int32_as_int buf ~pos_ref ~pos:(pos + 1) + | (*$ Code.char INT64 *)'\xfc'(*$*) -> + if arch_sixtyfour then + safe_bin_read_int64_as_int buf ~pos_ref ~pos:(pos + 1) + else + raise_read_error ReadError.Int_overflow pos + | _ -> + raise_read_error ReadError.Int_code pos + [@@ocamlformat "disable"] + + let bin_read_float buf ~pos_ref = + let pos = safe_get_pos buf pos_ref in + assert_pos pos; + let next = pos + 8 in + check_next buf next; + pos_ref := next; + (* No error possible either. *) + Int64.float_of_bits (unsafe_get64le buf pos) + ;; + + let bin_read_int32 buf ~pos_ref = + let pos = safe_get_pos buf pos_ref in + assert_pos pos; + match unsafe_get buf pos with + | '\x00'..'\x7f' as ch -> + pos_ref := pos + 1; + Int32.of_int (Char.code ch) + | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> + Int32.of_int (safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1)) + | (*$ Code.char INT16 *)'\xfe'(*$*) -> + Int32.of_int (safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1)) + | (*$ Code.char INT32 *)'\xfd'(*$*) -> + safe_bin_read_int32 buf ~pos_ref ~pos:(pos + 1) + | _ -> + raise_read_error ReadError.Int32_code pos + [@@ocamlformat "disable"] + + let bin_read_int64 buf ~pos_ref = + let pos = safe_get_pos buf pos_ref in + assert_pos pos; + match unsafe_get buf pos with + | '\x00'..'\x7f' as ch -> + pos_ref := pos + 1; + Int64.of_int (Char.code ch) + | (*$ Code.char NEG_INT8 *)'\xff'(*$*) -> + Int64.of_int (safe_bin_read_neg_int8 buf ~pos_ref ~pos:(pos + 1)) + | (*$ Code.char INT16 *)'\xfe'(*$*) -> + Int64.of_int (safe_bin_read_int16 buf ~pos_ref ~pos:(pos + 1)) + | (*$ Code.char INT32 *)'\xfd'(*$*) -> + safe_bin_read_int32_as_int64 buf ~pos_ref ~pos:(pos + 1) + | (*$ Code.char INT64 *)'\xfc'(*$*) -> + safe_bin_read_int64 buf ~pos_ref ~pos:(pos + 1) + | _ -> + raise_read_error ReadError.Int64_code pos + [@@ocamlformat "disable"] + + let _ = + (*$ + {x=[]}; + () + *) + (*$*) diff --git a/tests/passing/comments.ml b/tests/passing/comments.ml deleted file mode 100644 index f7497c9b..00000000 --- a/tests/passing/comments.ml +++ /dev/null @@ -1,110 +0,0 @@ -(* A *) - -type x = - (* A *) - | Foo - - (* B *) - - | Bar - -(* AA *) - -(* D *) -let x = 3 - -module M = struct - (* M1 *) - let x = - a - (* M2 *) - let y = - b - - (* M3 *) - (* M4 *) -end - -let f x = - if true then - 0 - (* comment *) - else if false then - 1 - -let g x = - if true then - 0 - - (* comment *) - else if false then - 1 - -let _ = - f x - (* bla *) y - (* bla *) (z) - -module M_bad : sig - type _ t = - | A : a -> a t - | B : b -> b t - (** Indented correctly *) - - type 'a t = - | A of 'a - (** Indented correctly *) - - type 'a t = - | A of 'a - | B of 'a - (** Indented too far *) -end - -module M_ok : sig - type _ t = - | A : a -> a t - | B : b -> b t - (** Indented correctly *) - - type 'a t = - | A of 'a - (** Indented correctly *) - - type 'a t = - | A of 'a - | B of 'a - (** Indented correctly! *) - - val x : int -end - -module M = struct - type _ t = - | A : a -> a t - | B : b -> b t - (** Indented too far *) -end - -module type M = sig - type _ t = - | A : a -> a t - | B : b -> b t - (** Indented correctly! *) - - val x : int -end - -module M : sig - type _ t = - | A : a -> a t - (** Indented correctly *) -end - -type _ t = - | A : a -> a t - | B : b -> b t - (** Indented correctly *) - -(* ending comments *) - diff --git a/tests/passing/comments.t b/tests/passing/comments.t new file mode 100644 index 00000000..69348c25 --- /dev/null +++ b/tests/passing/comments.t @@ -0,0 +1,225 @@ + + $ cat > comments.ml << "EOF" + > (* A *) + > + > type x = + > (* A *) + > | Foo + > + > (* B *) + > + > | Bar + > + > (* AA *) + > + > (* D *) + > let x = 3 + > + > module M = struct + > (* M1 *) + > let x = + > a + > (* M2 *) + > let y = + > b + > + > (* M3 *) + > (* M4 *) + > end + > + > let f x = + > if true then + > 0 + > (* comment *) + > else if false then + > 1 + > + > let g x = + > if true then + > 0 + > + > (* comment *) + > else if false then + > 1 + > + > let _ = + > f x + > (* bla *) y + > (* bla *) (z) + > + > module M_bad : sig + > type _ t = + > | A : a -> a t + > | B : b -> b t + > (** Indented correctly *) + > + > type 'a t = + > | A of 'a + > (** Indented correctly *) + > + > type 'a t = + > | A of 'a + > | B of 'a + > (** Indented too far *) + > end + > + > module M_ok : sig + > type _ t = + > | A : a -> a t + > | B : b -> b t + > (** Indented correctly *) + > + > type 'a t = + > | A of 'a + > (** Indented correctly *) + > + > type 'a t = + > | A of 'a + > | B of 'a + > (** Indented correctly! *) + > + > val x : int + > end + > + > module M = struct + > type _ t = + > | A : a -> a t + > | B : b -> b t + > (** Indented too far *) + > end + > + > module type M = sig + > type _ t = + > | A : a -> a t + > | B : b -> b t + > (** Indented correctly! *) + > + > val x : int + > end + > + > module M : sig + > type _ t = + > | A : a -> a t + > (** Indented correctly *) + > end + > + > type _ t = + > | A : a -> a t + > | B : b -> b t + > (** Indented correctly *) + > + > (* ending comments *) + > + > EOF + + $ ocp-indent comments.ml + (* A *) + + type x = + (* A *) + | Foo + + (* B *) + + | Bar + + (* AA *) + + (* D *) + let x = 3 + + module M = struct + (* M1 *) + let x = + a + (* M2 *) + let y = + b + + (* M3 *) + (* M4 *) + end + + let f x = + if true then + 0 + (* comment *) + else if false then + 1 + + let g x = + if true then + 0 + + (* comment *) + else if false then + 1 + + let _ = + f x + (* bla *) y + (* bla *) (z) + + module M_bad : sig + type _ t = + | A : a -> a t + | B : b -> b t + (** Indented correctly *) + + type 'a t = + | A of 'a + (** Indented correctly *) + + type 'a t = + | A of 'a + | B of 'a + (** Indented too far *) + end + + module M_ok : sig + type _ t = + | A : a -> a t + | B : b -> b t + (** Indented correctly *) + + type 'a t = + | A of 'a + (** Indented correctly *) + + type 'a t = + | A of 'a + | B of 'a + (** Indented correctly! *) + + val x : int + end + + module M = struct + type _ t = + | A : a -> a t + | B : b -> b t + (** Indented too far *) + end + + module type M = sig + type _ t = + | A : a -> a t + | B : b -> b t + (** Indented correctly! *) + + val x : int + end + + module M : sig + type _ t = + | A : a -> a t + (** Indented correctly *) + end + + type _ t = + | A : a -> a t + | B : b -> b t + (** Indented correctly *) + + (* ending comments *) + diff --git a/tests/passing/core-failing.ml b/tests/passing/core-failing.ml deleted file mode 100644 index 14f7f09d..00000000 --- a/tests/passing/core-failing.ml +++ /dev/null @@ -1,19 +0,0 @@ -exception IOError of - int * - exn - -module type S = S - with type ('a, 'b, 'c) map := ('a, 'b, 'c) t - -let _ = - let start_finaliser_thread () = - ignore (Thread.create (fun () -> Fn.forever (fun () -> - match read_finaliser_queue () with - | None -> Thread.delay 1.0 - | Some f -> Exn.handle_uncaught ~exit:false f)) ()) - in - () - -module F - (A) - (B) diff --git a/tests/passing/core-failing.t b/tests/passing/core-failing.t new file mode 100644 index 00000000..0e0e6d00 --- /dev/null +++ b/tests/passing/core-failing.t @@ -0,0 +1,43 @@ + + $ cat > core-failing.ml << "EOF" + > exception IOError of + > int * + > exn + > + > module type S = S + > with type ('a, 'b, 'c) map := ('a, 'b, 'c) t + > + > let _ = + > let start_finaliser_thread () = + > ignore (Thread.create (fun () -> Fn.forever (fun () -> + > match read_finaliser_queue () with + > | None -> Thread.delay 1.0 + > | Some f -> Exn.handle_uncaught ~exit:false f)) ()) + > in + > () + > + > module F + > (A) + > (B) + > EOF + + $ ocp-indent core-failing.ml + exception IOError of + int * + exn + + module type S = S + with type ('a, 'b, 'c) map := ('a, 'b, 'c) t + + let _ = + let start_finaliser_thread () = + ignore (Thread.create (fun () -> Fn.forever (fun () -> + match read_finaliser_queue () with + | None -> Thread.delay 1.0 + | Some f -> Exn.handle_uncaught ~exit:false f)) ()) + in + () + + module F + (A) + (B) diff --git a/tests/passing/core-passing.ml b/tests/passing/core-passing.ml deleted file mode 100644 index dd8e712c..00000000 --- a/tests/passing/core-passing.ml +++ /dev/null @@ -1,181 +0,0 @@ -type t1 = - { - a: int; - b: int -> int; - c: int; - } - -let try_lock t = - wrap_mutex a.b (fun () -> - was_locked) - -let blit_string_bigstring ~src ?src_pos ?src_len ~dst ?dst_pos () = - blit_common - ~get_src_len:String.length ~get_dst_len:length - ~blit:unsafe_blit_string_bigstring - ~src ?src_pos ?src_len ~dst ?dst_pos - () - -let f = - test bla Int32.to_string - pack_signed_32 - -module S : S1 - with type t = S1.t - with type comparator = S.comparator - -let error_string message = error message () <:sexp_of< unit >> -let unimplemented s = () - -let () = - StdLabels.List.iter - ~f:(fun (exc, handler) -> - Conv.Exn_converter.add_auto ~finalise:false exc handler) - () - -let _ = - Date.to_string date - :: " " - :: (if is_utc then ["Z"] - else bla) - -val v - : t - -let _ = - let module M = (val m : S with type t = t') in - x - -let a,b,c = - d - -type t = t0 = { - a: int; -} - -type t2 = [ - | `a - | `b -] - -type t = private - | A - | B - -module Make : (S with type t = t') = -struct - type contents = C.t -end - -module Map_and_set_binable = struct - module C : (S with type t = t) - val v -end - -type compare = - [`no_polymorphic_compare] - -> [`no_polymorphic_compare] - -let _ = - {Parts. - sign = sign; - hr = hr; - } - -module M (A) : sig - val bla : bla -end = struct -end - -val marshal_blit : - ?flags : Marshal.extern_flags list -> 'a -> - ?pos : int -> ?len : int -> t -> int - -let daemonize ?(redirect_stdout=`Dev_null) ?(redirect_stderr=`Dev_null) - ?(cd = "/") ?umask:(umask_value = default_umask) () = - bla - -val add : - t -> - (event -> Time.t -> unit) -> - a - -let _ = match a with - | A - when b -> c - | A b - when b -> c - -module S : S1 - with type t = S1.t - with type comparator = S.comparator - -let _ = - let f x = - bla - and g x = - bli - -include struct - exception Break = Break - let y = 2 -end - -let should_check_can_sell_and_marking regulatory_regime = - match z with - | `foo - -> some_function - argument; - flu - | `foo -> some_function - argument; - flu - -let _ = - invalid_arg - (sprintf "Dequeue.%s: index %i is not in [%d, %d]" - fname i (front_index buf) (back_index buf)) - -let mem { ar; cmp } el = - let len = Array.length ar in - len > 0 && - let rec loop pos = - bla - in - blu - -let blit_to (type a) (blit : (Base.t, a) Blit.t) = - (); fun t ~dst ~dst_pos -> - blit ~src:t.base ~src_pos:t.pos ~src_len:t.len ~dst ~dst_pos () - -type 'a t = 'a Bin_prot.Type_class.writer -= { size : 'a Size.sizer; - write : 'a Write_ml.writer; - unsafe_write : 'a Unsafe_write_c.writer; - } - -let create - ?(message = Pid.to_string (Unix.getpid ())) - ?(close_on_exec=true) - = - xx - -module Make_using_comparator (Elt : Comparator.S) - : S with type Elt.t = Elt.t - with type Elt.comparator = Elt.comparator - -let _ = - find_thread_count - (In_channel.read_lines - ("/proc/" ^ string_of_int (Unix.getpid ()) ^ "/status")) - -type variant = [ `Jan | `Feb | `Mar | `Apr | `May | `Jun - | `Jul | `Aug | `Sep | `Oct | `Nov | `Dec ] - -let _ = - let exception E in - () - -let _ = - let exception E of string in - () diff --git a/tests/passing/core-passing.t b/tests/passing/core-passing.t new file mode 100644 index 00000000..8186382c --- /dev/null +++ b/tests/passing/core-passing.t @@ -0,0 +1,367 @@ + + $ cat > core-passing.ml << "EOF" + > type t1 = + > { + > a: int; + > b: int -> int; + > c: int; + > } + > + > let try_lock t = + > wrap_mutex a.b (fun () -> + > was_locked) + > + > let blit_string_bigstring ~src ?src_pos ?src_len ~dst ?dst_pos () = + > blit_common + > ~get_src_len:String.length ~get_dst_len:length + > ~blit:unsafe_blit_string_bigstring + > ~src ?src_pos ?src_len ~dst ?dst_pos + > () + > + > let f = + > test bla Int32.to_string + > pack_signed_32 + > + > module S : S1 + > with type t = S1.t + > with type comparator = S.comparator + > + > let error_string message = error message () <:sexp_of< unit >> + > let unimplemented s = () + > + > let () = + > StdLabels.List.iter + > ~f:(fun (exc, handler) -> + > Conv.Exn_converter.add_auto ~finalise:false exc handler) + > () + > + > let _ = + > Date.to_string date + > :: " " + > :: (if is_utc then ["Z"] + > else bla) + > + > val v + > : t + > + > let _ = + > let module M = (val m : S with type t = t') in + > x + > + > let a,b,c = + > d + > + > type t = t0 = { + > a: int; + > } + > + > type t2 = [ + > | `a + > | `b + > ] + > + > type t = private + > | A + > | B + > + > module Make : (S with type t = t') = + > struct + > type contents = C.t + > end + > + > module Map_and_set_binable = struct + > module C : (S with type t = t) + > val v + > end + > + > type compare = + > [`no_polymorphic_compare] + > -> [`no_polymorphic_compare] + > + > let _ = + > {Parts. + > sign = sign; + > hr = hr; + > } + > + > module M (A) : sig + > val bla : bla + > end = struct + > end + > + > val marshal_blit : + > ?flags : Marshal.extern_flags list -> 'a -> + > ?pos : int -> ?len : int -> t -> int + > + > let daemonize ?(redirect_stdout=`Dev_null) ?(redirect_stderr=`Dev_null) + > ?(cd = "/") ?umask:(umask_value = default_umask) () = + > bla + > + > val add : + > t -> + > (event -> Time.t -> unit) -> + > a + > + > let _ = match a with + > | A + > when b -> c + > | A b + > when b -> c + > + > module S : S1 + > with type t = S1.t + > with type comparator = S.comparator + > + > let _ = + > let f x = + > bla + > and g x = + > bli + > + > include struct + > exception Break = Break + > let y = 2 + > end + > + > let should_check_can_sell_and_marking regulatory_regime = + > match z with + > | `foo + > -> some_function + > argument; + > flu + > | `foo -> some_function + > argument; + > flu + > + > let _ = + > invalid_arg + > (sprintf "Dequeue.%s: index %i is not in [%d, %d]" + > fname i (front_index buf) (back_index buf)) + > + > let mem { ar; cmp } el = + > let len = Array.length ar in + > len > 0 && + > let rec loop pos = + > bla + > in + > blu + > + > let blit_to (type a) (blit : (Base.t, a) Blit.t) = + > (); fun t ~dst ~dst_pos -> + > blit ~src:t.base ~src_pos:t.pos ~src_len:t.len ~dst ~dst_pos () + > + > type 'a t = 'a Bin_prot.Type_class.writer + > = { size : 'a Size.sizer; + > write : 'a Write_ml.writer; + > unsafe_write : 'a Unsafe_write_c.writer; + > } + > + > let create + > ?(message = Pid.to_string (Unix.getpid ())) + > ?(close_on_exec=true) + > = + > xx + > + > module Make_using_comparator (Elt : Comparator.S) + > : S with type Elt.t = Elt.t + > with type Elt.comparator = Elt.comparator + > + > let _ = + > find_thread_count + > (In_channel.read_lines + > ("/proc/" ^ string_of_int (Unix.getpid ()) ^ "/status")) + > + > type variant = [ `Jan | `Feb | `Mar | `Apr | `May | `Jun + > | `Jul | `Aug | `Sep | `Oct | `Nov | `Dec ] + > + > let _ = + > let exception E in + > () + > + > let _ = + > let exception E of string in + > () + > EOF + + $ ocp-indent core-passing.ml + type t1 = + { + a: int; + b: int -> int; + c: int; + } + + let try_lock t = + wrap_mutex a.b (fun () -> + was_locked) + + let blit_string_bigstring ~src ?src_pos ?src_len ~dst ?dst_pos () = + blit_common + ~get_src_len:String.length ~get_dst_len:length + ~blit:unsafe_blit_string_bigstring + ~src ?src_pos ?src_len ~dst ?dst_pos + () + + let f = + test bla Int32.to_string + pack_signed_32 + + module S : S1 + with type t = S1.t + with type comparator = S.comparator + + let error_string message = error message () <:sexp_of< unit >> + let unimplemented s = () + + let () = + StdLabels.List.iter + ~f:(fun (exc, handler) -> + Conv.Exn_converter.add_auto ~finalise:false exc handler) + () + + let _ = + Date.to_string date + :: " " + :: (if is_utc then ["Z"] + else bla) + + val v + : t + + let _ = + let module M = (val m : S with type t = t') in + x + + let a,b,c = + d + + type t = t0 = { + a: int; + } + + type t2 = [ + | `a + | `b + ] + + type t = private + | A + | B + + module Make : (S with type t = t') = + struct + type contents = C.t + end + + module Map_and_set_binable = struct + module C : (S with type t = t) + val v + end + + type compare = + [`no_polymorphic_compare] + -> [`no_polymorphic_compare] + + let _ = + {Parts. + sign = sign; + hr = hr; + } + + module M (A) : sig + val bla : bla + end = struct + end + + val marshal_blit : + ?flags : Marshal.extern_flags list -> 'a -> + ?pos : int -> ?len : int -> t -> int + + let daemonize ?(redirect_stdout=`Dev_null) ?(redirect_stderr=`Dev_null) + ?(cd = "/") ?umask:(umask_value = default_umask) () = + bla + + val add : + t -> + (event -> Time.t -> unit) -> + a + + let _ = match a with + | A + when b -> c + | A b + when b -> c + + module S : S1 + with type t = S1.t + with type comparator = S.comparator + + let _ = + let f x = + bla + and g x = + bli + + include struct + exception Break = Break + let y = 2 + end + + let should_check_can_sell_and_marking regulatory_regime = + match z with + | `foo + -> some_function + argument; + flu + | `foo -> some_function + argument; + flu + + let _ = + invalid_arg + (sprintf "Dequeue.%s: index %i is not in [%d, %d]" + fname i (front_index buf) (back_index buf)) + + let mem { ar; cmp } el = + let len = Array.length ar in + len > 0 && + let rec loop pos = + bla + in + blu + + let blit_to (type a) (blit : (Base.t, a) Blit.t) = + (); fun t ~dst ~dst_pos -> + blit ~src:t.base ~src_pos:t.pos ~src_len:t.len ~dst ~dst_pos () + + type 'a t = 'a Bin_prot.Type_class.writer + = { size : 'a Size.sizer; + write : 'a Write_ml.writer; + unsafe_write : 'a Unsafe_write_c.writer; + } + + let create + ?(message = Pid.to_string (Unix.getpid ())) + ?(close_on_exec=true) + = + xx + + module Make_using_comparator (Elt : Comparator.S) + : S with type Elt.t = Elt.t + with type Elt.comparator = Elt.comparator + + let _ = + find_thread_count + (In_channel.read_lines + ("/proc/" ^ string_of_int (Unix.getpid ()) ^ "/status")) + + type variant = [ `Jan | `Feb | `Mar | `Apr | `May | `Jun + | `Jul | `Aug | `Sep | `Oct | `Nov | `Dec ] + + let _ = + let exception E in + () + + let _ = + let exception E of string in + () diff --git a/tests/passing/dune b/tests/passing/dune new file mode 100644 index 00000000..ddd4a8c5 --- /dev/null +++ b/tests/passing/dune @@ -0,0 +1,3 @@ +(cram + (deps + (package ocp-indent))) diff --git a/tests/passing/edge-cases.ml b/tests/passing/edge-cases.ml deleted file mode 100644 index ef1662a9..00000000 --- a/tests/passing/edge-cases.ml +++ /dev/null @@ -1,91 +0,0 @@ - -(* this could be fixed, but we actually want to handle the first case - differently for when there is only one case (see next examples) *) -let f x = function A -> x; - 2 - | B -> y; - 3 - -(* if we were to fix to the case above, the second >>= would be below the _ - (test taken from js-fun) *) -let _ = - x - >>= fun x -> - try x with _ -> () - >>= fun x -> - x - -(* (and also: the some_handling here would be below Not_found) *) -let _ = - try - _ - with Not_found -> - some_handling - -let f = fun x -> - x - -let f = (fun x -> - x - ) - -let f g = g @@ fun x -> - x - -let f g = g @@ (fun x -> - x - ) - - -(* the above should probably be consistent with: *) -let f x y = y + match x with A -> - 0 - -let f x y = y + (match x with A -> - 0 - ) - -(* wich means we may over-indent even when the block is non-closable *) - -let f x y = y + match x with - | A -> 0 - -let f x y = y + (match x with - | A -> 0 - ) - -let f x y = y + match x with - | A -> 0 - -let _ = - somefun - (fun x -> - x); - somefun - (if - bla - then - bli); - somefun - (if bla then - bli - else - blu) - -let _ = - a - ; - b - -(* Surprisingly, this is the indentation correpsonding to OCaml's interpretation - of this code. Indenting this accordingly may help users notice that they're - doing something dubious. - EDIT Louis/2019: [function] used to be unindented. Not sure what the above - meant since this is a parse error anyway ? -*) -let b = `b -let d = `d -;; -let a = b - function (_ : [ `c ]) -> d -;; diff --git a/tests/passing/edge-cases.t b/tests/passing/edge-cases.t new file mode 100644 index 00000000..2880ea4b --- /dev/null +++ b/tests/passing/edge-cases.t @@ -0,0 +1,187 @@ + + $ cat > edge-cases.ml << "EOF" + > + > (* this could be fixed, but we actually want to handle the first case + > differently for when there is only one case (see next examples) *) + > let f x = function A -> x; + > 2 + > | B -> y; + > 3 + > + > (* if we were to fix to the case above, the second >>= would be below the _ + > (test taken from js-fun) *) + > let _ = + > x + > >>= fun x -> + > try x with _ -> () + > >>= fun x -> + > x + > + > (* (and also: the some_handling here would be below Not_found) *) + > let _ = + > try + > _ + > with Not_found -> + > some_handling + > + > let f = fun x -> + > x + > + > let f = (fun x -> + > x + > ) + > + > let f g = g @@ fun x -> + > x + > + > let f g = g @@ (fun x -> + > x + > ) + > + > + > (* the above should probably be consistent with: *) + > let f x y = y + match x with A -> + > 0 + > + > let f x y = y + (match x with A -> + > 0 + > ) + > + > (* wich means we may over-indent even when the block is non-closable *) + > + > let f x y = y + match x with + > | A -> 0 + > + > let f x y = y + (match x with + > | A -> 0 + > ) + > + > let f x y = y + match x with + > | A -> 0 + > + > let _ = + > somefun + > (fun x -> + > x); + > somefun + > (if + > bla + > then + > bli); + > somefun + > (if bla then + > bli + > else + > blu) + > + > let _ = + > a + > ; + > b + > + > (* Surprisingly, this is the indentation correpsonding to OCaml's interpretation + > of this code. Indenting this accordingly may help users notice that they're + > doing something dubious. + > EDIT Louis/2019: [function] used to be unindented. Not sure what the above + > meant since this is a parse error anyway ? + > *) + > let b = `b + > let d = `d + > ;; + > let a = b + > function (_ : [ `c ]) -> d + > ;; + > EOF + + $ ocp-indent edge-cases.ml + + (* this could be fixed, but we actually want to handle the first case + differently for when there is only one case (see next examples) *) + let f x = function A -> x; + 2 + | B -> y; + 3 + + (* if we were to fix to the case above, the second >>= would be below the _ + (test taken from js-fun) *) + let _ = + x + >>= fun x -> + try x with _ -> () + >>= fun x -> + x + + (* (and also: the some_handling here would be below Not_found) *) + let _ = + try + _ + with Not_found -> + some_handling + + let f = fun x -> + x + + let f = (fun x -> + x + ) + + let f g = g @@ fun x -> + x + + let f g = g @@ (fun x -> + x + ) + + + (* the above should probably be consistent with: *) + let f x y = y + match x with A -> + 0 + + let f x y = y + (match x with A -> + 0 + ) + + (* wich means we may over-indent even when the block is non-closable *) + + let f x y = y + match x with + | A -> 0 + + let f x y = y + (match x with + | A -> 0 + ) + + let f x y = y + match x with + | A -> 0 + + let _ = + somefun + (fun x -> + x); + somefun + (if + bla + then + bli); + somefun + (if bla then + bli + else + blu) + + let _ = + a + ; + b + + (* Surprisingly, this is the indentation correpsonding to OCaml's interpretation + of this code. Indenting this accordingly may help users notice that they're + doing something dubious. + EDIT Louis/2019: [function] used to be unindented. Not sure what the above + meant since this is a parse error anyway ? + *) + let b = `b + let d = `d + ;; + let a = b + function (_ : [ `c ]) -> d + ;; diff --git a/tests/passing/embedded-match.ml b/tests/passing/embedded-match.ml deleted file mode 100644 index a1b58ecb..00000000 --- a/tests/passing/embedded-match.ml +++ /dev/null @@ -1,32 +0,0 @@ -let f x = function - | A when match x with A | B -> true | _ -> false - -> - B - | A -> x - | _ -> B - -let f x = - if - match x with - | A -> true - then - 1 - else - 0 - -let f x = - match x with - | A -> true - | B -> - false - | exception - Not_found -> - false - | C -> true - | exception (Failure _ | Invalid_argument _) -> - true - | exception (A | B) | exception B.Err - | exception C.Types.Xxx "someparam" -> - false - -exception MyExn of string diff --git a/tests/passing/embedded-match.t b/tests/passing/embedded-match.t new file mode 100644 index 00000000..cd860c3f --- /dev/null +++ b/tests/passing/embedded-match.t @@ -0,0 +1,69 @@ + + $ cat > embedded-match.ml << "EOF" + > let f x = function + > | A when match x with A | B -> true | _ -> false + > -> + > B + > | A -> x + > | _ -> B + > + > let f x = + > if + > match x with + > | A -> true + > then + > 1 + > else + > 0 + > + > let f x = + > match x with + > | A -> true + > | B -> + > false + > | exception + > Not_found -> + > false + > | C -> true + > | exception (Failure _ | Invalid_argument _) -> + > true + > | exception (A | B) | exception B.Err + > | exception C.Types.Xxx "someparam" -> + > false + > + > exception MyExn of string + > EOF + + $ ocp-indent embedded-match.ml + let f x = function + | A when match x with A | B -> true | _ -> false + -> + B + | A -> x + | _ -> B + + let f x = + if + match x with + | A -> true + then + 1 + else + 0 + + let f x = + match x with + | A -> true + | B -> + false + | exception + Not_found -> + false + | C -> true + | exception (Failure _ | Invalid_argument _) -> + true + | exception (A | B) | exception B.Err + | exception C.Types.Xxx "someparam" -> + false + + exception MyExn of string diff --git a/tests/passing/exprs.ml b/tests/passing/exprs.ml deleted file mode 100644 index 6636fe5e..00000000 --- a/tests/passing/exprs.ml +++ /dev/null @@ -1,105 +0,0 @@ -f "foo" - g - [ 1; - 2] -;; - -let x = - f 1 ((x 3) - || (x f) - lor (g lsl k) - lor g - && g - lsr g) - -let f x = - g - (fun x -> x) - [] - x:x - ?y:z - () - 0 - -let f - ~p - ~g - () - ?k - () = - let x = 0 in - p - -let f = - for i = 0 to 1; do - a; - b; - done; - x - -external f : - 'a -> x : int -> t - = "b" - -external g : - x : t -> s : i -> d : t -> unit - = "b2" - -let f ?(g = []) v ?(x = 0) ?l b = - let l = g b ~p l in - c ~l:"foo" b ~p ~l; - u v ~p ~l b f - -let f () = - g x y - ?x:y ?y:w - ~a:b - -let f () = - f (fun () -> - for i = 0 to 10 do - g - done; - x - ) - -external f: int -> int = "foo" - -let f () = - for i = 0 to 10 do - g - done - -let f () = - { x = 1; - y = 2; - } - -let f () = { - x = 1; - y = 2; -} - -let f () = - { - x = 1; - y = 2; - } - -let f () = - { x = 1 - ; y = 2 } - -let f x = - if x then - x - else - f @@ fun () -> - g; - h - -let funct param - : A_very_long_module_name.t t1 - * t2 - = - something diff --git a/tests/passing/exprs.t b/tests/passing/exprs.t new file mode 100644 index 00000000..e178e325 --- /dev/null +++ b/tests/passing/exprs.t @@ -0,0 +1,215 @@ + + $ cat > exprs.ml << "EOF" + > f "foo" + > g + > [ 1; + > 2] + > ;; + > + > let x = + > f 1 ((x 3) + > || (x f) + > lor (g lsl k) + > lor g + > && g + > lsr g) + > + > let f x = + > g + > (fun x -> x) + > [] + > x:x + > ?y:z + > () + > 0 + > + > let f + > ~p + > ~g + > () + > ?k + > () = + > let x = 0 in + > p + > + > let f = + > for i = 0 to 1; do + > a; + > b; + > done; + > x + > + > external f : + > 'a -> x : int -> t + > = "b" + > + > external g : + > x : t -> s : i -> d : t -> unit + > = "b2" + > + > let f ?(g = []) v ?(x = 0) ?l b = + > let l = g b ~p l in + > c ~l:"foo" b ~p ~l; + > u v ~p ~l b f + > + > let f () = + > g x y + > ?x:y ?y:w + > ~a:b + > + > let f () = + > f (fun () -> + > for i = 0 to 10 do + > g + > done; + > x + > ) + > + > external f: int -> int = "foo" + > + > let f () = + > for i = 0 to 10 do + > g + > done + > + > let f () = + > { x = 1; + > y = 2; + > } + > + > let f () = { + > x = 1; + > y = 2; + > } + > + > let f () = + > { + > x = 1; + > y = 2; + > } + > + > let f () = + > { x = 1 + > ; y = 2 } + > + > let f x = + > if x then + > x + > else + > f @@ fun () -> + > g; + > h + > + > let funct param + > : A_very_long_module_name.t t1 + > * t2 + > = + > something + > EOF + + $ ocp-indent exprs.ml + f "foo" + g + [ 1; + 2] + ;; + + let x = + f 1 ((x 3) + || (x f) + lor (g lsl k) + lor g + && g + lsr g) + + let f x = + g + (fun x -> x) + [] + x:x + ?y:z + () + 0 + + let f + ~p + ~g + () + ?k + () = + let x = 0 in + p + + let f = + for i = 0 to 1; do + a; + b; + done; + x + + external f : + 'a -> x : int -> t + = "b" + + external g : + x : t -> s : i -> d : t -> unit + = "b2" + + let f ?(g = []) v ?(x = 0) ?l b = + let l = g b ~p l in + c ~l:"foo" b ~p ~l; + u v ~p ~l b f + + let f () = + g x y + ?x:y ?y:w + ~a:b + + let f () = + f (fun () -> + for i = 0 to 10 do + g + done; + x + ) + + external f: int -> int = "foo" + + let f () = + for i = 0 to 10 do + g + done + + let f () = + { x = 1; + y = 2; + } + + let f () = { + x = 1; + y = 2; + } + + let f () = + { + x = 1; + y = 2; + } + + let f () = + { x = 1 + ; y = 2 } + + let f x = + if x then + x + else + f @@ fun () -> + g; + h + + let funct param + : A_very_long_module_name.t t1 + * t2 + = + something diff --git a/tests/passing/extensible.ml b/tests/passing/extensible.ml deleted file mode 100644 index 790f47d1..00000000 --- a/tests/passing/extensible.ml +++ /dev/null @@ -1,39 +0,0 @@ -(* Simple declaration : OK *) -type t = .. -type t += - A - | B - -(* But : *) -type t = .. -type t += - | A - | B - -(* Inside modules : same pb *) -module P = struct - type t = .. - type t += - | A - | B -end - -module Q = struct - type P.t += - | C - | D -end - -(* another one *) -module Q' = struct - type P.t += - | C = P.A - | D -end - -(* also *) -module M = struct - type t = .. - let a = 1 - let b = 2 -end diff --git a/tests/passing/extensible.t b/tests/passing/extensible.t new file mode 100644 index 00000000..5f4e93fb --- /dev/null +++ b/tests/passing/extensible.t @@ -0,0 +1,83 @@ + + $ cat > extensible.ml << "EOF" + > (* Simple declaration : OK *) + > type t = .. + > type t += + > A + > | B + > + > (* But : *) + > type t = .. + > type t += + > | A + > | B + > + > (* Inside modules : same pb *) + > module P = struct + > type t = .. + > type t += + > | A + > | B + > end + > + > module Q = struct + > type P.t += + > | C + > | D + > end + > + > (* another one *) + > module Q' = struct + > type P.t += + > | C = P.A + > | D + > end + > + > (* also *) + > module M = struct + > type t = .. + > let a = 1 + > let b = 2 + > end + > EOF + + $ ocp-indent extensible.ml + (* Simple declaration : OK *) + type t = .. + type t += + A + | B + + (* But : *) + type t = .. + type t += + | A + | B + + (* Inside modules : same pb *) + module P = struct + type t = .. + type t += + | A + | B + end + + module Q = struct + type P.t += + | C + | D + end + + (* another one *) + module Q' = struct + type P.t += + | C = P.A + | D + end + + (* also *) + module M = struct + type t = .. + let a = 1 + let b = 2 + end diff --git a/tests/passing/gadt.ml b/tests/passing/gadt.ml deleted file mode 100644 index 3485d972..00000000 --- a/tests/passing/gadt.ml +++ /dev/null @@ -1,78 +0,0 @@ -type _ term = - | Int : int -> int term - | Add : (int -> int -> int) term - | App : ('b -> 'a) term * 'b term -> 'a term - -let rec eval : type a. a term -> a = function - | Int n -> n (* a = int *) - | Add -> (fun x y -> x+y) (* a = int -> int -> int *) - | App(f,x) -> (eval f) (eval x) -(* eval called at types (b->a) and b for fresh b *) - -let two = eval (App (App (Add, Int 1), Int 1)) - -let rec sum : type a. a term -> _ = fun x -> - let y = - match x with - | Int n -> n - | Add -> 0 - | App(f,x) -> sum f + sum x - in y + 1 - -type _ typ = - | Int : int typ - | String : string typ - | Pair : 'a typ * 'b typ -> ('a * 'b) typ - -let rec to_string: type t. t typ -> t -> string = - fun t x -> - match t with - | Int -> string_of_int x - | String -> Printf.sprintf "%S" x - | Pair(t1,t2) -> - let (x1, x2) = x in - Printf.sprintf "(%s,%s)" (to_string t1 x1) (to_string t2 x2) - -type (_,_) eq = Eq : ('a,'a) eq - -let cast : type a b. (a,b) eq -> a -> b = fun Eq x -> x - -let rec eq_type : type a b. a typ -> b typ -> (a,b) eq option = - fun a b -> - match a, b with - | Int, Int -> Some Eq - | String, String -> Some Eq - | Pair(a1,a2), Pair(b1,b2) -> - begin match eq_type a1 b1, eq_type a2 b2 with - | Some Eq, Some Eq -> Some Eq - | _ -> None - end - | _ -> None - -type dyn = Dyn : 'a typ * 'a -> dyn - -let get_dyn : type a. a typ -> dyn -> a option = - fun a (Dyn(b,x)) -> - match eq_type a b with - | None -> None - | Some Eq -> Some x - -let _ = - let f: type a. a list -> int = - fun _x -> 42 - in - f [] - -let nth t n = - if n < 0 then None else - let rec nth_aux: type b. ('a, b) t -> int -> 'a option = fun t n -> - match t with - | Empty -> None - | Node (a, t) -> if n = 0 then Some a else nth_aux t (n-1) - in - nth_aux t n - -let rec f : type a b. a = function - | _ -> assert false -and g : type a. a = function - | _ -> assert false diff --git a/tests/passing/gadt.t b/tests/passing/gadt.t new file mode 100644 index 00000000..cbcf3b8a --- /dev/null +++ b/tests/passing/gadt.t @@ -0,0 +1,161 @@ + + $ cat > gadt.ml << "EOF" + > type _ term = + > | Int : int -> int term + > | Add : (int -> int -> int) term + > | App : ('b -> 'a) term * 'b term -> 'a term + > + > let rec eval : type a. a term -> a = function + > | Int n -> n (* a = int *) + > | Add -> (fun x y -> x+y) (* a = int -> int -> int *) + > | App(f,x) -> (eval f) (eval x) + > (* eval called at types (b->a) and b for fresh b *) + > + > let two = eval (App (App (Add, Int 1), Int 1)) + > + > let rec sum : type a. a term -> _ = fun x -> + > let y = + > match x with + > | Int n -> n + > | Add -> 0 + > | App(f,x) -> sum f + sum x + > in y + 1 + > + > type _ typ = + > | Int : int typ + > | String : string typ + > | Pair : 'a typ * 'b typ -> ('a * 'b) typ + > + > let rec to_string: type t. t typ -> t -> string = + > fun t x -> + > match t with + > | Int -> string_of_int x + > | String -> Printf.sprintf "%S" x + > | Pair(t1,t2) -> + > let (x1, x2) = x in + > Printf.sprintf "(%s,%s)" (to_string t1 x1) (to_string t2 x2) + > + > type (_,_) eq = Eq : ('a,'a) eq + > + > let cast : type a b. (a,b) eq -> a -> b = fun Eq x -> x + > + > let rec eq_type : type a b. a typ -> b typ -> (a,b) eq option = + > fun a b -> + > match a, b with + > | Int, Int -> Some Eq + > | String, String -> Some Eq + > | Pair(a1,a2), Pair(b1,b2) -> + > begin match eq_type a1 b1, eq_type a2 b2 with + > | Some Eq, Some Eq -> Some Eq + > | _ -> None + > end + > | _ -> None + > + > type dyn = Dyn : 'a typ * 'a -> dyn + > + > let get_dyn : type a. a typ -> dyn -> a option = + > fun a (Dyn(b,x)) -> + > match eq_type a b with + > | None -> None + > | Some Eq -> Some x + > + > let _ = + > let f: type a. a list -> int = + > fun _x -> 42 + > in + > f [] + > + > let nth t n = + > if n < 0 then None else + > let rec nth_aux: type b. ('a, b) t -> int -> 'a option = fun t n -> + > match t with + > | Empty -> None + > | Node (a, t) -> if n = 0 then Some a else nth_aux t (n-1) + > in + > nth_aux t n + > + > let rec f : type a b. a = function + > | _ -> assert false + > and g : type a. a = function + > | _ -> assert false + > EOF + + $ ocp-indent gadt.ml + type _ term = + | Int : int -> int term + | Add : (int -> int -> int) term + | App : ('b -> 'a) term * 'b term -> 'a term + + let rec eval : type a. a term -> a = function + | Int n -> n (* a = int *) + | Add -> (fun x y -> x+y) (* a = int -> int -> int *) + | App(f,x) -> (eval f) (eval x) + (* eval called at types (b->a) and b for fresh b *) + + let two = eval (App (App (Add, Int 1), Int 1)) + + let rec sum : type a. a term -> _ = fun x -> + let y = + match x with + | Int n -> n + | Add -> 0 + | App(f,x) -> sum f + sum x + in y + 1 + + type _ typ = + | Int : int typ + | String : string typ + | Pair : 'a typ * 'b typ -> ('a * 'b) typ + + let rec to_string: type t. t typ -> t -> string = + fun t x -> + match t with + | Int -> string_of_int x + | String -> Printf.sprintf "%S" x + | Pair(t1,t2) -> + let (x1, x2) = x in + Printf.sprintf "(%s,%s)" (to_string t1 x1) (to_string t2 x2) + + type (_,_) eq = Eq : ('a,'a) eq + + let cast : type a b. (a,b) eq -> a -> b = fun Eq x -> x + + let rec eq_type : type a b. a typ -> b typ -> (a,b) eq option = + fun a b -> + match a, b with + | Int, Int -> Some Eq + | String, String -> Some Eq + | Pair(a1,a2), Pair(b1,b2) -> + begin match eq_type a1 b1, eq_type a2 b2 with + | Some Eq, Some Eq -> Some Eq + | _ -> None + end + | _ -> None + + type dyn = Dyn : 'a typ * 'a -> dyn + + let get_dyn : type a. a typ -> dyn -> a option = + fun a (Dyn(b,x)) -> + match eq_type a b with + | None -> None + | Some Eq -> Some x + + let _ = + let f: type a. a list -> int = + fun _x -> 42 + in + f [] + + let nth t n = + if n < 0 then None else + let rec nth_aux: type b. ('a, b) t -> int -> 'a option = fun t n -> + match t with + | Empty -> None + | Node (a, t) -> if n = 0 then Some a else nth_aux t (n-1) + in + nth_aux t n + + let rec f : type a b. a = function + | _ -> assert false + and g : type a. a = function + | _ -> assert false diff --git a/tests/passing/ifand.ml b/tests/passing/ifand.ml deleted file mode 100644 index b32f05df..00000000 --- a/tests/passing/ifand.ml +++ /dev/null @@ -1,13 +0,0 @@ -let _ = - if cond1 - && cond2 - then _ - -let _ = function - | _ when x = 2 - && y = 3 -> - begin if a = b - || b = c - && c = d then - _ - end diff --git a/tests/passing/ifand.t b/tests/passing/ifand.t new file mode 100644 index 00000000..3b7268fa --- /dev/null +++ b/tests/passing/ifand.t @@ -0,0 +1,31 @@ + + $ cat > ifand.ml << "EOF" + > let _ = + > if cond1 + > && cond2 + > then _ + > + > let _ = function + > | _ when x = 2 + > && y = 3 -> + > begin if a = b + > || b = c + > && c = d then + > _ + > end + > EOF + + $ ocp-indent ifand.ml + let _ = + if cond1 + && cond2 + then _ + + let _ = function + | _ when x = 2 + && y = 3 -> + begin if a = b + || b = c + && c = d then + _ + end diff --git a/tests/passing/indent-empty-1.ml b/tests/passing/indent-empty-1.ml deleted file mode 100644 index c148e028..00000000 --- a/tests/passing/indent-empty-1.ml +++ /dev/null @@ -1,9 +0,0 @@ -module M = struct - - let f = - -end - -let g = - - fun x -> 3 + 4 * diff --git a/tests/passing/indent-empty-1.ml.opts b/tests/passing/indent-empty-1.ml.opts deleted file mode 100644 index 714e4702..00000000 --- a/tests/passing/indent-empty-1.ml.opts +++ /dev/null @@ -1 +0,0 @@ ---lines 4 --numeric diff --git a/tests/passing/indent-empty-1.ml.ref b/tests/passing/indent-empty-1.ml.ref deleted file mode 100644 index b8626c4c..00000000 --- a/tests/passing/indent-empty-1.ml.ref +++ /dev/null @@ -1 +0,0 @@ -4 diff --git a/tests/passing/indent-empty-1.t b/tests/passing/indent-empty-1.t new file mode 100644 index 00000000..b9ee3853 --- /dev/null +++ b/tests/passing/indent-empty-1.t @@ -0,0 +1,15 @@ + + $ cat > indent-empty-1.ml << "EOF" + > module M = struct + > + > let f = + > + > end + > + > let g = + > + > fun x -> 3 + 4 * + > EOF + + $ ocp-indent --lines 4 --numeric indent-empty-1.ml + 4 diff --git a/tests/passing/indent-empty-nm.ml b/tests/passing/indent-empty-nm.ml deleted file mode 100644 index c148e028..00000000 --- a/tests/passing/indent-empty-nm.ml +++ /dev/null @@ -1,9 +0,0 @@ -module M = struct - - let f = - -end - -let g = - - fun x -> 3 + 4 * diff --git a/tests/passing/indent-empty-nm.ml.opts b/tests/passing/indent-empty-nm.ml.opts deleted file mode 100644 index 5e6bffdf..00000000 --- a/tests/passing/indent-empty-nm.ml.opts +++ /dev/null @@ -1 +0,0 @@ ---indent-empty --numeric diff --git a/tests/passing/indent-empty-nm.ml.ref b/tests/passing/indent-empty-nm.ml.ref deleted file mode 100644 index 5562b731..00000000 --- a/tests/passing/indent-empty-nm.ml.ref +++ /dev/null @@ -1,10 +0,0 @@ -0 -2 -2 -4 -0 -0 -0 -2 -2 -15 diff --git a/tests/passing/indent-empty-nm.t b/tests/passing/indent-empty-nm.t new file mode 100644 index 00000000..afeb60ac --- /dev/null +++ b/tests/passing/indent-empty-nm.t @@ -0,0 +1,24 @@ + + $ cat > indent-empty-nm.ml << "EOF" + > module M = struct + > + > let f = + > + > end + > + > let g = + > + > fun x -> 3 + 4 * + > EOF + + $ ocp-indent --indent-empty --numeric indent-empty-nm.ml + 0 + 2 + 2 + 4 + 0 + 0 + 0 + 2 + 2 + 15 diff --git a/tests/passing/indent-empty.ml b/tests/passing/indent-empty.ml deleted file mode 100644 index c148e028..00000000 --- a/tests/passing/indent-empty.ml +++ /dev/null @@ -1,9 +0,0 @@ -module M = struct - - let f = - -end - -let g = - - fun x -> 3 + 4 * diff --git a/tests/passing/indent-empty.ml.opts b/tests/passing/indent-empty.ml.opts deleted file mode 100644 index 2a040da9..00000000 --- a/tests/passing/indent-empty.ml.opts +++ /dev/null @@ -1 +0,0 @@ ---indent-empty diff --git a/tests/passing/indent-empty.ml.ref b/tests/passing/indent-empty.ml.ref deleted file mode 100644 index cdaba330..00000000 --- a/tests/passing/indent-empty.ml.ref +++ /dev/null @@ -1,10 +0,0 @@ -module M = struct - - let f = - -end - -let g = - - fun x -> 3 + 4 * - \ No newline at end of file diff --git a/tests/passing/indent-empty.t b/tests/passing/indent-empty.t new file mode 100644 index 00000000..0cb88803 --- /dev/null +++ b/tests/passing/indent-empty.t @@ -0,0 +1,24 @@ + + $ cat > indent-empty.ml << "EOF" + > module M = struct + > + > let f = + > + > end + > + > let g = + > + > fun x -> 3 + 4 * + > EOF + + $ ocp-indent --indent-empty indent-empty.ml + module M = struct + + let f = + + end + + let g = + + fun x -> 3 + 4 * + diff --git a/tests/passing/js-2018.ml b/tests/passing/js-2018.ml deleted file mode 100644 index a802dfee..00000000 --- a/tests/passing/js-2018.ml +++ /dev/null @@ -1,104 +0,0 @@ -(* New issues reported as of 2018 *) - -(* include.ml *) - -module M : sig - include module type of struct - include I - end - - val f : unit -> unit -end - -(* record.ml *) -let _ = - { a_field : int = - 3 - ; another_field : int = - 3 - } - -let _ = - { a_field = - 3 - ; another_field = - 3 - } - -(* polyvariant.mli *) -module type S = sig - val a : - something:int - -> non_optional: - int list - list - list - -> ?optional: - int - -> int -end - -module type S = sig - val a - : something:int - -> non_optional: - [ `A - | `B - ] - -> ?optional: - [ `A - | `B - ] - -> int -end - -(* type_annot_ext.ml *) -let x = - let v : [%ext : int] = w in - "hello" - -let f a = - match (a : Nothing.t) with - | _ -> . - -let g () = - 1 - -;; - -(* let_module_functor_application.ml *) -let module X = Make (struct - let i = 10 - end) - -(* gadts.ml *) -type 'a t = - | Foo : - int list list list list - * string list - * float list - * bool list - * 'a option list list - -> 'a option list list t - -(* inline_record_indentation.ml *) -type t = - | Clause of { - field : ty; - } - | Clause of { - field : ty; - } - | Clause of { - field : ty; - } - -(* constraint.ml *) -type 'a t = 'b constraint 'a = < foo : 'b > - -let x = 8 - -(* custom_delim_in_comments.ml *) -(* some comment {|"|} *) -let f x = x -(* {|"|} *) diff --git a/tests/passing/js-2018.ml.opts b/tests/passing/js-2018.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-2018.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-2018.t b/tests/passing/js-2018.t new file mode 100644 index 00000000..b2d50eaa --- /dev/null +++ b/tests/passing/js-2018.t @@ -0,0 +1,213 @@ + + $ cat > js-2018.ml << "EOF" + > (* New issues reported as of 2018 *) + > + > (* include.ml *) + > + > module M : sig + > include module type of struct + > include I + > end + > + > val f : unit -> unit + > end + > + > (* record.ml *) + > let _ = + > { a_field : int = + > 3 + > ; another_field : int = + > 3 + > } + > + > let _ = + > { a_field = + > 3 + > ; another_field = + > 3 + > } + > + > (* polyvariant.mli *) + > module type S = sig + > val a : + > something:int + > -> non_optional: + > int list + > list + > list + > -> ?optional: + > int + > -> int + > end + > + > module type S = sig + > val a + > : something:int + > -> non_optional: + > [ `A + > | `B + > ] + > -> ?optional: + > [ `A + > | `B + > ] + > -> int + > end + > + > (* type_annot_ext.ml *) + > let x = + > let v : [%ext : int] = w in + > "hello" + > + > let f a = + > match (a : Nothing.t) with + > | _ -> . + > + > let g () = + > 1 + > + > ;; + > + > (* let_module_functor_application.ml *) + > let module X = Make (struct + > let i = 10 + > end) + > + > (* gadts.ml *) + > type 'a t = + > | Foo : + > int list list list list + > * string list + > * float list + > * bool list + > * 'a option list list + > -> 'a option list list t + > + > (* inline_record_indentation.ml *) + > type t = + > | Clause of { + > field : ty; + > } + > | Clause of { + > field : ty; + > } + > | Clause of { + > field : ty; + > } + > + > (* constraint.ml *) + > type 'a t = 'b constraint 'a = < foo : 'b > + > + > let x = 8 + > + > (* custom_delim_in_comments.ml *) + > (* some comment {|"|} *) + > let f x = x + > (* {|"|} *) + > EOF + + $ ocp-indent -c JaneStreet js-2018.ml + (* New issues reported as of 2018 *) + + (* include.ml *) + + module M : sig + include module type of struct + include I + end + + val f : unit -> unit + end + + (* record.ml *) + let _ = + { a_field : int = + 3 + ; another_field : int = + 3 + } + + let _ = + { a_field = + 3 + ; another_field = + 3 + } + + (* polyvariant.mli *) + module type S = sig + val a : + something:int + -> non_optional: + int list + list + list + -> ?optional: + int + -> int + end + + module type S = sig + val a + : something:int + -> non_optional: + [ `A + | `B + ] + -> ?optional: + [ `A + | `B + ] + -> int + end + + (* type_annot_ext.ml *) + let x = + let v : [%ext : int] = w in + "hello" + + let f a = + match (a : Nothing.t) with + | _ -> . + + let g () = + 1 + + ;; + + (* let_module_functor_application.ml *) + let module X = Make (struct + let i = 10 + end) + + (* gadts.ml *) + type 'a t = + | Foo : + int list list list list + * string list + * float list + * bool list + * 'a option list list + -> 'a option list list t + + (* inline_record_indentation.ml *) + type t = + | Clause of { + field : ty; + } + | Clause of { + field : ty; + } + | Clause of { + field : ty; + } + + (* constraint.ml *) + type 'a t = 'b constraint 'a = < foo : 'b > + + let x = 8 + + (* custom_delim_in_comments.ml *) + (* some comment {|"|} *) + let f x = x + (* {|"|} *) diff --git a/tests/passing/js-and.ml b/tests/passing/js-and.ml deleted file mode 100644 index c171318e..00000000 --- a/tests/passing/js-and.ml +++ /dev/null @@ -1,4 +0,0 @@ -module M : S with type a = b - and type c = d - and type e = f -;; diff --git a/tests/passing/js-and.ml.opts b/tests/passing/js-and.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-and.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-and.t b/tests/passing/js-and.t new file mode 100644 index 00000000..008f67f7 --- /dev/null +++ b/tests/passing/js-and.t @@ -0,0 +1,13 @@ + + $ cat > js-and.ml << "EOF" + > module M : S with type a = b + > and type c = d + > and type e = f + > ;; + > EOF + + $ ocp-indent -c JaneStreet js-and.ml + module M : S with type a = b + and type c = d + and type e = f + ;; diff --git a/tests/passing/js-andand.ml b/tests/passing/js-andand.ml deleted file mode 100644 index 0db9bbd4..00000000 --- a/tests/passing/js-andand.ml +++ /dev/null @@ -1,12 +0,0 @@ -let all_equal = - a = b - && c = d - && e = f (* this && should line up with previous one *) -;; - -(* '=' seems to be relevant here *) -let _ = - x - && t.entity = entity - && t.clearing_firm = clearing_firm - && t.type_ = type_ diff --git a/tests/passing/js-andand.ml.opts b/tests/passing/js-andand.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-andand.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-andand.t b/tests/passing/js-andand.t new file mode 100644 index 00000000..2fc5dcee --- /dev/null +++ b/tests/passing/js-andand.t @@ -0,0 +1,29 @@ + + $ cat > js-andand.ml << "EOF" + > let all_equal = + > a = b + > && c = d + > && e = f (* this && should line up with previous one *) + > ;; + > + > (* '=' seems to be relevant here *) + > let _ = + > x + > && t.entity = entity + > && t.clearing_firm = clearing_firm + > && t.type_ = type_ + > EOF + + $ ocp-indent -c JaneStreet js-andand.ml + let all_equal = + a = b + && c = d + && e = f (* this && should line up with previous one *) + ;; + + (* '=' seems to be relevant here *) + let _ = + x + && t.entity = entity + && t.clearing_firm = clearing_firm + && t.type_ = type_ diff --git a/tests/passing/js-applicative.ml b/tests/passing/js-applicative.ml deleted file mode 100644 index 1b97a8e2..00000000 --- a/tests/passing/js-applicative.ml +++ /dev/null @@ -1,12 +0,0 @@ -(* applicative_intf.ml *) - -let args = - bar "A" - @> baz "B" - @> nil - -let args = - bar "A" - @> baz_qux - @@ zap "D" - @> nil diff --git a/tests/passing/js-applicative.ml.opts b/tests/passing/js-applicative.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-applicative.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-applicative.t b/tests/passing/js-applicative.t new file mode 100644 index 00000000..3531dd5f --- /dev/null +++ b/tests/passing/js-applicative.t @@ -0,0 +1,29 @@ + + $ cat > js-applicative.ml << "EOF" + > (* applicative_intf.ml *) + > + > let args = + > bar "A" + > @> baz "B" + > @> nil + > + > let args = + > bar "A" + > @> baz_qux + > @@ zap "D" + > @> nil + > EOF + + $ ocp-indent -c JaneStreet js-applicative.ml + (* applicative_intf.ml *) + + let args = + bar "A" + @> baz "B" + @> nil + + let args = + bar "A" + @> baz_qux + @@ zap "D" + @> nil diff --git a/tests/passing/js-bench.ml b/tests/passing/js-bench.ml deleted file mode 100644 index 2f9c67f7..00000000 --- a/tests/passing/js-bench.ml +++ /dev/null @@ -1,39 +0,0 @@ -BENCH_FUN "Array.get (tuple)" = - (* This is mis-indented only when BENCH_FUN is on the first line. *) - let len = 300 in - let arr = create ~len (1,2) in - (fun () -> ignore(arr.(len-1))) - -BENCH_FUN "Array.set (tuple)" = - let len = 300 in - let arr = create ~len (1,2) in - (fun () -> arr.(len-1) <- (3,4)) - -(* Some benchmarks of the blit operations *) -BENCH_MODULE "Blit tests" = struct - let lengths = [0; 10; 100; 1000; 10_000] - - BENCH_MODULE "Int" = struct - BENCH_INDEXED "blit" len lengths = - let src = create ~len 0 in - let dst = create ~len 0 in - (fun () -> Int.blit ~src ~src_pos:0 ~dst ~dst_pos:0 ~len) - - BENCH_INDEXED "blito" len lengths = - let src = create ~len 0 in - let dst = create ~len 0 in - (fun () -> Int.blito ~src ~src_pos:0 ~dst ~dst_pos:0 ~src_len:len ()) - end - - BENCH_MODULE "Float" = struct - BENCH_INDEXED "blit" len lengths = - let src = create ~len 0.0 in - let dst = create ~len 0.0 in - (fun () -> Float.blit ~src ~src_pos:0 ~dst ~dst_pos:0 ~len) - - BENCH_INDEXED "blito" len lengths = - let src = create ~len 0.0 in - let dst = create ~len 0.0 in - (fun () -> Float.blito ~src ~src_pos:0 ~dst ~dst_pos:0 ~src_len:len ()) - end -end diff --git a/tests/passing/js-bench.ml.opts b/tests/passing/js-bench.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-bench.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-bench.t b/tests/passing/js-bench.t new file mode 100644 index 00000000..96ee61cb --- /dev/null +++ b/tests/passing/js-bench.t @@ -0,0 +1,83 @@ + + $ cat > js-bench.ml << "EOF" + > BENCH_FUN "Array.get (tuple)" = + > (* This is mis-indented only when BENCH_FUN is on the first line. *) + > let len = 300 in + > let arr = create ~len (1,2) in + > (fun () -> ignore(arr.(len-1))) + > + > BENCH_FUN "Array.set (tuple)" = + > let len = 300 in + > let arr = create ~len (1,2) in + > (fun () -> arr.(len-1) <- (3,4)) + > + > (* Some benchmarks of the blit operations *) + > BENCH_MODULE "Blit tests" = struct + > let lengths = [0; 10; 100; 1000; 10_000] + > + > BENCH_MODULE "Int" = struct + > BENCH_INDEXED "blit" len lengths = + > let src = create ~len 0 in + > let dst = create ~len 0 in + > (fun () -> Int.blit ~src ~src_pos:0 ~dst ~dst_pos:0 ~len) + > + > BENCH_INDEXED "blito" len lengths = + > let src = create ~len 0 in + > let dst = create ~len 0 in + > (fun () -> Int.blito ~src ~src_pos:0 ~dst ~dst_pos:0 ~src_len:len ()) + > end + > + > BENCH_MODULE "Float" = struct + > BENCH_INDEXED "blit" len lengths = + > let src = create ~len 0.0 in + > let dst = create ~len 0.0 in + > (fun () -> Float.blit ~src ~src_pos:0 ~dst ~dst_pos:0 ~len) + > + > BENCH_INDEXED "blito" len lengths = + > let src = create ~len 0.0 in + > let dst = create ~len 0.0 in + > (fun () -> Float.blito ~src ~src_pos:0 ~dst ~dst_pos:0 ~src_len:len ()) + > end + > end + > EOF + + $ ocp-indent -c JaneStreet js-bench.ml + BENCH_FUN "Array.get (tuple)" = + (* This is mis-indented only when BENCH_FUN is on the first line. *) + let len = 300 in + let arr = create ~len (1,2) in + (fun () -> ignore(arr.(len-1))) + + BENCH_FUN "Array.set (tuple)" = + let len = 300 in + let arr = create ~len (1,2) in + (fun () -> arr.(len-1) <- (3,4)) + + (* Some benchmarks of the blit operations *) + BENCH_MODULE "Blit tests" = struct + let lengths = [0; 10; 100; 1000; 10_000] + + BENCH_MODULE "Int" = struct + BENCH_INDEXED "blit" len lengths = + let src = create ~len 0 in + let dst = create ~len 0 in + (fun () -> Int.blit ~src ~src_pos:0 ~dst ~dst_pos:0 ~len) + + BENCH_INDEXED "blito" len lengths = + let src = create ~len 0 in + let dst = create ~len 0 in + (fun () -> Int.blito ~src ~src_pos:0 ~dst ~dst_pos:0 ~src_len:len ()) + end + + BENCH_MODULE "Float" = struct + BENCH_INDEXED "blit" len lengths = + let src = create ~len 0.0 in + let dst = create ~len 0.0 in + (fun () -> Float.blit ~src ~src_pos:0 ~dst ~dst_pos:0 ~len) + + BENCH_INDEXED "blito" len lengths = + let src = create ~len 0.0 in + let dst = create ~len 0.0 in + (fun () -> Float.blito ~src ~src_pos:0 ~dst ~dst_pos:0 ~src_len:len ()) + end + end diff --git a/tests/passing/js-bind.ml b/tests/passing/js-bind.ml deleted file mode 100644 index 34bfd0d7..00000000 --- a/tests/passing/js-bind.ml +++ /dev/null @@ -1,27 +0,0 @@ -let assigned_to u = - Deferred.List.filter (Request_util.requests ()) ~f:(fun request -> - if _ - then _ - else - status_request ~request () ~msg_client:no_msg >>= fun status -> - not (up_to_date_user status u)) - - - -let old_good = - foo bar qaz *>>= fun x -> - hey ho lala *>>= fun y -> - return (x,y) - -let old_good = - foo bar qaz +>>= fun x -> - hey ho lala +>>= fun y -> - return (x,y) - -(* generalizations based on Tuareg code *) -let old_good = - foo bar qaz *>>| fun x -> - hey ho lala *>>> fun y -> - foo bar qaz +>>| fun x -> - hey ho lala +>>> fun y -> - return (x,y) diff --git a/tests/passing/js-bind.ml.opts b/tests/passing/js-bind.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-bind.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-bind.t b/tests/passing/js-bind.t new file mode 100644 index 00000000..8a2bb9c8 --- /dev/null +++ b/tests/passing/js-bind.t @@ -0,0 +1,59 @@ + + $ cat > js-bind.ml << "EOF" + > let assigned_to u = + > Deferred.List.filter (Request_util.requests ()) ~f:(fun request -> + > if _ + > then _ + > else + > status_request ~request () ~msg_client:no_msg >>= fun status -> + > not (up_to_date_user status u)) + > + > + > + > let old_good = + > foo bar qaz *>>= fun x -> + > hey ho lala *>>= fun y -> + > return (x,y) + > + > let old_good = + > foo bar qaz +>>= fun x -> + > hey ho lala +>>= fun y -> + > return (x,y) + > + > (* generalizations based on Tuareg code *) + > let old_good = + > foo bar qaz *>>| fun x -> + > hey ho lala *>>> fun y -> + > foo bar qaz +>>| fun x -> + > hey ho lala +>>> fun y -> + > return (x,y) + > EOF + + $ ocp-indent -c JaneStreet js-bind.ml + let assigned_to u = + Deferred.List.filter (Request_util.requests ()) ~f:(fun request -> + if _ + then _ + else + status_request ~request () ~msg_client:no_msg >>= fun status -> + not (up_to_date_user status u)) + + + + let old_good = + foo bar qaz *>>= fun x -> + hey ho lala *>>= fun y -> + return (x,y) + + let old_good = + foo bar qaz +>>= fun x -> + hey ho lala +>>= fun y -> + return (x,y) + + (* generalizations based on Tuareg code *) + let old_good = + foo bar qaz *>>| fun x -> + hey ho lala *>>> fun y -> + foo bar qaz +>>| fun x -> + hey ho lala +>>> fun y -> + return (x,y) diff --git a/tests/passing/js-comment.ml b/tests/passing/js-comment.ml deleted file mode 100644 index 6aa9a1e1..00000000 --- a/tests/passing/js-comment.ml +++ /dev/null @@ -1,182 +0,0 @@ -(* ocp-indent is not going to be confused by comment-embedded tokens. *) - - - -type t = { - (* This is a comment *) - a: int; -} - -type t = { - (* This is a comment : with a colon. *) - a: int; -} - -type t = { - a: int; - (* with the : second field *) - b: int; -} - -type t = { - a: int; - b: int; - (* and : the third... *) - c: int; -} - - - -(* colon in CR comment messes Tuareg up *) -type cfg = { - foo : int; (* ignore-CR someone: float? *) - bar : string; -} - -(* To be more precise about the Tuareg bug, it is the fact that the colon in the comment -is the first or second colon after the start of the record definition. If the comment -occurs after the first 2 fields in the record everything is fine. - -For example, this is OK: *) -type t= { - foo : int; - bar : string; (* ignore-CR someone: float? *) - baz : string; -} - -(* but Tuareg messes this up *) -type t= { - foo : int; - (* ignore-CR someone: float? *) - bar : string; -} - - - -(* Now that we have support for {v v} and {[ ]}, reindent inside comments, - unless they are explicitly delimited as code or pre-formatted text. These - three all end up flattened to the same level. *) -(* -type t = { - (* This is a comment *) - a: int; -} -*) -(* - type t = { - (* This is a comment *) - a: int; - } -*) -(* - type t = { - (* This is a comment *) - a: int; - } -*) - - - -(* Possible to-do warning: Star-prefixed lines are allowed and indented a little - less, to line up with the star in the opening comment parenthesis. Maybe we - don't care enough about them to worry about it, though. *) - - - -(** Doc comment text should be aligned with the first line, so indented more -than otherwise. *) - -(* We're now using some ocamldoc block syntax to control indentation, and sweeks -and the rest of us have been relying on it, in and out of doc comments. - -{[ -let code = -should be reindented like code -so as to work also with vim -]} - - {v g - This is totally verbatim text and shouldn't be reindented. It - probably doesn't matter what the indentation of the first line of a -verbatim block is. But how will this be done in vim? - xx - yy - zz - c v} - -Does this even confront ocp-indent? I think, when reindenting whole files, -source code blocks do confront ocp-indent. -*) - - - -(* {v - -(* comments embedded in verbatim sections *) -(* want to be able to verbatim-out big chunks of code *) - -v} *) - - - -(* {v - -non-comments in verbatim sections -duh - -v} *) - - - -module M = struct - let x = 0 - - (* reference *) -end - -module M = struct - let () = - () - - (* If there's a blank line before this, at least, shouldn't it revert to the - block-level indentation, even if it doesn't precede a declaration? As - long as the prior declaration is complete, I mean. If there isn't a - blank line, I can see associating the comment with the line before. *) -end - -module M = struct - let () = () - - (* sim. *) -end - -module M = struct - let () = - () - - (* no problem *) - let () = - () -end - - - -val f : foo : int -> - -> bar_snoo : a b - (* this comment is in the wrong place *) - -> unit - -val f : foo : int -> - -> bar_snoo : a - (* this comment is in the right place [under discussion] *) - -> unit - -(* The only difference is the type "a b" instead of "a" for the labeled value - bar_snoo. *) - - - -module M : sig - val v : 'a t -> s -> 'a t - (* ... *) -end diff --git a/tests/passing/js-comment.ml.opts b/tests/passing/js-comment.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-comment.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-comment.ml.ref b/tests/passing/js-comment.ml.ref deleted file mode 100644 index 424aad55..00000000 --- a/tests/passing/js-comment.ml.ref +++ /dev/null @@ -1,182 +0,0 @@ -(* ocp-indent is not going to be confused by comment-embedded tokens. *) - - - -type t = { - (* This is a comment *) - a: int; -} - -type t = { - (* This is a comment : with a colon. *) - a: int; -} - -type t = { - a: int; - (* with the : second field *) - b: int; -} - -type t = { - a: int; - b: int; - (* and : the third... *) - c: int; -} - - - -(* colon in CR comment messes Tuareg up *) -type cfg = { - foo : int; (* ignore-CR someone: float? *) - bar : string; -} - -(* To be more precise about the Tuareg bug, it is the fact that the colon in the comment - is the first or second colon after the start of the record definition. If the comment - occurs after the first 2 fields in the record everything is fine. - - For example, this is OK: *) -type t= { - foo : int; - bar : string; (* ignore-CR someone: float? *) - baz : string; -} - -(* but Tuareg messes this up *) -type t= { - foo : int; - (* ignore-CR someone: float? *) - bar : string; -} - - - -(* Now that we have support for {v v} and {[ ]}, reindent inside comments, - unless they are explicitly delimited as code or pre-formatted text. These - three all end up flattened to the same level. *) -(* - type t = { - (* This is a comment *) - a: int; - } -*) -(* - type t = { - (* This is a comment *) - a: int; - } -*) -(* - type t = { - (* This is a comment *) - a: int; - } -*) - - - -(* Possible to-do warning: Star-prefixed lines are allowed and indented a little - less, to line up with the star in the opening comment parenthesis. Maybe we - don't care enough about them to worry about it, though. *) - - - -(** Doc comment text should be aligned with the first line, so indented more - than otherwise. *) - -(* We're now using some ocamldoc block syntax to control indentation, and sweeks - and the rest of us have been relying on it, in and out of doc comments. - - {[ - let code = - should be reindented like code - so as to work also with vim - ]} - - {v g - This is totally verbatim text and shouldn't be reindented. It - probably doesn't matter what the indentation of the first line of a -verbatim block is. But how will this be done in vim? - xx - yy - zz - c v} - - Does this even confront ocp-indent? I think, when reindenting whole files, - source code blocks do confront ocp-indent. -*) - - - -(* {v - -(* comments embedded in verbatim sections *) -(* want to be able to verbatim-out big chunks of code *) - -v} *) - - - -(* {v - -non-comments in verbatim sections -duh - -v} *) - - - -module M = struct - let x = 0 - - (* reference *) -end - -module M = struct - let () = - () - - (* If there's a blank line before this, at least, shouldn't it revert to the - block-level indentation, even if it doesn't precede a declaration? As - long as the prior declaration is complete, I mean. If there isn't a - blank line, I can see associating the comment with the line before. *) -end - -module M = struct - let () = () - - (* sim. *) -end - -module M = struct - let () = - () - - (* no problem *) - let () = - () -end - - - -val f : foo : int -> - -> bar_snoo : a b - (* this comment is in the wrong place *) - -> unit - -val f : foo : int -> - -> bar_snoo : a - (* this comment is in the right place [under discussion] *) - -> unit - -(* The only difference is the type "a b" instead of "a" for the labeled value - bar_snoo. *) - - - -module M : sig - val v : 'a t -> s -> 'a t - (* ... *) -end diff --git a/tests/passing/js-comment.t b/tests/passing/js-comment.t new file mode 100644 index 00000000..7e58cf79 --- /dev/null +++ b/tests/passing/js-comment.t @@ -0,0 +1,369 @@ + + $ cat > js-comment.ml << "EOF" + > (* ocp-indent is not going to be confused by comment-embedded tokens. *) + > + > + > + > type t = { + > (* This is a comment *) + > a: int; + > } + > + > type t = { + > (* This is a comment : with a colon. *) + > a: int; + > } + > + > type t = { + > a: int; + > (* with the : second field *) + > b: int; + > } + > + > type t = { + > a: int; + > b: int; + > (* and : the third... *) + > c: int; + > } + > + > + > + > (* colon in CR comment messes Tuareg up *) + > type cfg = { + > foo : int; (* ignore-CR someone: float? *) + > bar : string; + > } + > + > (* To be more precise about the Tuareg bug, it is the fact that the colon in the comment + > is the first or second colon after the start of the record definition. If the comment + > occurs after the first 2 fields in the record everything is fine. + > + > For example, this is OK: *) + > type t= { + > foo : int; + > bar : string; (* ignore-CR someone: float? *) + > baz : string; + > } + > + > (* but Tuareg messes this up *) + > type t= { + > foo : int; + > (* ignore-CR someone: float? *) + > bar : string; + > } + > + > + > + > (* Now that we have support for {v v} and {[ ]}, reindent inside comments, + > unless they are explicitly delimited as code or pre-formatted text. These + > three all end up flattened to the same level. *) + > (* + > type t = { + > (* This is a comment *) + > a: int; + > } + > *) + > (* + > type t = { + > (* This is a comment *) + > a: int; + > } + > *) + > (* + > type t = { + > (* This is a comment *) + > a: int; + > } + > *) + > + > + > + > (* Possible to-do warning: Star-prefixed lines are allowed and indented a little + > less, to line up with the star in the opening comment parenthesis. Maybe we + > don't care enough about them to worry about it, though. *) + > + > + > + > (** Doc comment text should be aligned with the first line, so indented more + > than otherwise. *) + > + > (* We're now using some ocamldoc block syntax to control indentation, and sweeks + > and the rest of us have been relying on it, in and out of doc comments. + > + > {[ + > let code = + > should be reindented like code + > so as to work also with vim + > ]} + > + > {v g + > This is totally verbatim text and shouldn't be reindented. It + > probably doesn't matter what the indentation of the first line of a + > verbatim block is. But how will this be done in vim? + > xx + > yy + > zz + > c v} + > + > Does this even confront ocp-indent? I think, when reindenting whole files, + > source code blocks do confront ocp-indent. + > *) + > + > + > + > (* {v + > + > (* comments embedded in verbatim sections *) + > (* want to be able to verbatim-out big chunks of code *) + > + > v} *) + > + > + > + > (* {v + > + > non-comments in verbatim sections + > duh + > + > v} *) + > + > + > + > module M = struct + > let x = 0 + > + > (* reference *) + > end + > + > module M = struct + > let () = + > () + > + > (* If there's a blank line before this, at least, shouldn't it revert to the + > block-level indentation, even if it doesn't precede a declaration? As + > long as the prior declaration is complete, I mean. If there isn't a + > blank line, I can see associating the comment with the line before. *) + > end + > + > module M = struct + > let () = () + > + > (* sim. *) + > end + > + > module M = struct + > let () = + > () + > + > (* no problem *) + > let () = + > () + > end + > + > + > + > val f : foo : int -> + > -> bar_snoo : a b + > (* this comment is in the wrong place *) + > -> unit + > + > val f : foo : int -> + > -> bar_snoo : a + > (* this comment is in the right place [under discussion] *) + > -> unit + > + > (* The only difference is the type "a b" instead of "a" for the labeled value + > bar_snoo. *) + > + > + > + > module M : sig + > val v : 'a t -> s -> 'a t + > (* ... *) + > end + > EOF + + $ ocp-indent -c JaneStreet js-comment.ml + (* ocp-indent is not going to be confused by comment-embedded tokens. *) + + + + type t = { + (* This is a comment *) + a: int; + } + + type t = { + (* This is a comment : with a colon. *) + a: int; + } + + type t = { + a: int; + (* with the : second field *) + b: int; + } + + type t = { + a: int; + b: int; + (* and : the third... *) + c: int; + } + + + + (* colon in CR comment messes Tuareg up *) + type cfg = { + foo : int; (* ignore-CR someone: float? *) + bar : string; + } + + (* To be more precise about the Tuareg bug, it is the fact that the colon in the comment + is the first or second colon after the start of the record definition. If the comment + occurs after the first 2 fields in the record everything is fine. + + For example, this is OK: *) + type t= { + foo : int; + bar : string; (* ignore-CR someone: float? *) + baz : string; + } + + (* but Tuareg messes this up *) + type t= { + foo : int; + (* ignore-CR someone: float? *) + bar : string; + } + + + + (* Now that we have support for {v v} and {[ ]}, reindent inside comments, + unless they are explicitly delimited as code or pre-formatted text. These + three all end up flattened to the same level. *) + (* + type t = { + (* This is a comment *) + a: int; + } + *) + (* + type t = { + (* This is a comment *) + a: int; + } + *) + (* + type t = { + (* This is a comment *) + a: int; + } + *) + + + + (* Possible to-do warning: Star-prefixed lines are allowed and indented a little + less, to line up with the star in the opening comment parenthesis. Maybe we + don't care enough about them to worry about it, though. *) + + + + (** Doc comment text should be aligned with the first line, so indented more + than otherwise. *) + + (* We're now using some ocamldoc block syntax to control indentation, and sweeks + and the rest of us have been relying on it, in and out of doc comments. + + {[ + let code = + should be reindented like code + so as to work also with vim + ]} + + {v g + This is totally verbatim text and shouldn't be reindented. It + probably doesn't matter what the indentation of the first line of a + verbatim block is. But how will this be done in vim? + xx + yy + zz + c v} + + Does this even confront ocp-indent? I think, when reindenting whole files, + source code blocks do confront ocp-indent. + *) + + + + (* {v + + (* comments embedded in verbatim sections *) + (* want to be able to verbatim-out big chunks of code *) + + v} *) + + + + (* {v + + non-comments in verbatim sections + duh + + v} *) + + + + module M = struct + let x = 0 + + (* reference *) + end + + module M = struct + let () = + () + + (* If there's a blank line before this, at least, shouldn't it revert to the + block-level indentation, even if it doesn't precede a declaration? As + long as the prior declaration is complete, I mean. If there isn't a + blank line, I can see associating the comment with the line before. *) + end + + module M = struct + let () = () + + (* sim. *) + end + + module M = struct + let () = + () + + (* no problem *) + let () = + () + end + + + + val f : foo : int -> + -> bar_snoo : a b + (* this comment is in the wrong place *) + -> unit + + val f : foo : int -> + -> bar_snoo : a + (* this comment is in the right place [under discussion] *) + -> unit + + (* The only difference is the type "a b" instead of "a" for the labeled value + bar_snoo. *) + + + + module M : sig + val v : 'a t -> s -> 'a t + (* ... *) + end diff --git a/tests/passing/js-comment1.ml b/tests/passing/js-comment1.ml deleted file mode 100644 index be94b245..00000000 --- a/tests/passing/js-comment1.ml +++ /dev/null @@ -1,91 +0,0 @@ -type foo = int (* just in case *) - - - -(* These two shouldn't be indented differently, but are. *) - -type z = - [ `Bar of foo - (* a comment [expected to apply to `Foo as below] *) - | `Foo ] - -type z = - [ `Bar - (* a comment *) - | `Foo ] - - - -(* On second thought, I kind of like this way of thinking about this -indentation, even though it is kind of parasyntactic: *) - -type z = - (* Applies to "[" or `Bar. *) - [ `Bar of foo - (* Applies to "|" or `Foo. Indented too much. *) - | `Foo ] - -type z = - (* Applies to "[" or `Bar. *) - [ `Bar - (* Applies to "|" or `Foo. *) - | `Foo ] - -(* The way we write code, that will line up more nicely. *) - - - -let _ = - (foo - (* This is indented too far to the left *) - (bar)) - -(* It looks to me like we generally want the comment to apply to the - following line in most circumstances, including this one. The default indent -for an empty line after a function application that isn't terminated with a - ";" or something would probably also be in a bit, in anticipation of an -argument, although I don't think that's crucial. *) -let _ = - foo quux -(* about bar *) - bar -(* about baz *) - baz - -(** Trying lists within comments: - - this is a - multi-line element of a list. - - and this is a one-liner - - this - has - many - more - lines - - and this is indented like a sub-list - - but isn't one at - -all - - this is outside of the list though. - - - and this is - - another - list - - - and another -one - -the end -*) - -(* There is an issue with toplevel sessions: - # expr1;; - - : type1 = value1 - # expr2;; - - : type2 = value2 - - Comment. *) - -(* Comment: - - - [code]; - - {[ code ]} *) diff --git a/tests/passing/js-comment1.ml.opts b/tests/passing/js-comment1.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-comment1.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-comment1.ml.ref b/tests/passing/js-comment1.ml.ref deleted file mode 100644 index 16184f17..00000000 --- a/tests/passing/js-comment1.ml.ref +++ /dev/null @@ -1,91 +0,0 @@ -type foo = int (* just in case *) - - - -(* These two shouldn't be indented differently, but are. *) - -type z = - [ `Bar of foo - (* a comment [expected to apply to `Foo as below] *) - | `Foo ] - -type z = - [ `Bar - (* a comment *) - | `Foo ] - - - -(* On second thought, I kind of like this way of thinking about this - indentation, even though it is kind of parasyntactic: *) - -type z = - (* Applies to "[" or `Bar. *) - [ `Bar of foo - (* Applies to "|" or `Foo. Indented too much. *) - | `Foo ] - -type z = - (* Applies to "[" or `Bar. *) - [ `Bar - (* Applies to "|" or `Foo. *) - | `Foo ] - -(* The way we write code, that will line up more nicely. *) - - - -let _ = - (foo - (* This is indented too far to the left *) - (bar)) - -(* It looks to me like we generally want the comment to apply to the - following line in most circumstances, including this one. The default indent - for an empty line after a function application that isn't terminated with a - ";" or something would probably also be in a bit, in anticipation of an - argument, although I don't think that's crucial. *) -let _ = - foo quux - (* about bar *) - bar - (* about baz *) - baz - -(** Trying lists within comments: - - this is a - multi-line element of a list. - - and this is a one-liner - - this - has - many - more - lines - - and this is indented like a sub-list - - but isn't one at - -all - - this is outside of the list though. - - - and this is - - another - list - - - and another - one - - the end -*) - -(* There is an issue with toplevel sessions: - # expr1;; - - : type1 = value1 - # expr2;; - - : type2 = value2 - - Comment. *) - -(* Comment: - - - [code]; - - {[ code ]} *) diff --git a/tests/passing/js-comment1.t b/tests/passing/js-comment1.t new file mode 100644 index 00000000..4275a3a4 --- /dev/null +++ b/tests/passing/js-comment1.t @@ -0,0 +1,187 @@ + + $ cat > js-comment1.ml << "EOF" + > type foo = int (* just in case *) + > + > + > + > (* These two shouldn't be indented differently, but are. *) + > + > type z = + > [ `Bar of foo + > (* a comment [expected to apply to `Foo as below] *) + > | `Foo ] + > + > type z = + > [ `Bar + > (* a comment *) + > | `Foo ] + > + > + > + > (* On second thought, I kind of like this way of thinking about this + > indentation, even though it is kind of parasyntactic: *) + > + > type z = + > (* Applies to "[" or `Bar. *) + > [ `Bar of foo + > (* Applies to "|" or `Foo. Indented too much. *) + > | `Foo ] + > + > type z = + > (* Applies to "[" or `Bar. *) + > [ `Bar + > (* Applies to "|" or `Foo. *) + > | `Foo ] + > + > (* The way we write code, that will line up more nicely. *) + > + > + > + > let _ = + > (foo + > (* This is indented too far to the left *) + > (bar)) + > + > (* It looks to me like we generally want the comment to apply to the + > following line in most circumstances, including this one. The default indent + > for an empty line after a function application that isn't terminated with a + > ";" or something would probably also be in a bit, in anticipation of an + > argument, although I don't think that's crucial. *) + > let _ = + > foo quux + > (* about bar *) + > bar + > (* about baz *) + > baz + > + > (** Trying lists within comments: + > - this is a + > multi-line element of a list. + > - and this is a one-liner + > - this + > has + > many + > more + > lines + > - and this is indented like a sub-list + > - but isn't one at + > -all + > + > this is outside of the list though. + > + > - and this is + > - another + > list + > + > - and another + > one + > + > the end + > *) + > + > (* There is an issue with toplevel sessions: + > # expr1;; + > - : type1 = value1 + > # expr2;; + > - : type2 = value2 + > + > Comment. *) + > + > (* Comment: + > + > - [code]; + > - {[ code ]} *) + > EOF + + $ ocp-indent -c JaneStreet js-comment1.ml + type foo = int (* just in case *) + + + + (* These two shouldn't be indented differently, but are. *) + + type z = + [ `Bar of foo + (* a comment [expected to apply to `Foo as below] *) + | `Foo ] + + type z = + [ `Bar + (* a comment *) + | `Foo ] + + + + (* On second thought, I kind of like this way of thinking about this + indentation, even though it is kind of parasyntactic: *) + + type z = + (* Applies to "[" or `Bar. *) + [ `Bar of foo + (* Applies to "|" or `Foo. Indented too much. *) + | `Foo ] + + type z = + (* Applies to "[" or `Bar. *) + [ `Bar + (* Applies to "|" or `Foo. *) + | `Foo ] + + (* The way we write code, that will line up more nicely. *) + + + + let _ = + (foo + (* This is indented too far to the left *) + (bar)) + + (* It looks to me like we generally want the comment to apply to the + following line in most circumstances, including this one. The default indent + for an empty line after a function application that isn't terminated with a + ";" or something would probably also be in a bit, in anticipation of an + argument, although I don't think that's crucial. *) + let _ = + foo quux + (* about bar *) + bar + (* about baz *) + baz + + (** Trying lists within comments: + - this is a + multi-line element of a list. + - and this is a one-liner + - this + has + many + more + lines + - and this is indented like a sub-list + - but isn't one at + -all + + this is outside of the list though. + + - and this is + - another + list + + - and another + one + + the end + *) + + (* There is an issue with toplevel sessions: + # expr1;; + - : type1 = value1 + # expr2;; + - : type2 = value2 + + Comment. *) + + (* Comment: + + - [code]; + - {[ code ]} *) diff --git a/tests/passing/js-default.ml b/tests/passing/js-default.ml deleted file mode 100644 index 4c2a4b26..00000000 --- a/tests/passing/js-default.ml +++ /dev/null @@ -1,15 +0,0 @@ -type t = - { last_trading : Week_date.Spec.t; - first_notice : Week_date.Spec.t option; - first_notice_exceptions : Date.t Year_month.Map.t - with default(Year_month.Map.empty); - offset : Week_date.Offset.t; - (* n > 0 *) - new_contract_expires_in_n_months : int - } -[@@deriving sexp, compare] - -module M = struct - type t = { x: int } - [@@deriving sexp] -end diff --git a/tests/passing/js-default.ml.opts b/tests/passing/js-default.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-default.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-default.t b/tests/passing/js-default.t new file mode 100644 index 00000000..9b562e8f --- /dev/null +++ b/tests/passing/js-default.t @@ -0,0 +1,35 @@ + + $ cat > js-default.ml << "EOF" + > type t = + > { last_trading : Week_date.Spec.t; + > first_notice : Week_date.Spec.t option; + > first_notice_exceptions : Date.t Year_month.Map.t + > with default(Year_month.Map.empty); + > offset : Week_date.Offset.t; + > (* n > 0 *) + > new_contract_expires_in_n_months : int + > } + > [@@deriving sexp, compare] + > + > module M = struct + > type t = { x: int } + > [@@deriving sexp] + > end + > EOF + + $ ocp-indent -c JaneStreet js-default.ml + type t = + { last_trading : Week_date.Spec.t; + first_notice : Week_date.Spec.t option; + first_notice_exceptions : Date.t Year_month.Map.t + with default(Year_month.Map.empty); + offset : Week_date.Offset.t; + (* n > 0 *) + new_contract_expires_in_n_months : int + } + [@@deriving sexp, compare] + + module M = struct + type t = { x: int } + [@@deriving sexp] + end diff --git a/tests/passing/js-fun-rec.ml b/tests/passing/js-fun-rec.ml deleted file mode 100644 index 4e2c2f80..00000000 --- a/tests/passing/js-fun-rec.ml +++ /dev/null @@ -1,13 +0,0 @@ -let rec check_header t = - if Iobuf.length t.buf < header_length then failwiths "Short packet" t !sexp_of_t; -and session t = - check_header t; - Session_id.of_int_exn id_int -and length t = - let len = raw_length t in - if len = eos_marker then 0 else len -and sexp_of_t t = (* something pretty for debugging *) - let lo, len = Iobuf.snapshot t.buf, Iobuf.length t.buf in - protect ~finally:(fun () -> Iobuf.Snapshot.rewind lo t.buf; Iobuf.resize t.buf len) - (fun () -> ()) -;; diff --git a/tests/passing/js-fun-rec.ml.opts b/tests/passing/js-fun-rec.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-fun-rec.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-fun-rec.t b/tests/passing/js-fun-rec.t new file mode 100644 index 00000000..e29653f5 --- /dev/null +++ b/tests/passing/js-fun-rec.t @@ -0,0 +1,31 @@ + + $ cat > js-fun-rec.ml << "EOF" + > let rec check_header t = + > if Iobuf.length t.buf < header_length then failwiths "Short packet" t !sexp_of_t; + > and session t = + > check_header t; + > Session_id.of_int_exn id_int + > and length t = + > let len = raw_length t in + > if len = eos_marker then 0 else len + > and sexp_of_t t = (* something pretty for debugging *) + > let lo, len = Iobuf.snapshot t.buf, Iobuf.length t.buf in + > protect ~finally:(fun () -> Iobuf.Snapshot.rewind lo t.buf; Iobuf.resize t.buf len) + > (fun () -> ()) + > ;; + > EOF + + $ ocp-indent -c JaneStreet js-fun-rec.ml + let rec check_header t = + if Iobuf.length t.buf < header_length then failwiths "Short packet" t !sexp_of_t; + and session t = + check_header t; + Session_id.of_int_exn id_int + and length t = + let len = raw_length t in + if len = eos_marker then 0 else len + and sexp_of_t t = (* something pretty for debugging *) + let lo, len = Iobuf.snapshot t.buf, Iobuf.length t.buf in + protect ~finally:(fun () -> Iobuf.Snapshot.rewind lo t.buf; Iobuf.resize t.buf len) + (fun () -> ()) + ;; diff --git a/tests/passing/js-label.ml b/tests/passing/js-label.ml deleted file mode 100644 index 1898df2e..00000000 --- a/tests/passing/js-label.ml +++ /dev/null @@ -1,19 +0,0 @@ -(* Get C.t and (r : S.t -> T.t) indented two chars right of their labels. *) -type t - = A.t - -> bbb : - C.t - -> D.t - -> e : (f : G.t -> H.t) - -> I.t - -> jjj : [ `K - | `L - ] - -> M.t - -> nnn : - [ `O - | `P - ] - -> qqq : - (r : S.t -> T.t) - -> U.t diff --git a/tests/passing/js-label.ml.opts b/tests/passing/js-label.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-label.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-label.t b/tests/passing/js-label.t new file mode 100644 index 00000000..c3938145 --- /dev/null +++ b/tests/passing/js-label.t @@ -0,0 +1,43 @@ + + $ cat > js-label.ml << "EOF" + > (* Get C.t and (r : S.t -> T.t) indented two chars right of their labels. *) + > type t + > = A.t + > -> bbb : + > C.t + > -> D.t + > -> e : (f : G.t -> H.t) + > -> I.t + > -> jjj : [ `K + > | `L + > ] + > -> M.t + > -> nnn : + > [ `O + > | `P + > ] + > -> qqq : + > (r : S.t -> T.t) + > -> U.t + > EOF + + $ ocp-indent -c JaneStreet js-label.ml + (* Get C.t and (r : S.t -> T.t) indented two chars right of their labels. *) + type t + = A.t + -> bbb : + C.t + -> D.t + -> e : (f : G.t -> H.t) + -> I.t + -> jjj : [ `K + | `L + ] + -> M.t + -> nnn : + [ `O + | `P + ] + -> qqq : + (r : S.t -> T.t) + -> U.t diff --git a/tests/passing/js-let.ml b/tests/passing/js-let.ml deleted file mode 100644 index 7065f9c4..00000000 --- a/tests/passing/js-let.ml +++ /dev/null @@ -1,42 +0,0 @@ -let foo - some very long arguments that we break onto the next line - = - bar (); - baz -(* The [some] above is indented less when [let foo] is the first line. The - problem goes away if there's anything on the line before [let foo]. *) - -(* The picture shows where we want the `=' to be. However, Tuareg currently moves it over - to line up with the arguments. - - Perhaps this is merely a personal preference, but that seems ugly to me. - - pszilagyi: It's consistent with other infix operators (although this is syntax) for it - to be where you prefer. *) - -let foo arguments - = bar - -let foo - arguments - = bar - -(* This program parses, but the [let] is indented incorrectly. *) -module M = struct - module M : module type of M = struct - let x = () - end -end -(* Removing the [: module type of M] removes the bug. *) - -let parenthesized_let_tweak = - (let sub value n l f = - case ~value (message ("fix_sending_" ^ n) ~length:(35 + 29 + l) f) - in - x) - -let parenthesized_let_tweak = - f ~x:(let n = - S.S.g s.S.s ~s - in - y) diff --git a/tests/passing/js-let.ml.opts b/tests/passing/js-let.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-let.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-let.t b/tests/passing/js-let.t new file mode 100644 index 00000000..87f9313b --- /dev/null +++ b/tests/passing/js-let.t @@ -0,0 +1,89 @@ + + $ cat > js-let.ml << "EOF" + > let foo + > some very long arguments that we break onto the next line + > = + > bar (); + > baz + > (* The [some] above is indented less when [let foo] is the first line. The + > problem goes away if there's anything on the line before [let foo]. *) + > + > (* The picture shows where we want the `=' to be. However, Tuareg currently moves it over + > to line up with the arguments. + > + > Perhaps this is merely a personal preference, but that seems ugly to me. + > + > pszilagyi: It's consistent with other infix operators (although this is syntax) for it + > to be where you prefer. *) + > + > let foo arguments + > = bar + > + > let foo + > arguments + > = bar + > + > (* This program parses, but the [let] is indented incorrectly. *) + > module M = struct + > module M : module type of M = struct + > let x = () + > end + > end + > (* Removing the [: module type of M] removes the bug. *) + > + > let parenthesized_let_tweak = + > (let sub value n l f = + > case ~value (message ("fix_sending_" ^ n) ~length:(35 + 29 + l) f) + > in + > x) + > + > let parenthesized_let_tweak = + > f ~x:(let n = + > S.S.g s.S.s ~s + > in + > y) + > EOF + + $ ocp-indent -c JaneStreet js-let.ml + let foo + some very long arguments that we break onto the next line + = + bar (); + baz + (* The [some] above is indented less when [let foo] is the first line. The + problem goes away if there's anything on the line before [let foo]. *) + + (* The picture shows where we want the `=' to be. However, Tuareg currently moves it over + to line up with the arguments. + + Perhaps this is merely a personal preference, but that seems ugly to me. + + pszilagyi: It's consistent with other infix operators (although this is syntax) for it + to be where you prefer. *) + + let foo arguments + = bar + + let foo + arguments + = bar + + (* This program parses, but the [let] is indented incorrectly. *) + module M = struct + module M : module type of M = struct + let x = () + end + end + (* Removing the [: module type of M] removes the bug. *) + + let parenthesized_let_tweak = + (let sub value n l f = + case ~value (message ("fix_sending_" ^ n) ~length:(35 + 29 + l) f) + in + x) + + let parenthesized_let_tweak = + f ~x:(let n = + S.S.g s.S.s ~s + in + y) diff --git a/tests/passing/js-list.ml b/tests/passing/js-list.ml deleted file mode 100644 index 9b68f226..00000000 --- a/tests/passing/js-list.ml +++ /dev/null @@ -1,12 +0,0 @@ -(* mixed list styles *) -let cases = - [ Group ("publishing", [ - basic_pre2 - ~name; - ]); (* I think this line and the 2 preceding ones are indented one space too - few by ocp-indent *) - Group ("recovery", [ - basic_pre2 - ~name - ]); - ] diff --git a/tests/passing/js-list.ml.opts b/tests/passing/js-list.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-list.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-list.t b/tests/passing/js-list.t new file mode 100644 index 00000000..6fce9412 --- /dev/null +++ b/tests/passing/js-list.t @@ -0,0 +1,29 @@ + + $ cat > js-list.ml << "EOF" + > (* mixed list styles *) + > let cases = + > [ Group ("publishing", [ + > basic_pre2 + > ~name; + > ]); (* I think this line and the 2 preceding ones are indented one space too + > few by ocp-indent *) + > Group ("recovery", [ + > basic_pre2 + > ~name + > ]); + > ] + > EOF + + $ ocp-indent -c JaneStreet js-list.ml + (* mixed list styles *) + let cases = + [ Group ("publishing", [ + basic_pre2 + ~name; + ]); (* I think this line and the 2 preceding ones are indented one space too + few by ocp-indent *) + Group ("recovery", [ + basic_pre2 + ~name + ]); + ] diff --git a/tests/passing/js-low-priority.ml b/tests/passing/js-low-priority.ml deleted file mode 100644 index eb3ba49e..00000000 --- a/tests/passing/js-low-priority.ml +++ /dev/null @@ -1,35 +0,0 @@ -(* Relatively low priority Jane Street indentation bugs. *) - - - -(* js-args *) - -(* uncommon *) -let x = - try x with a -> b - | c -> d -let x = - try x - with a -> b - | c -> d - - - -(* js-comment *) - -let mk_cont_parser cont_parse = (); fun _state str ~max_pos ~pos -> - let len = max_pos - pos + 1 in - cont_parse ~pos ~len str - -(* sexp parser is sensitive to - absent newlines at the end of files. *) - - - -(* It would be nice if a partially completed ocamldoc code fragment inside a - comment had the closing delimiter "]}" indented nicely before the comment is - closed. (This has to be the last comment in the file, to be partial.) *) -(* Maybe add: - {[ - val state : t -> [ `Unstarted | `Running | `Stopped ] - ]} diff --git a/tests/passing/js-low-priority.ml.opts b/tests/passing/js-low-priority.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-low-priority.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-low-priority.t b/tests/passing/js-low-priority.t new file mode 100644 index 00000000..012822f2 --- /dev/null +++ b/tests/passing/js-low-priority.t @@ -0,0 +1,75 @@ + + $ cat > js-low-priority.ml << "EOF" + > (* Relatively low priority Jane Street indentation bugs. *) + > + > + > + > (* js-args *) + > + > (* uncommon *) + > let x = + > try x with a -> b + > | c -> d + > let x = + > try x + > with a -> b + > | c -> d + > + > + > + > (* js-comment *) + > + > let mk_cont_parser cont_parse = (); fun _state str ~max_pos ~pos -> + > let len = max_pos - pos + 1 in + > cont_parse ~pos ~len str + > + > (* sexp parser is sensitive to + > absent newlines at the end of files. *) + > + > + > + > (* It would be nice if a partially completed ocamldoc code fragment inside a + > comment had the closing delimiter "]}" indented nicely before the comment is + > closed. (This has to be the last comment in the file, to be partial.) *) + > (* Maybe add: + > {[ + > val state : t -> [ `Unstarted | `Running | `Stopped ] + > ]} + > EOF + + $ ocp-indent -c JaneStreet js-low-priority.ml + (* Relatively low priority Jane Street indentation bugs. *) + + + + (* js-args *) + + (* uncommon *) + let x = + try x with a -> b + | c -> d + let x = + try x + with a -> b + | c -> d + + + + (* js-comment *) + + let mk_cont_parser cont_parse = (); fun _state str ~max_pos ~pos -> + let len = max_pos - pos + 1 in + cont_parse ~pos ~len str + + (* sexp parser is sensitive to + absent newlines at the end of files. *) + + + + (* It would be nice if a partially completed ocamldoc code fragment inside a + comment had the closing delimiter "]}" indented nicely before the comment is + closed. (This has to be the last comment in the file, to be partial.) *) + (* Maybe add: + {[ + val state : t -> [ `Unstarted | `Running | `Stopped ] + ]} diff --git a/tests/passing/js-map.ml b/tests/passing/js-map.ml deleted file mode 100644 index 581d3938..00000000 --- a/tests/passing/js-map.ml +++ /dev/null @@ -1,4 +0,0 @@ -let projection_files = - Deferred.List.map x ~f:(fun p -> - _) - >>| String.split ~on:'\n' diff --git a/tests/passing/js-map.ml.opts b/tests/passing/js-map.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-map.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-map.t b/tests/passing/js-map.t new file mode 100644 index 00000000..087ffb1a --- /dev/null +++ b/tests/passing/js-map.t @@ -0,0 +1,13 @@ + + $ cat > js-map.ml << "EOF" + > let projection_files = + > Deferred.List.map x ~f:(fun p -> + > _) + > >>| String.split ~on:'\n' + > EOF + + $ ocp-indent -c JaneStreet js-map.ml + let projection_files = + Deferred.List.map x ~f:(fun p -> + _) + >>| String.split ~on:'\n' diff --git a/tests/passing/js-model.ml b/tests/passing/js-model.ml deleted file mode 100644 index 82ca648d..00000000 --- a/tests/passing/js-model.ml +++ /dev/null @@ -1,22 +0,0 @@ -val f - : int - -> int - -type t = - | A - | B - -let height = function - | A -> 0 - | B -> 1 - -let _ = - if x then begin - y - end else if x then - y - else z - -type t - = int - -> int diff --git a/tests/passing/js-model.ml.opts b/tests/passing/js-model.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-model.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-model.t b/tests/passing/js-model.t new file mode 100644 index 00000000..23e0179c --- /dev/null +++ b/tests/passing/js-model.t @@ -0,0 +1,49 @@ + + $ cat > js-model.ml << "EOF" + > val f + > : int + > -> int + > + > type t = + > | A + > | B + > + > let height = function + > | A -> 0 + > | B -> 1 + > + > let _ = + > if x then begin + > y + > end else if x then + > y + > else z + > + > type t + > = int + > -> int + > EOF + + $ ocp-indent -c JaneStreet js-model.ml + val f + : int + -> int + + type t = + | A + | B + + let height = function + | A -> 0 + | B -> 1 + + let _ = + if x then begin + y + end else if x then + y + else z + + type t + = int + -> int diff --git a/tests/passing/js-pipebang.ml b/tests/passing/js-pipebang.ml deleted file mode 100644 index 35f09994..00000000 --- a/tests/passing/js-pipebang.ml +++ /dev/null @@ -1,83 +0,0 @@ -let f x = - x - >>| fun x -> - g x - >>| fun x -> - h x -;; - -let f x = - x >>| fun x -> - g x >>| fun x -> - h x -;; - -let f x = - x - |! fun x -> - g x - |! fun x -> - h x -;; - -let f x = - x |! fun x -> - g x |! fun x -> - h x -;; - -let _ = - (z (fun x -> x) - |! Validate.of_list) (* Tuareg indents this line too far. *) - -let _ = - (* Tuareg works correctly on this (if you drop the fun). *) - (z x - |! Validate.of_list) - -(* jli found this great one. Tuareg gets confused by the paren before List.map and - indents |! way too far, under "k ^". ocp-indent should shine, since it understands the - syntax better. *) -let _ = - List.filter_opt [ - format old (fun old -> "removed: " - ^ (List.map old ~f:(fun (k, v) -> k ^ "=" ^ acl_to_string v) - |! String.concat ~sep:", ")) - ] - - - -(* (|>) = (|!) *) - -let f x = - x - |> fun x -> - g x - |> fun x -> - h x -;; - -let f x = - x |> fun x -> - g x |> fun x -> - h x -;; - -let _ = - (z (fun x -> x) - |> Validate.of_list) (* Tuareg indents this line too far. *) - -let _ = - (* Tuareg works correctly on this (if you drop the fun). *) - (z x - |> Validate.of_list) - -(* jli found this great one. Tuareg gets confused by the paren before List.map and - indents |> way too far, under "k ^". ocp-indent should shine, since it understands the - syntax better. *) -let _ = - List.filter_opt [ - format old (fun old -> "removed: " - ^ (List.map old ~f:(fun (k, v) -> k ^ "=" ^ acl_to_string v) - |> String.concat ~sep:", ")) - ] diff --git a/tests/passing/js-pipebang.ml.opts b/tests/passing/js-pipebang.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-pipebang.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-pipebang.t b/tests/passing/js-pipebang.t new file mode 100644 index 00000000..b0b7a75b --- /dev/null +++ b/tests/passing/js-pipebang.t @@ -0,0 +1,171 @@ + + $ cat > js-pipebang.ml << "EOF" + > let f x = + > x + > >>| fun x -> + > g x + > >>| fun x -> + > h x + > ;; + > + > let f x = + > x >>| fun x -> + > g x >>| fun x -> + > h x + > ;; + > + > let f x = + > x + > |! fun x -> + > g x + > |! fun x -> + > h x + > ;; + > + > let f x = + > x |! fun x -> + > g x |! fun x -> + > h x + > ;; + > + > let _ = + > (z (fun x -> x) + > |! Validate.of_list) (* Tuareg indents this line too far. *) + > + > let _ = + > (* Tuareg works correctly on this (if you drop the fun). *) + > (z x + > |! Validate.of_list) + > + > (* jli found this great one. Tuareg gets confused by the paren before List.map and + > indents |! way too far, under "k ^". ocp-indent should shine, since it understands the + > syntax better. *) + > let _ = + > List.filter_opt [ + > format old (fun old -> "removed: " + > ^ (List.map old ~f:(fun (k, v) -> k ^ "=" ^ acl_to_string v) + > |! String.concat ~sep:", ")) + > ] + > + > + > + > (* (|>) = (|!) *) + > + > let f x = + > x + > |> fun x -> + > g x + > |> fun x -> + > h x + > ;; + > + > let f x = + > x |> fun x -> + > g x |> fun x -> + > h x + > ;; + > + > let _ = + > (z (fun x -> x) + > |> Validate.of_list) (* Tuareg indents this line too far. *) + > + > let _ = + > (* Tuareg works correctly on this (if you drop the fun). *) + > (z x + > |> Validate.of_list) + > + > (* jli found this great one. Tuareg gets confused by the paren before List.map and + > indents |> way too far, under "k ^". ocp-indent should shine, since it understands the + > syntax better. *) + > let _ = + > List.filter_opt [ + > format old (fun old -> "removed: " + > ^ (List.map old ~f:(fun (k, v) -> k ^ "=" ^ acl_to_string v) + > |> String.concat ~sep:", ")) + > ] + > EOF + + $ ocp-indent -c JaneStreet js-pipebang.ml + let f x = + x + >>| fun x -> + g x + >>| fun x -> + h x + ;; + + let f x = + x >>| fun x -> + g x >>| fun x -> + h x + ;; + + let f x = + x + |! fun x -> + g x + |! fun x -> + h x + ;; + + let f x = + x |! fun x -> + g x |! fun x -> + h x + ;; + + let _ = + (z (fun x -> x) + |! Validate.of_list) (* Tuareg indents this line too far. *) + + let _ = + (* Tuareg works correctly on this (if you drop the fun). *) + (z x + |! Validate.of_list) + + (* jli found this great one. Tuareg gets confused by the paren before List.map and + indents |! way too far, under "k ^". ocp-indent should shine, since it understands the + syntax better. *) + let _ = + List.filter_opt [ + format old (fun old -> "removed: " + ^ (List.map old ~f:(fun (k, v) -> k ^ "=" ^ acl_to_string v) + |! String.concat ~sep:", ")) + ] + + + + (* (|>) = (|!) *) + + let f x = + x + |> fun x -> + g x + |> fun x -> + h x + ;; + + let f x = + x |> fun x -> + g x |> fun x -> + h x + ;; + + let _ = + (z (fun x -> x) + |> Validate.of_list) (* Tuareg indents this line too far. *) + + let _ = + (* Tuareg works correctly on this (if you drop the fun). *) + (z x + |> Validate.of_list) + + (* jli found this great one. Tuareg gets confused by the paren before List.map and + indents |> way too far, under "k ^". ocp-indent should shine, since it understands the + syntax better. *) + let _ = + List.filter_opt [ + format old (fun old -> "removed: " + ^ (List.map old ~f:(fun (k, v) -> k ^ "=" ^ acl_to_string v) + |> String.concat ~sep:", ")) + ] diff --git a/tests/passing/js-poly.ml b/tests/passing/js-poly.ml deleted file mode 100644 index 9956bfd3..00000000 --- a/tests/passing/js-poly.ml +++ /dev/null @@ -1,16 +0,0 @@ -let handle_query qs ~msg_client:_ = - try_with (fun () -> - if _ then - f >>| fun () -> - `Done () - else - _ - ) -;; - -if _ then - _ -else - assert_branch_has_node branch node >>| fun () -> - { t with node; floating } -;; diff --git a/tests/passing/js-poly.ml.opts b/tests/passing/js-poly.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-poly.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-poly.t b/tests/passing/js-poly.t new file mode 100644 index 00000000..9ea9f410 --- /dev/null +++ b/tests/passing/js-poly.t @@ -0,0 +1,37 @@ + + $ cat > js-poly.ml << "EOF" + > let handle_query qs ~msg_client:_ = + > try_with (fun () -> + > if _ then + > f >>| fun () -> + > `Done () + > else + > _ + > ) + > ;; + > + > if _ then + > _ + > else + > assert_branch_has_node branch node >>| fun () -> + > { t with node; floating } + > ;; + > EOF + + $ ocp-indent -c JaneStreet js-poly.ml + let handle_query qs ~msg_client:_ = + try_with (fun () -> + if _ then + f >>| fun () -> + `Done () + else + _ + ) + ;; + + if _ then + _ + else + assert_branch_has_node branch node >>| fun () -> + { t with node; floating } + ;; diff --git a/tests/passing/js-ppx-struct.ml b/tests/passing/js-ppx-struct.ml deleted file mode 100644 index 8315e51a..00000000 --- a/tests/passing/js-ppx-struct.ml +++ /dev/null @@ -1,44 +0,0 @@ -open! Base -open Ppxlib -open Ast_builder.Default - -let loc = location ~start:[%here] ~end_:[%here] ~ghost:true - -(* These three are okay: *) - -include struct - let _ = [%expr `x] - let _ = () -end - -include struct - let _ = [%type: [`x]] - let _ = () -end - -include struct - let _ = [%pat? `x] - let _ = () -end - -(* These four cause the following line to jump back all the way to the left: *) - -include struct - let _ = [%stri let () = ();;] - let _ = () -end - -include struct - let _ = [%str let () = ();;] - let _ = () -end - -include struct - let _ = [%sigi: val x : int] - let _ = () -end - -include struct - let _ = [%sig: val x : int] - let _ = () -end diff --git a/tests/passing/js-ppx-struct.t b/tests/passing/js-ppx-struct.t new file mode 100644 index 00000000..d04fbd85 --- /dev/null +++ b/tests/passing/js-ppx-struct.t @@ -0,0 +1,93 @@ + + $ cat > js-ppx-struct.ml << "EOF" + > open! Base + > open Ppxlib + > open Ast_builder.Default + > + > let loc = location ~start:[%here] ~end_:[%here] ~ghost:true + > + > (* These three are okay: *) + > + > include struct + > let _ = [%expr `x] + > let _ = () + > end + > + > include struct + > let _ = [%type: [`x]] + > let _ = () + > end + > + > include struct + > let _ = [%pat? `x] + > let _ = () + > end + > + > (* These four cause the following line to jump back all the way to the left: *) + > + > include struct + > let _ = [%stri let () = ();;] + > let _ = () + > end + > + > include struct + > let _ = [%str let () = ();;] + > let _ = () + > end + > + > include struct + > let _ = [%sigi: val x : int] + > let _ = () + > end + > + > include struct + > let _ = [%sig: val x : int] + > let _ = () + > end + > EOF + + $ ocp-indent js-ppx-struct.ml + open! Base + open Ppxlib + open Ast_builder.Default + + let loc = location ~start:[%here] ~end_:[%here] ~ghost:true + + (* These three are okay: *) + + include struct + let _ = [%expr `x] + let _ = () + end + + include struct + let _ = [%type: [`x]] + let _ = () + end + + include struct + let _ = [%pat? `x] + let _ = () + end + + (* These four cause the following line to jump back all the way to the left: *) + + include struct + let _ = [%stri let () = ();;] + let _ = () + end + + include struct + let _ = [%str let () = ();;] + let _ = () + end + + include struct + let _ = [%sigi: val x : int] + let _ = () + end + + include struct + let _ = [%sig: val x : int] + let _ = () + end diff --git a/tests/passing/js-sexp.ml b/tests/passing/js-sexp.ml deleted file mode 100644 index f92c04e8..00000000 --- a/tests/passing/js-sexp.ml +++ /dev/null @@ -1,21 +0,0 @@ -let () = - f - x - [%sexp_of int] - y -;; - -(* y *) -let z = - some_function - [%sexp_of foo] -;; - -let z = - some_function - argument - -let d = - print_sexp - [%sexp_of unit] - () diff --git a/tests/passing/js-sexp.ml.opts b/tests/passing/js-sexp.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-sexp.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-sexp.t b/tests/passing/js-sexp.t new file mode 100644 index 00000000..9122a630 --- /dev/null +++ b/tests/passing/js-sexp.t @@ -0,0 +1,47 @@ + + $ cat > js-sexp.ml << "EOF" + > let () = + > f + > x + > [%sexp_of int] + > y + > ;; + > + > (* y *) + > let z = + > some_function + > [%sexp_of foo] + > ;; + > + > let z = + > some_function + > argument + > + > let d = + > print_sexp + > [%sexp_of unit] + > () + > EOF + + $ ocp-indent -c JaneStreet js-sexp.ml + let () = + f + x + [%sexp_of int] + y + ;; + + (* y *) + let z = + some_function + [%sexp_of foo] + ;; + + let z = + some_function + argument + + let d = + print_sexp + [%sexp_of unit] + () diff --git a/tests/passing/js-str.ml b/tests/passing/js-str.ml deleted file mode 100644 index fff72258..00000000 --- a/tests/passing/js-str.ml +++ /dev/null @@ -1,7 +0,0 @@ -(* gigantic string with weird characters that causes trouble *) -TEST_UNIT = - eprintf "%s\n" - (remove_progress_bar "[============================================================ ] 04840 / 04841 [============================================================ ] 04841 / 04842 [======================================= ] 05010 / 07826 [======================== ] 05053 / 13052 [============================= ] 06807 / 14348 [=============================== ] 08203 / 16405 [================================= ] 09418 / 17458 [================================= ] 09566 / 17458 [================================== ] 09631 / 17458 [================================= ] 10200 / 18846 [=========================== ] 10221 / 23043 [============================= ] 11016 / 23098 make[1]: Leaving directory `/mnt/local/sda1/mstanojevic/repos/live/submissions'") - -let _ = -x diff --git a/tests/passing/js-str.ml.opts b/tests/passing/js-str.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-str.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-str.ml.ref b/tests/passing/js-str.ml.ref deleted file mode 100644 index f1452090..00000000 --- a/tests/passing/js-str.ml.ref +++ /dev/null @@ -1,7 +0,0 @@ -(* gigantic string with weird characters that causes trouble *) -TEST_UNIT = - eprintf "%s\n" - (remove_progress_bar "[============================================================ ] 04840 / 04841 [============================================================ ] 04841 / 04842 [======================================= ] 05010 / 07826 [======================== ] 05053 / 13052 [============================= ] 06807 / 14348 [=============================== ] 08203 / 16405 [================================= ] 09418 / 17458 [================================= ] 09566 / 17458 [================================== ] 09631 / 17458 [================================= ] 10200 / 18846 [=========================== ] 10221 / 23043 [============================= ] 11016 / 23098 make[1]: Leaving directory `/mnt/local/sda1/mstanojevic/repos/live/submissions'") - -let _ = - x diff --git a/tests/passing/js-str.t b/tests/passing/js-str.t new file mode 100644 index 00000000..a611d27f --- /dev/null +++ b/tests/passing/js-str.t @@ -0,0 +1,19 @@ + + $ cat > js-str.ml << "EOF" + > (* gigantic string with weird characters that causes trouble *) + > TEST_UNIT = + > eprintf "%s\n" + > (remove_progress_bar "[============================================================ ] 04840 / 04841 [============================================================ ] 04841 / 04842 [======================================= ] 05010 / 07826 [======================== ] 05053 / 13052 [============================= ] 06807 / 14348 [=============================== ] 08203 / 16405 [================================= ] 09418 / 17458 [================================= ] 09566 / 17458 [================================== ] 09631 / 17458 [================================= ] 10200 / 18846 [=========================== ] 10221 / 23043 [============================= ] 11016 / 23098 make[1]: Leaving directory `/mnt/local/sda1/mstanojevic/repos/live/submissions'") + > + > let _ = + > x + > EOF + + $ ocp-indent -c JaneStreet js-str.ml + (* gigantic string with weird characters that causes trouble *) + TEST_UNIT = + eprintf "%s\n" + (remove_progress_bar "[============================================================ ] 04840 / 04841 [============================================================ ] 04841 / 04842 [======================================= ] 05010 / 07826 [======================== ] 05053 / 13052 [============================= ] 06807 / 14348 [=============================== ] 08203 / 16405 [================================= ] 09418 / 17458 [================================= ] 09566 / 17458 [================================== ] 09631 / 17458 [================================= ] 10200 / 18846 [=========================== ] 10221 / 23043 [============================= ] 11016 / 23098 make[1]: Leaving directory `/mnt/local/sda1/mstanojevic/repos/live/submissions'") + + let _ = + x diff --git a/tests/passing/js-test.ml b/tests/passing/js-test.ml deleted file mode 100644 index ec6a6c2d..00000000 --- a/tests/passing/js-test.ml +++ /dev/null @@ -1,37 +0,0 @@ -let%test = - let b = true in - b -(* Above, a multi-line TEST (likewise BENCH) was indented wrong only when it - started on the first line. (That wasn't really a big problem.) *) - -(* oUnit *) - -module E = Example - -let%test_module = - (module struct - let%test = false - let%test = - let b = true in - b - let%test "Name_test" = - let b = true in (* tricky for Tuareg *) - b - end) - -let%test_module "Name" = - (module struct - let%test_unit = () - let%test_unit = - let () = () in - () - let%test_unit "Name_unit" = - let () = () in (* tricky for Tuareg *) - () - - let%test_unit = - let msgcount = 10_000 in (* tricky for Tuareg *) - () - end) - -let _ = printf "Hello, world!\n" diff --git a/tests/passing/js-test.ml.opts b/tests/passing/js-test.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-test.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-test.t b/tests/passing/js-test.t new file mode 100644 index 00000000..36401174 --- /dev/null +++ b/tests/passing/js-test.t @@ -0,0 +1,79 @@ + + $ cat > js-test.ml << "EOF" + > let%test = + > let b = true in + > b + > (* Above, a multi-line TEST (likewise BENCH) was indented wrong only when it + > started on the first line. (That wasn't really a big problem.) *) + > + > (* oUnit *) + > + > module E = Example + > + > let%test_module = + > (module struct + > let%test = false + > let%test = + > let b = true in + > b + > let%test "Name_test" = + > let b = true in (* tricky for Tuareg *) + > b + > end) + > + > let%test_module "Name" = + > (module struct + > let%test_unit = () + > let%test_unit = + > let () = () in + > () + > let%test_unit "Name_unit" = + > let () = () in (* tricky for Tuareg *) + > () + > + > let%test_unit = + > let msgcount = 10_000 in (* tricky for Tuareg *) + > () + > end) + > + > let _ = printf "Hello, world!\n" + > EOF + + $ ocp-indent -c JaneStreet js-test.ml + let%test = + let b = true in + b + (* Above, a multi-line TEST (likewise BENCH) was indented wrong only when it + started on the first line. (That wasn't really a big problem.) *) + + (* oUnit *) + + module E = Example + + let%test_module = + (module struct + let%test = false + let%test = + let b = true in + b + let%test "Name_test" = + let b = true in (* tricky for Tuareg *) + b + end) + + let%test_module "Name" = + (module struct + let%test_unit = () + let%test_unit = + let () = () in + () + let%test_unit "Name_unit" = + let () = () in (* tricky for Tuareg *) + () + + let%test_unit = + let msgcount = 10_000 in (* tricky for Tuareg *) + () + end) + + let _ = printf "Hello, world!\n" diff --git a/tests/passing/js-try.ml b/tests/passing/js-try.ml deleted file mode 100644 index ff684159..00000000 --- a/tests/passing/js-try.ml +++ /dev/null @@ -1,5 +0,0 @@ -(* nested "try" *) -try - try x - with e -> e -with e -> e (* indented too far *) diff --git a/tests/passing/js-try.ml.opts b/tests/passing/js-try.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-try.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-try.t b/tests/passing/js-try.t new file mode 100644 index 00000000..b2f400f7 --- /dev/null +++ b/tests/passing/js-try.t @@ -0,0 +1,15 @@ + + $ cat > js-try.ml << "EOF" + > (* nested "try" *) + > try + > try x + > with e -> e + > with e -> e (* indented too far *) + > EOF + + $ ocp-indent -c JaneStreet js-try.ml + (* nested "try" *) + try + try x + with e -> e + with e -> e (* indented too far *) diff --git a/tests/passing/js-type.ml b/tests/passing/js-type.ml deleted file mode 100644 index 9f9eb0d7..00000000 --- a/tests/passing/js-type.ml +++ /dev/null @@ -1,54 +0,0 @@ -type t = - S.s (* looks like a constructor to ocp-indent, which indents too far *) -type t = - s (* correct, because this doesn't look like a constructor to ocp-indent *) -type t = - S (* correctly indented a little more, because... *) -type t = - | S (* we leave room for the vertical bar *) - - - -(* analogous value expressions, analogous to lists, some different from now *) -let _ = - [ x - ; y - ] -let _ = - [ x; - y - ] -let _ = - ( x - , y - ) -let _ = - ( x, - y - ) -let _ = - ( - x - , y - ) -let _ = - [ - x - ; y - ] -let _ = ( - x, - y -) -let _ = [ - x; - y -] -let _ = ( - x -, y -) -let _ = [ - x -; y -] diff --git a/tests/passing/js-type.ml.opts b/tests/passing/js-type.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-type.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-type.t b/tests/passing/js-type.t new file mode 100644 index 00000000..02ffa09f --- /dev/null +++ b/tests/passing/js-type.t @@ -0,0 +1,113 @@ + + $ cat > js-type.ml << "EOF" + > type t = + > S.s (* looks like a constructor to ocp-indent, which indents too far *) + > type t = + > s (* correct, because this doesn't look like a constructor to ocp-indent *) + > type t = + > S (* correctly indented a little more, because... *) + > type t = + > | S (* we leave room for the vertical bar *) + > + > + > + > (* analogous value expressions, analogous to lists, some different from now *) + > let _ = + > [ x + > ; y + > ] + > let _ = + > [ x; + > y + > ] + > let _ = + > ( x + > , y + > ) + > let _ = + > ( x, + > y + > ) + > let _ = + > ( + > x + > , y + > ) + > let _ = + > [ + > x + > ; y + > ] + > let _ = ( + > x, + > y + > ) + > let _ = [ + > x; + > y + > ] + > let _ = ( + > x + > , y + > ) + > let _ = [ + > x + > ; y + > ] + > EOF + + $ ocp-indent -c JaneStreet js-type.ml + type t = + S.s (* looks like a constructor to ocp-indent, which indents too far *) + type t = + s (* correct, because this doesn't look like a constructor to ocp-indent *) + type t = + S (* correctly indented a little more, because... *) + type t = + | S (* we leave room for the vertical bar *) + + + + (* analogous value expressions, analogous to lists, some different from now *) + let _ = + [ x + ; y + ] + let _ = + [ x; + y + ] + let _ = + ( x + , y + ) + let _ = + ( x, + y + ) + let _ = + ( + x + , y + ) + let _ = + [ + x + ; y + ] + let _ = ( + x, + y + ) + let _ = [ + x; + y + ] + let _ = ( + x + , y + ) + let _ = [ + x + ; y + ] diff --git a/tests/passing/js-var.ml b/tests/passing/js-var.ml deleted file mode 100644 index b6434edd..00000000 --- a/tests/passing/js-var.ml +++ /dev/null @@ -1,4 +0,0 @@ -type t = - | A - | B of int - | C diff --git a/tests/passing/js-var.ml.opts b/tests/passing/js-var.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/js-var.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/js-var.t b/tests/passing/js-var.t new file mode 100644 index 00000000..263086c4 --- /dev/null +++ b/tests/passing/js-var.t @@ -0,0 +1,13 @@ + + $ cat > js-var.ml << "EOF" + > type t = + > | A + > | B of int + > | C + > EOF + + $ ocp-indent -c JaneStreet js-var.ml + type t = + | A + | B of int + | C diff --git a/tests/passing/let-and.ml b/tests/passing/let-and.ml deleted file mode 100644 index 56d5f522..00000000 --- a/tests/passing/let-and.ml +++ /dev/null @@ -1,13 +0,0 @@ -let f - = fun x -> x -and g - = fun x -> x -and h - = fun x -> x - -let rec f : 'a. 'a -> 'a - = fun x -> g x -and g : 'a. 'a -> 'a - = fun x -> h x -and h : 'a. 'a -> 'a - = fun x -> f x diff --git a/tests/passing/let-and.t b/tests/passing/let-and.t new file mode 100644 index 00000000..e2e2f383 --- /dev/null +++ b/tests/passing/let-and.t @@ -0,0 +1,31 @@ + + $ cat > let-and.ml << "EOF" + > let f + > = fun x -> x + > and g + > = fun x -> x + > and h + > = fun x -> x + > + > let rec f : 'a. 'a -> 'a + > = fun x -> g x + > and g : 'a. 'a -> 'a + > = fun x -> h x + > and h : 'a. 'a -> 'a + > = fun x -> f x + > EOF + + $ ocp-indent let-and.ml + let f + = fun x -> x + and g + = fun x -> x + and h + = fun x -> x + + let rec f : 'a. 'a -> 'a + = fun x -> g x + and g : 'a. 'a -> 'a + = fun x -> h x + and h : 'a. 'a -> 'a + = fun x -> f x diff --git a/tests/passing/let-open.ml b/tests/passing/let-open.ml deleted file mode 100644 index 15ff8e75..00000000 --- a/tests/passing/let-open.ml +++ /dev/null @@ -1,5 +0,0 @@ - -let _ = - (* ... *) - let open Option in - indented_line diff --git a/tests/passing/let-open.t b/tests/passing/let-open.t new file mode 100644 index 00000000..c1a51776 --- /dev/null +++ b/tests/passing/let-open.t @@ -0,0 +1,15 @@ + + $ cat > let-open.ml << "EOF" + > + > let _ = + > (* ... *) + > let open Option in + > indented_line + > EOF + + $ ocp-indent let-open.ml + + let _ = + (* ... *) + let open Option in + indented_line diff --git a/tests/passing/lwt.ml b/tests/passing/lwt.ml deleted file mode 100644 index 01b16faa..00000000 --- a/tests/passing/lwt.ml +++ /dev/null @@ -1,24 +0,0 @@ -let f () = - lwt x = g () in - Lwt.return x - -let f x = match_lwt x with - | A -> A - | B -> B - -let g x = try_lwt - f x - finally - g x - -let a f x = - try_lwt f x - with Failure _ -> () - finally () - -(* should'nt break normal try/with imbrication *) -let z f x = - try - try f x - with Exit -> () - with _ -> () diff --git a/tests/passing/lwt.ml.opts b/tests/passing/lwt.ml.opts deleted file mode 100644 index cf245345..00000000 --- a/tests/passing/lwt.ml.opts +++ /dev/null @@ -1 +0,0 @@ ---syntax lwt diff --git a/tests/passing/lwt.t b/tests/passing/lwt.t new file mode 100644 index 00000000..e15ba74b --- /dev/null +++ b/tests/passing/lwt.t @@ -0,0 +1,53 @@ + + $ cat > lwt.ml << "EOF" + > let f () = + > lwt x = g () in + > Lwt.return x + > + > let f x = match_lwt x with + > | A -> A + > | B -> B + > + > let g x = try_lwt + > f x + > finally + > g x + > + > let a f x = + > try_lwt f x + > with Failure _ -> () + > finally () + > + > (* should'nt break normal try/with imbrication *) + > let z f x = + > try + > try f x + > with Exit -> () + > with _ -> () + > EOF + + $ ocp-indent --syntax lwt lwt.ml + let f () = + lwt x = g () in + Lwt.return x + + let f x = match_lwt x with + | A -> A + | B -> B + + let g x = try_lwt + f x + finally + g x + + let a f x = + try_lwt f x + with Failure _ -> () + finally () + + (* should'nt break normal try/with imbrication *) + let z f x = + try + try f x + with Exit -> () + with _ -> () diff --git a/tests/passing/macro.ml b/tests/passing/macro.ml deleted file mode 100644 index 3bdcf293..00000000 --- a/tests/passing/macro.ml +++ /dev/null @@ -1,10 +0,0 @@ -open Foo - -INCLUDE "bar" - -IFDEF "foo" -let f x = 3 -ENDIF - -TEST foo -TEST bar diff --git a/tests/passing/macro.t b/tests/passing/macro.t new file mode 100644 index 00000000..874740f0 --- /dev/null +++ b/tests/passing/macro.t @@ -0,0 +1,25 @@ + + $ cat > macro.ml << "EOF" + > open Foo + > + > INCLUDE "bar" + > + > IFDEF "foo" + > let f x = 3 + > ENDIF + > + > TEST foo + > TEST bar + > EOF + + $ ocp-indent macro.ml + open Foo + + INCLUDE "bar" + + IFDEF "foo" + let f x = 3 + ENDIF + + TEST foo + TEST bar diff --git a/tests/passing/match_fun.ml b/tests/passing/match_fun.ml deleted file mode 100644 index 800a0cf1..00000000 --- a/tests/passing/match_fun.ml +++ /dev/null @@ -1,4 +0,0 @@ -let reset_cond = - match states with - | [ _ ] -> fun _ v _ -> e_id v - | _ -> fun s v clk -> (* … *) diff --git a/tests/passing/match_fun.t b/tests/passing/match_fun.t new file mode 100644 index 00000000..c4d8f787 --- /dev/null +++ b/tests/passing/match_fun.t @@ -0,0 +1,13 @@ + + $ cat > match_fun.ml << "EOF" + > let reset_cond = + > match states with + > | [ _ ] -> fun _ v _ -> e_id v + > | _ -> fun s v clk -> (* … *) + > EOF + + $ ocp-indent match_fun.ml + let reset_cond = + match states with + | [ _ ] -> fun _ v _ -> e_id v + | _ -> fun s v clk -> (* … *) diff --git a/tests/passing/misc-2018.ml b/tests/passing/misc-2018.ml deleted file mode 100644 index 29e21a55..00000000 --- a/tests/passing/misc-2018.ml +++ /dev/null @@ -1,93 +0,0 @@ -(* #183 *) - -type 'a repr = -| Bytes of ('a -> string) -| Int of ('a -> int) -| Int32 of ('a -> int32) -| Int64 of ('a -> int64) -| Float of ('a -> float) - -let bytes_of_repr = function -| Bytes b -> fun v -> b v -| Int i -> fun v -> R_byte_sort.of_int (i v) -| Int32 i -> fun v -> R_byte_sort.of_int32 (i v) -| Int64 i -> fun v -> R_byte_sort.of_int64 (i v) -| Float f -> fun v -> R_byte_sort.of_float (f v) - -(* #265 *) - -let _ = ( a - ; - b - ) - -let _ = { - a - ; - b -} - -let f x = - ( foo - ; - bar ) - -let _ = ( a - ; (* foo *) - b - ) - -let _ = { - a - ; (* foo *) - b -} - -let f x = - ( foo - ; (* foo *) - bar ) - -(* #224 *) -let () = - begin [@attribute] - print_endline "hello"; - print_endline "world"; - end - -(* #188 *) -let f : t1 -> t2 -> t3 = - fun x y z -> - x + y + z - -(* #257 *) -module M = struct - type a = A of b [@@deriving compare] - and b = B of a -end - -(* #275 *) -let g x = - (x * x - [@ocaml.ppwarning "TODO: blabla"]) - -let h = "I am well indented" - -let i x = - x * x - [@ocaml.ppwarning "TODO: blabla"] - -let j = "I am NOT well indented" - -(* #277 *) -module V = struct - type t = - | A of A.t [@blah "a"] - | B of B.t [@blah "b"] - | C of C.t [@blah "c"] -end - -let foo = - let f x = - foo bar [@@bla] in - zz diff --git a/tests/passing/misc-2018.ml.opts b/tests/passing/misc-2018.ml.opts deleted file mode 100644 index 160044cc..00000000 --- a/tests/passing/misc-2018.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c strict_with=always,with=0 diff --git a/tests/passing/misc-2018.t b/tests/passing/misc-2018.t new file mode 100644 index 00000000..281cba6c --- /dev/null +++ b/tests/passing/misc-2018.t @@ -0,0 +1,191 @@ + + $ cat > misc-2018.ml << "EOF" + > (* #183 *) + > + > type 'a repr = + > | Bytes of ('a -> string) + > | Int of ('a -> int) + > | Int32 of ('a -> int32) + > | Int64 of ('a -> int64) + > | Float of ('a -> float) + > + > let bytes_of_repr = function + > | Bytes b -> fun v -> b v + > | Int i -> fun v -> R_byte_sort.of_int (i v) + > | Int32 i -> fun v -> R_byte_sort.of_int32 (i v) + > | Int64 i -> fun v -> R_byte_sort.of_int64 (i v) + > | Float f -> fun v -> R_byte_sort.of_float (f v) + > + > (* #265 *) + > + > let _ = ( a + > ; + > b + > ) + > + > let _ = { + > a + > ; + > b + > } + > + > let f x = + > ( foo + > ; + > bar ) + > + > let _ = ( a + > ; (* foo *) + > b + > ) + > + > let _ = { + > a + > ; (* foo *) + > b + > } + > + > let f x = + > ( foo + > ; (* foo *) + > bar ) + > + > (* #224 *) + > let () = + > begin [@attribute] + > print_endline "hello"; + > print_endline "world"; + > end + > + > (* #188 *) + > let f : t1 -> t2 -> t3 = + > fun x y z -> + > x + y + z + > + > (* #257 *) + > module M = struct + > type a = A of b [@@deriving compare] + > and b = B of a + > end + > + > (* #275 *) + > let g x = + > (x * x + > [@ocaml.ppwarning "TODO: blabla"]) + > + > let h = "I am well indented" + > + > let i x = + > x * x + > [@ocaml.ppwarning "TODO: blabla"] + > + > let j = "I am NOT well indented" + > + > (* #277 *) + > module V = struct + > type t = + > | A of A.t [@blah "a"] + > | B of B.t [@blah "b"] + > | C of C.t [@blah "c"] + > end + > + > let foo = + > let f x = + > foo bar [@@bla] in + > zz + > EOF + + $ ocp-indent -c strict_with=always,with=0 misc-2018.ml + (* #183 *) + + type 'a repr = + | Bytes of ('a -> string) + | Int of ('a -> int) + | Int32 of ('a -> int32) + | Int64 of ('a -> int64) + | Float of ('a -> float) + + let bytes_of_repr = function + | Bytes b -> fun v -> b v + | Int i -> fun v -> R_byte_sort.of_int (i v) + | Int32 i -> fun v -> R_byte_sort.of_int32 (i v) + | Int64 i -> fun v -> R_byte_sort.of_int64 (i v) + | Float f -> fun v -> R_byte_sort.of_float (f v) + + (* #265 *) + + let _ = ( a + ; + b + ) + + let _ = { + a + ; + b + } + + let f x = + ( foo + ; + bar ) + + let _ = ( a + ; (* foo *) + b + ) + + let _ = { + a + ; (* foo *) + b + } + + let f x = + ( foo + ; (* foo *) + bar ) + + (* #224 *) + let () = + begin [@attribute] + print_endline "hello"; + print_endline "world"; + end + + (* #188 *) + let f : t1 -> t2 -> t3 = + fun x y z -> + x + y + z + + (* #257 *) + module M = struct + type a = A of b [@@deriving compare] + and b = B of a + end + + (* #275 *) + let g x = + (x * x + [@ocaml.ppwarning "TODO: blabla"]) + + let h = "I am well indented" + + let i x = + x * x + [@ocaml.ppwarning "TODO: blabla"] + + let j = "I am NOT well indented" + + (* #277 *) + module V = struct + type t = + | A of A.t [@blah "a"] + | B of B.t [@blah "b"] + | C of C.t [@blah "c"] + end + + let foo = + let f x = + foo bar [@@bla] in + zz diff --git a/tests/passing/misc-2019.ml b/tests/passing/misc-2019.ml deleted file mode 100644 index 892725de..00000000 --- a/tests/passing/misc-2019.ml +++ /dev/null @@ -1,85 +0,0 @@ -module Unsafe_blit = struct - external unsafe_blit - : src:t_ - -> src_pos:int - -> dst:t_ - -> dst_pos:int - -> len:int - -> unit - = "core_array_unsafe_int_blit" - [@@noalloc] -end - -(** @open *) -include - module type of struct - include Base.Array - end - with type 'a t := 'a t - -(** Return the class of the given floating-point number: - normal, subnormal, zero, infinite, or not a number. *) -external classify_float - : (float[@unboxed]) - -> fpclass - = "caml_classify_float" "caml_classify_float_unboxed" -[@@noalloc] [@@deprecated "[since 2014-10] Use [Float.classify]"] - -(** {6 String operations} - - More string operations are provided in module {!String}. -*) - -(** String concatenation. *) -val ( ^ ) : string -> string -> string - -module V1 = struct - type t = Xxxxxxxxxxxxxxxx.t = - { xxxxxxxxxxxxxxxxxxxx : Xxxxxxxxxxxxxx.t - [@default Xxxxxxxxxxxxxx.empty] - [@sexp_drop_if Xxxxxxxxxxxxxx.is_empty] - } - [@@deriving bin_io, sexp] -end - -module M = struct - - include Validate (struct type nonrec t = t [@@deriving_inline compare, sexp_of] - let compare : t -> t -> int = compare - let sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t = sexp_of_t - [@@@end] end) -end - -type t = | -let x = () - -(* nested [open struct] (#300) *) -include struct - open struct - include String - end - let get = get -end - -(* cinaps comments (#299) *) -let _ = - (*$ - let f = function - | Some x -> x - | None -> 0 - in - print_endline - ";;" - *) - () - -(* and+ mis-indented (#292) *) -let (and+) x y = - match x,y with - | Some x, Some y -> Some (x, y) - | _ -> None - -module Infix : sig - val (and+) : ('a, 'error) result -> ('b, 'error) result -> ('a * 'b, 'error) result - val (let+) : ('a, 'error) result -> ('a -> 'b) -> ('b, 'error) result -end diff --git a/tests/passing/misc-2019.ml.opts b/tests/passing/misc-2019.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/misc-2019.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/misc-2019.t b/tests/passing/misc-2019.t new file mode 100644 index 00000000..7a7f51f2 --- /dev/null +++ b/tests/passing/misc-2019.t @@ -0,0 +1,175 @@ + + $ cat > misc-2019.ml << "EOF" + > module Unsafe_blit = struct + > external unsafe_blit + > : src:t_ + > -> src_pos:int + > -> dst:t_ + > -> dst_pos:int + > -> len:int + > -> unit + > = "core_array_unsafe_int_blit" + > [@@noalloc] + > end + > + > (** @open *) + > include + > module type of struct + > include Base.Array + > end + > with type 'a t := 'a t + > + > (** Return the class of the given floating-point number: + > normal, subnormal, zero, infinite, or not a number. *) + > external classify_float + > : (float[@unboxed]) + > -> fpclass + > = "caml_classify_float" "caml_classify_float_unboxed" + > [@@noalloc] [@@deprecated "[since 2014-10] Use [Float.classify]"] + > + > (** {6 String operations} + > + > More string operations are provided in module {!String}. + > *) + > + > (** String concatenation. *) + > val ( ^ ) : string -> string -> string + > + > module V1 = struct + > type t = Xxxxxxxxxxxxxxxx.t = + > { xxxxxxxxxxxxxxxxxxxx : Xxxxxxxxxxxxxx.t + > [@default Xxxxxxxxxxxxxx.empty] + > [@sexp_drop_if Xxxxxxxxxxxxxx.is_empty] + > } + > [@@deriving bin_io, sexp] + > end + > + > module M = struct + > + > include Validate (struct type nonrec t = t [@@deriving_inline compare, sexp_of] + > let compare : t -> t -> int = compare + > let sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t = sexp_of_t + > [@@@end] end) + > end + > + > type t = | + > let x = () + > + > (* nested [open struct] (#300) *) + > include struct + > open struct + > include String + > end + > let get = get + > end + > + > (* cinaps comments (#299) *) + > let _ = + > (*$ + > let f = function + > | Some x -> x + > | None -> 0 + > in + > print_endline + > ";;" + > *) + > () + > + > (* and+ mis-indented (#292) *) + > let (and+) x y = + > match x,y with + > | Some x, Some y -> Some (x, y) + > | _ -> None + > + > module Infix : sig + > val (and+) : ('a, 'error) result -> ('b, 'error) result -> ('a * 'b, 'error) result + > val (let+) : ('a, 'error) result -> ('a -> 'b) -> ('b, 'error) result + > end + > EOF + + $ ocp-indent -c JaneStreet misc-2019.ml + module Unsafe_blit = struct + external unsafe_blit + : src:t_ + -> src_pos:int + -> dst:t_ + -> dst_pos:int + -> len:int + -> unit + = "core_array_unsafe_int_blit" + [@@noalloc] + end + + (** @open *) + include + module type of struct + include Base.Array + end + with type 'a t := 'a t + + (** Return the class of the given floating-point number: + normal, subnormal, zero, infinite, or not a number. *) + external classify_float + : (float[@unboxed]) + -> fpclass + = "caml_classify_float" "caml_classify_float_unboxed" + [@@noalloc] [@@deprecated "[since 2014-10] Use [Float.classify]"] + + (** {6 String operations} + + More string operations are provided in module {!String}. + *) + + (** String concatenation. *) + val ( ^ ) : string -> string -> string + + module V1 = struct + type t = Xxxxxxxxxxxxxxxx.t = + { xxxxxxxxxxxxxxxxxxxx : Xxxxxxxxxxxxxx.t + [@default Xxxxxxxxxxxxxx.empty] + [@sexp_drop_if Xxxxxxxxxxxxxx.is_empty] + } + [@@deriving bin_io, sexp] + end + + module M = struct + + include Validate (struct type nonrec t = t [@@deriving_inline compare, sexp_of] + let compare : t -> t -> int = compare + let sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t = sexp_of_t + [@@@end] end) + end + + type t = | + let x = () + + (* nested [open struct] (#300) *) + include struct + open struct + include String + end + let get = get + end + + (* cinaps comments (#299) *) + let _ = + (*$ + let f = function + | Some x -> x + | None -> 0 + in + print_endline + ";;" + *) + () + + (* and+ mis-indented (#292) *) + let (and+) x y = + match x,y with + | Some x, Some y -> Some (x, y) + | _ -> None + + module Infix : sig + val (and+) : ('a, 'error) result -> ('b, 'error) result -> ('a * 'b, 'error) result + val (let+) : ('a, 'error) result -> ('a -> 'b) -> ('b, 'error) result + end diff --git a/tests/passing/module.ml b/tests/passing/module.ml deleted file mode 100644 index b23902a2..00000000 --- a/tests/passing/module.ml +++ /dev/null @@ -1,66 +0,0 @@ -module M (S : S) = - F.Make(struct - module G = struct - type t - include Foo with type t := t - include Bar with type t := t - end - end) - -module M = -struct - type t -end - -module Update : sig - val f : ('a, 'b) t -> 'a -> unit - val g : ('a, 'b) t -> 'a -> unit - module M : C with type k = t - module G : C with type k := f - type t -end = struct - type t = int -end - -module M : S - with type t = x - and type t' = y - and type t' = y -= -struct - type t = int -end - -module M : S with type t = x - and type t' = y - and type t' = y -= struct - type t = int -end - -module Make: functor (M : T) -> sig - val f : int -> int - val g : int -> int -end - -let _ = (module struct -end) - -let _ = - let _ = (module struct - foo - end) - -include (Bad : (module type of M - with module N = O)) - -val debatable : (module Module.Sub - with type t1 = t1' - and type t2 = t2') - -module Store (K: API.KEY) (V: API.VALUE) : - API.STORE with module K = K - and module V = V = -struct - - module K = K diff --git a/tests/passing/module.t b/tests/passing/module.t new file mode 100644 index 00000000..ef82eb52 --- /dev/null +++ b/tests/passing/module.t @@ -0,0 +1,137 @@ + + $ cat > module.ml << "EOF" + > module M (S : S) = + > F.Make(struct + > module G = struct + > type t + > include Foo with type t := t + > include Bar with type t := t + > end + > end) + > + > module M = + > struct + > type t + > end + > + > module Update : sig + > val f : ('a, 'b) t -> 'a -> unit + > val g : ('a, 'b) t -> 'a -> unit + > module M : C with type k = t + > module G : C with type k := f + > type t + > end = struct + > type t = int + > end + > + > module M : S + > with type t = x + > and type t' = y + > and type t' = y + > = + > struct + > type t = int + > end + > + > module M : S with type t = x + > and type t' = y + > and type t' = y + > = struct + > type t = int + > end + > + > module Make: functor (M : T) -> sig + > val f : int -> int + > val g : int -> int + > end + > + > let _ = (module struct + > end) + > + > let _ = + > let _ = (module struct + > foo + > end) + > + > include (Bad : (module type of M + > with module N = O)) + > + > val debatable : (module Module.Sub + > with type t1 = t1' + > and type t2 = t2') + > + > module Store (K: API.KEY) (V: API.VALUE) : + > API.STORE with module K = K + > and module V = V = + > struct + > + > module K = K + > EOF + + $ ocp-indent module.ml + module M (S : S) = + F.Make(struct + module G = struct + type t + include Foo with type t := t + include Bar with type t := t + end + end) + + module M = + struct + type t + end + + module Update : sig + val f : ('a, 'b) t -> 'a -> unit + val g : ('a, 'b) t -> 'a -> unit + module M : C with type k = t + module G : C with type k := f + type t + end = struct + type t = int + end + + module M : S + with type t = x + and type t' = y + and type t' = y + = + struct + type t = int + end + + module M : S with type t = x + and type t' = y + and type t' = y + = struct + type t = int + end + + module Make: functor (M : T) -> sig + val f : int -> int + val g : int -> int + end + + let _ = (module struct + end) + + let _ = + let _ = (module struct + foo + end) + + include (Bad : (module type of M + with module N = O)) + + val debatable : (module Module.Sub + with type t1 = t1' + and type t2 = t2') + + module Store (K: API.KEY) (V: API.VALUE) : + API.STORE with module K = K + and module V = V = + struct + + module K = K diff --git a/tests/passing/multiline.ml b/tests/passing/multiline.ml deleted file mode 100644 index 32fae8d9..00000000 --- a/tests/passing/multiline.ml +++ /dev/null @@ -1,28 +0,0 @@ -let _ = - (* multiline-comments - can be troublesome: - let x = - let y = - f z - in y - indented code should be kept as is *) - () - -let _ = (* what about multi-line - comments that don't start a line ? - *) - w - -let s1 = "a b c d - e f g h - i j k" - -let s2 = "a b c d \ - e f g h \ - i j k\ - \ l" - -let s3 = "a b c d \ - e f g h - i j k \ - l m" diff --git a/tests/passing/multiline.t b/tests/passing/multiline.t new file mode 100644 index 00000000..56f0a0fe --- /dev/null +++ b/tests/passing/multiline.t @@ -0,0 +1,61 @@ + + $ cat > multiline.ml << "EOF" + > let _ = + > (* multiline-comments + > can be troublesome: + > let x = + > let y = + > f z + > in y + > indented code should be kept as is *) + > () + > + > let _ = (* what about multi-line + > comments that don't start a line ? + > *) + > w + > + > let s1 = "a b c d + > e f g h + > i j k" + > + > let s2 = "a b c d \ + > e f g h \ + > i j k\ + > \ l" + > + > let s3 = "a b c d \ + > e f g h + > i j k \ + > l m" + > EOF + + $ ocp-indent multiline.ml + let _ = + (* multiline-comments + can be troublesome: + let x = + let y = + f z + in y + indented code should be kept as is *) + () + + let _ = (* what about multi-line + comments that don't start a line ? + *) + w + + let s1 = "a b c d + e f g h + i j k" + + let s2 = "a b c d \ + e f g h \ + i j k\ + \ l" + + let s3 = "a b c d \ + e f g h + i j k \ + l m" diff --git a/tests/passing/nested_variants.ml b/tests/passing/nested_variants.ml deleted file mode 100644 index fae1ffcb..00000000 --- a/tests/passing/nested_variants.ml +++ /dev/null @@ -1,18 +0,0 @@ -type tt = - | A of - int - | B of - string - | C of - float - | D of - char - -type tt = [ - | `a of int - | `blskdjf of - float - | `problem_cause of [ `more_brackets ] - | `problematic_case of - string -] diff --git a/tests/passing/nested_variants.t b/tests/passing/nested_variants.t new file mode 100644 index 00000000..122178a7 --- /dev/null +++ b/tests/passing/nested_variants.t @@ -0,0 +1,41 @@ + + $ cat > nested_variants.ml << "EOF" + > type tt = + > | A of + > int + > | B of + > string + > | C of + > float + > | D of + > char + > + > type tt = [ + > | `a of int + > | `blskdjf of + > float + > | `problem_cause of [ `more_brackets ] + > | `problematic_case of + > string + > ] + > EOF + + $ ocp-indent nested_variants.ml + type tt = + | A of + int + | B of + string + | C of + float + | D of + char + + type tt = [ + | `a of int + | `blskdjf of + float + | `problem_cause of [ `more_brackets ] + | `problematic_case of + string + ] diff --git a/tests/passing/nesting.ml b/tests/passing/nesting.ml deleted file mode 100644 index b4dbd34b..00000000 --- a/tests/passing/nesting.ml +++ /dev/null @@ -1,34 +0,0 @@ -module M = struct - let a = (((((( - ) - ) - ) - ) - ) - ) - - let a = (ff(ff(ff(ff(ff(ff( - ) - ) - ) - ) - ) - ) - ) - - let a = [[[[[[ - ] - ] - ] - ] - ] - ] - - let a = [ff[ff[ff[ff[ff[ff[ - ] - ] - ] - ] - ] - ] - ] diff --git a/tests/passing/nesting.t b/tests/passing/nesting.t new file mode 100644 index 00000000..e31f9038 --- /dev/null +++ b/tests/passing/nesting.t @@ -0,0 +1,73 @@ + + $ cat > nesting.ml << "EOF" + > module M = struct + > let a = (((((( + > ) + > ) + > ) + > ) + > ) + > ) + > + > let a = (ff(ff(ff(ff(ff(ff( + > ) + > ) + > ) + > ) + > ) + > ) + > ) + > + > let a = [[[[[[ + > ] + > ] + > ] + > ] + > ] + > ] + > + > let a = [ff[ff[ff[ff[ff[ff[ + > ] + > ] + > ] + > ] + > ] + > ] + > ] + > EOF + + $ ocp-indent nesting.ml + module M = struct + let a = (((((( + ) + ) + ) + ) + ) + ) + + let a = (ff(ff(ff(ff(ff(ff( + ) + ) + ) + ) + ) + ) + ) + + let a = [[[[[[ + ] + ] + ] + ] + ] + ] + + let a = [ff[ff[ff[ff[ff[ff[ + ] + ] + ] + ] + ] + ] + ] diff --git a/tests/passing/never_align.ml b/tests/passing/never_align.ml deleted file mode 100644 index 7eb0760f..00000000 --- a/tests/passing/never_align.ml +++ /dev/null @@ -1,20 +0,0 @@ -let _ = ( - a - b - c -) - -let _ = (a - b - c) - -let _ = { - a - b - b -} - -let _ = { a - b - c -} diff --git a/tests/passing/never_align.ml.opts b/tests/passing/never_align.ml.opts deleted file mode 100644 index f29e2f42..00000000 --- a/tests/passing/never_align.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c align_params=never diff --git a/tests/passing/never_align.t b/tests/passing/never_align.t new file mode 100644 index 00000000..20d93fc0 --- /dev/null +++ b/tests/passing/never_align.t @@ -0,0 +1,45 @@ + + $ cat > never_align.ml << "EOF" + > let _ = ( + > a + > b + > c + > ) + > + > let _ = (a + > b + > c) + > + > let _ = { + > a + > b + > b + > } + > + > let _ = { a + > b + > c + > } + > EOF + + $ ocp-indent -c align_params=never never_align.ml + let _ = ( + a + b + c + ) + + let _ = (a + b + c) + + let _ = { + a + b + b + } + + let _ = { a + b + c + } diff --git a/tests/passing/object.ml b/tests/passing/object.ml deleted file mode 100644 index 4a6ecabb..00000000 --- a/tests/passing/object.ml +++ /dev/null @@ -1,24 +0,0 @@ -let x = - object - inherit foo - method bar = _ - end - -class foo = - object - method x = 2 - inherit bar - end - -class foo = - object(this) - inherit bar - end - -class virtual map = object - method visit_expr_node : - 'env 'info_0 'info_1 . - ('env -> 'info_0 -> 'info_1) -> - 'env -> 'info_0 expr_node -> 'info_1 expr_node = - assert false -end diff --git a/tests/passing/object.t b/tests/passing/object.t new file mode 100644 index 00000000..985b136e --- /dev/null +++ b/tests/passing/object.t @@ -0,0 +1,53 @@ + + $ cat > object.ml << "EOF" + > let x = + > object + > inherit foo + > method bar = _ + > end + > + > class foo = + > object + > method x = 2 + > inherit bar + > end + > + > class foo = + > object(this) + > inherit bar + > end + > + > class virtual map = object + > method visit_expr_node : + > 'env 'info_0 'info_1 . + > ('env -> 'info_0 -> 'info_1) -> + > 'env -> 'info_0 expr_node -> 'info_1 expr_node = + > assert false + > end + > EOF + + $ ocp-indent object.ml + let x = + object + inherit foo + method bar = _ + end + + class foo = + object + method x = 2 + inherit bar + end + + class foo = + object(this) + inherit bar + end + + class virtual map = object + method visit_expr_node : + 'env 'info_0 'info_1 . + ('env -> 'info_0 -> 'info_1) -> + 'env -> 'info_0 expr_node -> 'info_1 expr_node = + assert false + end diff --git a/tests/passing/obuild.ml b/tests/passing/obuild.ml deleted file mode 100644 index b2ac58bf..00000000 --- a/tests/passing/obuild.ml +++ /dev/null @@ -1,10 +0,0 @@ -type predicate = - Pred_Byte - | Pred_Native - | Pred_Toploop - -let _ = - { pkg with - package_version = projFile.version - ; package_description = _ - ; package_requires = [] } diff --git a/tests/passing/obuild.ml.opts b/tests/passing/obuild.ml.opts deleted file mode 100644 index cc6b7976..00000000 --- a/tests/passing/obuild.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c base=2,type=2,match_clause=4,with=2 diff --git a/tests/passing/obuild.t b/tests/passing/obuild.t new file mode 100644 index 00000000..a61dbc97 --- /dev/null +++ b/tests/passing/obuild.t @@ -0,0 +1,25 @@ + + $ cat > obuild.ml << "EOF" + > type predicate = + > Pred_Byte + > | Pred_Native + > | Pred_Toploop + > + > let _ = + > { pkg with + > package_version = projFile.version + > ; package_description = _ + > ; package_requires = [] } + > EOF + + $ ocp-indent -c base=2,type=2,match_clause=4,with=2 obuild.ml + type predicate = + Pred_Byte + | Pred_Native + | Pred_Toploop + + let _ = + { pkg with + package_version = projFile.version + ; package_description = _ + ; package_requires = [] } diff --git a/tests/passing/ocamldoc.ml b/tests/passing/ocamldoc.ml deleted file mode 100644 index 72c5750a..00000000 --- a/tests/passing/ocamldoc.ml +++ /dev/null @@ -1,199 +0,0 @@ -(** From http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual029.html#htoc172 - The first special comment of the file is the comment associated - with the whole module.*) - - -(** Special comments can be placed between elements and are kept - by the OCamldoc tool, but are not associated to any element. - @-tags in these comments are ignored.*) - -(*******************************************************************) -(** Comments like the one above, with more than two asterisks, - are ignored. *) - -(** The comment for function f. *) -val f : int -> int -> int -(** The continuation of the comment for function f. *) - -(** Comment for exception My_exception, even with a simple comment - between the special comment and the exception.*) -(* Hello, I'm a simple comment :-) *) -exception My_exception of (int -> int) * int - -(** Comment for type weather *) -type weather = - | Rain of int (** The comment for construtor Rain *) - | Sun (** The comment for constructor Sun *) - -(** Comment for type weather2 *) -type weather2 = - | Rain of int (** The comment for construtor Rain *) - | Sun (** The comment for constructor Sun *) -(** I can continue the comment for type weather2 here - because there is already a comment associated to the last constructor.*) - -(** The comment for type my_record *) -type my_record = - { - foo : int ; (** Comment for field foo *) - bar : string ; (** Comment for field bar *) - } -(** Continuation of comment for type my_record *) - -(** Comment for foo *) -val foo : string -(** This comment is associated to foo and not to bar. *) -val bar : string -(** This comment is assciated to bar. *) - -(** The comment for class my_class *) -class my_class : - object - (** A comment to describe inheritance from cl *) - inherit cl - - (** The comment for attribute tutu *) - val mutable tutu : string - - (** The comment for attribute toto. *) - val toto : int - - (** This comment is not attached to titi since - there is a blank line before titi, but is kept - as a comment in the class. *) - - val titi : string - - (** Comment for method toto *) - method toto : string - - (** Comment for method m *) - method m : float -> int - end - -(** The comment for the class type my_class_type *) -class type my_class_type = - object - (** The comment for variable x. *) - val mutable x : int - - (** The commend for method m. *) - method m : int -> int - end - -(** The comment for module Foo *) -module Foo = -struct - (** The comment for x *) - val x : int - - (** A special comment that is kept but not associated to any element *) -end - -(** The comment for module type my_module_type. *) -module type my_module_type = -sig - (** The comment for value x. *) - val x : int - - (** The comment for module M. *) - module M = - struct - (** The comment for value y. *) - val y : int - - (* ... *) - end - -end - -(** The comment for class my_class *) -class my_class = - object - (** A comment to describe inheritance from cl *) - inherit cl - - (** The comment for the instance variable tutu *) - val mutable tutu = "tutu" - (** The comment for toto *) - val toto = 1 - val titi = "titi" - (** Comment for method toto *) - method toto = tutu ^ "!" - (** Comment for method m *) - method m (f : float) = 1 - end - -(** The comment for class type my_class_type *) -class type my_class_type = - object - (** The comment for the instance variable x. *) - val mutable x : int - (** The commend for method m. *) - method m : int -> int - end - -(** The comment for module Foo *) -module Foo = -struct - (** The comment for x *) - val x : int - (** A special comment in the class, but not associated to any element. *) -end - -(** The comment for module type my_module_type. *) -module type my_module_type = -sig - (* Comment for value x. *) - val x : int - (* ... *) -end - -(** Starting bla doc *) -type bla = - | Hup (** The hup case *) - | Hap (** The hap case *) -(** Ending bla doc *) - -(** Starting bla doc *) -type bla = - | Hup - (** The hup case *) - | Hap - (** The hap case *) -(** Ending bla doc *) - -type hop -(** Hop's documentation *) - -type mip = - { fup : int; (** fup field *) - fip : int; (** fip field *) } -(** Mip's documentation *) - -type t = Hey | Ho -(** Let's go. *) - -type tp = [ `Hey | `Ho ] -(** Tp doc. - Second line. *) - -(** Starting function f doc *) -val f : 'a -> 'b -(** Ending function f doc. *) - -val g : 'a -> t -(** Function g doc. - Second line. *) - -val g : 'a -> [`Hey | `Ho ] -(** Let's go - Second line. *) - -val x : unit -> unit -(** Here are a couple examples of some of its many uses - - {v step (fun m v -> m ~foo:v) - +> flag "-foo" no_arg : (foo:bool -> 'm, 'm) t - v} -*) diff --git a/tests/passing/ocamldoc.t b/tests/passing/ocamldoc.t new file mode 100644 index 00000000..bf9dd1db --- /dev/null +++ b/tests/passing/ocamldoc.t @@ -0,0 +1,403 @@ + + $ cat > ocamldoc.ml << "EOF" + > (** From http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual029.html#htoc172 + > The first special comment of the file is the comment associated + > with the whole module.*) + > + > + > (** Special comments can be placed between elements and are kept + > by the OCamldoc tool, but are not associated to any element. + > @-tags in these comments are ignored.*) + > + > (*******************************************************************) + > (** Comments like the one above, with more than two asterisks, + > are ignored. *) + > + > (** The comment for function f. *) + > val f : int -> int -> int + > (** The continuation of the comment for function f. *) + > + > (** Comment for exception My_exception, even with a simple comment + > between the special comment and the exception.*) + > (* Hello, I'm a simple comment :-) *) + > exception My_exception of (int -> int) * int + > + > (** Comment for type weather *) + > type weather = + > | Rain of int (** The comment for construtor Rain *) + > | Sun (** The comment for constructor Sun *) + > + > (** Comment for type weather2 *) + > type weather2 = + > | Rain of int (** The comment for construtor Rain *) + > | Sun (** The comment for constructor Sun *) + > (** I can continue the comment for type weather2 here + > because there is already a comment associated to the last constructor.*) + > + > (** The comment for type my_record *) + > type my_record = + > { + > foo : int ; (** Comment for field foo *) + > bar : string ; (** Comment for field bar *) + > } + > (** Continuation of comment for type my_record *) + > + > (** Comment for foo *) + > val foo : string + > (** This comment is associated to foo and not to bar. *) + > val bar : string + > (** This comment is assciated to bar. *) + > + > (** The comment for class my_class *) + > class my_class : + > object + > (** A comment to describe inheritance from cl *) + > inherit cl + > + > (** The comment for attribute tutu *) + > val mutable tutu : string + > + > (** The comment for attribute toto. *) + > val toto : int + > + > (** This comment is not attached to titi since + > there is a blank line before titi, but is kept + > as a comment in the class. *) + > + > val titi : string + > + > (** Comment for method toto *) + > method toto : string + > + > (** Comment for method m *) + > method m : float -> int + > end + > + > (** The comment for the class type my_class_type *) + > class type my_class_type = + > object + > (** The comment for variable x. *) + > val mutable x : int + > + > (** The commend for method m. *) + > method m : int -> int + > end + > + > (** The comment for module Foo *) + > module Foo = + > struct + > (** The comment for x *) + > val x : int + > + > (** A special comment that is kept but not associated to any element *) + > end + > + > (** The comment for module type my_module_type. *) + > module type my_module_type = + > sig + > (** The comment for value x. *) + > val x : int + > + > (** The comment for module M. *) + > module M = + > struct + > (** The comment for value y. *) + > val y : int + > + > (* ... *) + > end + > + > end + > + > (** The comment for class my_class *) + > class my_class = + > object + > (** A comment to describe inheritance from cl *) + > inherit cl + > + > (** The comment for the instance variable tutu *) + > val mutable tutu = "tutu" + > (** The comment for toto *) + > val toto = 1 + > val titi = "titi" + > (** Comment for method toto *) + > method toto = tutu ^ "!" + > (** Comment for method m *) + > method m (f : float) = 1 + > end + > + > (** The comment for class type my_class_type *) + > class type my_class_type = + > object + > (** The comment for the instance variable x. *) + > val mutable x : int + > (** The commend for method m. *) + > method m : int -> int + > end + > + > (** The comment for module Foo *) + > module Foo = + > struct + > (** The comment for x *) + > val x : int + > (** A special comment in the class, but not associated to any element. *) + > end + > + > (** The comment for module type my_module_type. *) + > module type my_module_type = + > sig + > (* Comment for value x. *) + > val x : int + > (* ... *) + > end + > + > (** Starting bla doc *) + > type bla = + > | Hup (** The hup case *) + > | Hap (** The hap case *) + > (** Ending bla doc *) + > + > (** Starting bla doc *) + > type bla = + > | Hup + > (** The hup case *) + > | Hap + > (** The hap case *) + > (** Ending bla doc *) + > + > type hop + > (** Hop's documentation *) + > + > type mip = + > { fup : int; (** fup field *) + > fip : int; (** fip field *) } + > (** Mip's documentation *) + > + > type t = Hey | Ho + > (** Let's go. *) + > + > type tp = [ `Hey | `Ho ] + > (** Tp doc. + > Second line. *) + > + > (** Starting function f doc *) + > val f : 'a -> 'b + > (** Ending function f doc. *) + > + > val g : 'a -> t + > (** Function g doc. + > Second line. *) + > + > val g : 'a -> [`Hey | `Ho ] + > (** Let's go + > Second line. *) + > + > val x : unit -> unit + > (** Here are a couple examples of some of its many uses + > + > {v step (fun m v -> m ~foo:v) + > +> flag "-foo" no_arg : (foo:bool -> 'm, 'm) t + > v} + > *) + > EOF + + $ ocp-indent ocamldoc.ml + (** From http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual029.html#htoc172 + The first special comment of the file is the comment associated + with the whole module.*) + + + (** Special comments can be placed between elements and are kept + by the OCamldoc tool, but are not associated to any element. + @-tags in these comments are ignored.*) + + (*******************************************************************) + (** Comments like the one above, with more than two asterisks, + are ignored. *) + + (** The comment for function f. *) + val f : int -> int -> int + (** The continuation of the comment for function f. *) + + (** Comment for exception My_exception, even with a simple comment + between the special comment and the exception.*) + (* Hello, I'm a simple comment :-) *) + exception My_exception of (int -> int) * int + + (** Comment for type weather *) + type weather = + | Rain of int (** The comment for construtor Rain *) + | Sun (** The comment for constructor Sun *) + + (** Comment for type weather2 *) + type weather2 = + | Rain of int (** The comment for construtor Rain *) + | Sun (** The comment for constructor Sun *) + (** I can continue the comment for type weather2 here + because there is already a comment associated to the last constructor.*) + + (** The comment for type my_record *) + type my_record = + { + foo : int ; (** Comment for field foo *) + bar : string ; (** Comment for field bar *) + } + (** Continuation of comment for type my_record *) + + (** Comment for foo *) + val foo : string + (** This comment is associated to foo and not to bar. *) + val bar : string + (** This comment is assciated to bar. *) + + (** The comment for class my_class *) + class my_class : + object + (** A comment to describe inheritance from cl *) + inherit cl + + (** The comment for attribute tutu *) + val mutable tutu : string + + (** The comment for attribute toto. *) + val toto : int + + (** This comment is not attached to titi since + there is a blank line before titi, but is kept + as a comment in the class. *) + + val titi : string + + (** Comment for method toto *) + method toto : string + + (** Comment for method m *) + method m : float -> int + end + + (** The comment for the class type my_class_type *) + class type my_class_type = + object + (** The comment for variable x. *) + val mutable x : int + + (** The commend for method m. *) + method m : int -> int + end + + (** The comment for module Foo *) + module Foo = + struct + (** The comment for x *) + val x : int + + (** A special comment that is kept but not associated to any element *) + end + + (** The comment for module type my_module_type. *) + module type my_module_type = + sig + (** The comment for value x. *) + val x : int + + (** The comment for module M. *) + module M = + struct + (** The comment for value y. *) + val y : int + + (* ... *) + end + + end + + (** The comment for class my_class *) + class my_class = + object + (** A comment to describe inheritance from cl *) + inherit cl + + (** The comment for the instance variable tutu *) + val mutable tutu = "tutu" + (** The comment for toto *) + val toto = 1 + val titi = "titi" + (** Comment for method toto *) + method toto = tutu ^ "!" + (** Comment for method m *) + method m (f : float) = 1 + end + + (** The comment for class type my_class_type *) + class type my_class_type = + object + (** The comment for the instance variable x. *) + val mutable x : int + (** The commend for method m. *) + method m : int -> int + end + + (** The comment for module Foo *) + module Foo = + struct + (** The comment for x *) + val x : int + (** A special comment in the class, but not associated to any element. *) + end + + (** The comment for module type my_module_type. *) + module type my_module_type = + sig + (* Comment for value x. *) + val x : int + (* ... *) + end + + (** Starting bla doc *) + type bla = + | Hup (** The hup case *) + | Hap (** The hap case *) + (** Ending bla doc *) + + (** Starting bla doc *) + type bla = + | Hup + (** The hup case *) + | Hap + (** The hap case *) + (** Ending bla doc *) + + type hop + (** Hop's documentation *) + + type mip = + { fup : int; (** fup field *) + fip : int; (** fip field *) } + (** Mip's documentation *) + + type t = Hey | Ho + (** Let's go. *) + + type tp = [ `Hey | `Ho ] + (** Tp doc. + Second line. *) + + (** Starting function f doc *) + val f : 'a -> 'b + (** Ending function f doc. *) + + val g : 'a -> t + (** Function g doc. + Second line. *) + + val g : 'a -> [`Hey | `Ho ] + (** Let's go + Second line. *) + + val x : unit -> unit + (** Here are a couple examples of some of its many uses + + {v step (fun m v -> m ~foo:v) + +> flag "-foo" no_arg : (foo:bool -> 'm, 'm) t + v} + *) diff --git a/tests/passing/ocamldoc2.ml b/tests/passing/ocamldoc2.ml deleted file mode 100644 index 8c2474f8..00000000 --- a/tests/passing/ocamldoc2.ml +++ /dev/null @@ -1,14 +0,0 @@ -a - (* {[ (* {v *) ]} {v v} *) - b - -let _ = - (* - {[ - while true do - xx - done - (* this is totally crazy !!! *) - ]} - *) - () diff --git a/tests/passing/ocamldoc2.t b/tests/passing/ocamldoc2.t new file mode 100644 index 00000000..fd116cec --- /dev/null +++ b/tests/passing/ocamldoc2.t @@ -0,0 +1,33 @@ + + $ cat > ocamldoc2.ml << "EOF" + > a + > (* {[ (* {v *) ]} {v v} *) + > b + > + > let _ = + > (* + > {[ + > while true do + > xx + > done + > (* this is totally crazy !!! *) + > ]} + > *) + > () + > EOF + + $ ocp-indent ocamldoc2.ml + a + (* {[ (* {v *) ]} {v v} *) + b + + let _ = + (* + {[ + while true do + xx + done + (* this is totally crazy !!! *) + ]} + *) + () diff --git a/tests/passing/partial-match.ml b/tests/passing/partial-match.ml deleted file mode 100644 index 6c6eaafb..00000000 --- a/tests/passing/partial-match.ml +++ /dev/null @@ -1,3 +0,0 @@ -let () = match x with - | `A -> "A" - | `B -> "B" diff --git a/tests/passing/partial-match.ml.opts b/tests/passing/partial-match.ml.opts deleted file mode 100644 index a8cebf00..00000000 --- a/tests/passing/partial-match.ml.opts +++ /dev/null @@ -1 +0,0 @@ ---lines 3- diff --git a/tests/passing/partial-match.t b/tests/passing/partial-match.t new file mode 100644 index 00000000..77a4f182 --- /dev/null +++ b/tests/passing/partial-match.t @@ -0,0 +1,11 @@ + + $ cat > partial-match.ml << "EOF" + > let () = match x with + > | `A -> "A" + > | `B -> "B" + > EOF + + $ ocp-indent --lines 3- partial-match.ml + let () = match x with + | `A -> "A" + | `B -> "B" diff --git a/tests/passing/partial.ml b/tests/passing/partial.ml deleted file mode 100644 index 5efcf777..00000000 --- a/tests/passing/partial.ml +++ /dev/null @@ -1,14 +0,0 @@ - let () = - ffff; - hhhhhh; - fff; - let (quot, _rem) = - let quot_rem n k = - let (d, m) = (n / k, n mod k) in - if d < 0 && m > 0 then (d+1, m-k) -else (d, m) - in - let quot n k = fst (quot_rem n k) in - let rem n k = snd (quot_rem n k) in - -quot, rem diff --git a/tests/passing/partial.ml.opts b/tests/passing/partial.ml.opts deleted file mode 100644 index 74167172..00000000 --- a/tests/passing/partial.ml.opts +++ /dev/null @@ -1 +0,0 @@ ---lines 5-8 diff --git a/tests/passing/partial.t b/tests/passing/partial.t new file mode 100644 index 00000000..8dc1e5de --- /dev/null +++ b/tests/passing/partial.t @@ -0,0 +1,33 @@ + + $ cat > partial.ml << "EOF" + > let () = + > ffff; + > hhhhhh; + > fff; + > let (quot, _rem) = + > let quot_rem n k = + > let (d, m) = (n / k, n mod k) in + > if d < 0 && m > 0 then (d+1, m-k) + > else (d, m) + > in + > let quot n k = fst (quot_rem n k) in + > let rem n k = snd (quot_rem n k) in + > + > quot, rem + > EOF + + $ ocp-indent --lines 5-8 partial.ml + let () = + ffff; + hhhhhh; + fff; + let (quot, _rem) = + let quot_rem n k = + let (d, m) = (n / k, n mod k) in + if d < 0 && m > 0 then (d+1, m-k) + else (d, m) + in + let quot n k = fst (quot_rem n k) in + let rem n k = snd (quot_rem n k) in + + quot, rem diff --git a/tests/passing/partial2.ml b/tests/passing/partial2.ml deleted file mode 100644 index 829e3292..00000000 --- a/tests/passing/partial2.ml +++ /dev/null @@ -1,3 +0,0 @@ -if () then () else - match () with - | () -> diff --git a/tests/passing/partial2.ml.opts b/tests/passing/partial2.ml.opts deleted file mode 100644 index 69eb111d..00000000 --- a/tests/passing/partial2.ml.opts +++ /dev/null @@ -1 +0,0 @@ ---lines 3 -c strict_else=auto diff --git a/tests/passing/partial2.t b/tests/passing/partial2.t new file mode 100644 index 00000000..b06d578c --- /dev/null +++ b/tests/passing/partial2.t @@ -0,0 +1,11 @@ + + $ cat > partial2.ml << "EOF" + > if () then () else + > match () with + > | () -> + > EOF + + $ ocp-indent --lines 3 -c strict_else=auto partial2.ml + if () then () else + match () with + | () -> diff --git a/tests/passing/pattern.ml b/tests/passing/pattern.ml deleted file mode 100644 index 74f54a1d..00000000 --- a/tests/passing/pattern.ml +++ /dev/null @@ -1,68 +0,0 @@ -let f = match x with - | { x = 3 } -> - let x = 4 in - () - -let f = match x with - | (X|Y) | (Z|U) -> 1 - | K -> 2 - -let f = match x with - | X when foo = bar -> - fff - | Y when f = x - && g = 3 -> - z - -let f () = - match s with - (* Parenthesized ident ? *) - | x -> x, d - (* Regular ident *) - | _ -> g -;; - -match x with -| X | Y -> 1 -| X -> - 2; - 3 -| A -> 2 -;; - -let f g = - (* haha *) - match z with - | Z | B _ -> x - | A (a, _, _, b) as x -> - let x = f a and hr = f b in - f - -let unwind_to = - match t with KType | KModule -> true | Kblob -> false - | _ -> true - -let f x = match x with - | A | B - | C -> - x - | z -> match z with - | _ -> function - | x -> - x - -let fun_dep ulam = function - | A - | B - | C -> - () - -let fun_dep ulam = function - |A - |B|C - |D -> - () - -let _ = - (match bla - with bli) diff --git a/tests/passing/pattern.t b/tests/passing/pattern.t new file mode 100644 index 00000000..aad2c3d4 --- /dev/null +++ b/tests/passing/pattern.t @@ -0,0 +1,141 @@ + + $ cat > pattern.ml << "EOF" + > let f = match x with + > | { x = 3 } -> + > let x = 4 in + > () + > + > let f = match x with + > | (X|Y) | (Z|U) -> 1 + > | K -> 2 + > + > let f = match x with + > | X when foo = bar -> + > fff + > | Y when f = x + > && g = 3 -> + > z + > + > let f () = + > match s with + > (* Parenthesized ident ? *) + > | x -> x, d + > (* Regular ident *) + > | _ -> g + > ;; + > + > match x with + > | X | Y -> 1 + > | X -> + > 2; + > 3 + > | A -> 2 + > ;; + > + > let f g = + > (* haha *) + > match z with + > | Z | B _ -> x + > | A (a, _, _, b) as x -> + > let x = f a and hr = f b in + > f + > + > let unwind_to = + > match t with KType | KModule -> true | Kblob -> false + > | _ -> true + > + > let f x = match x with + > | A | B + > | C -> + > x + > | z -> match z with + > | _ -> function + > | x -> + > x + > + > let fun_dep ulam = function + > | A + > | B + > | C -> + > () + > + > let fun_dep ulam = function + > |A + > |B|C + > |D -> + > () + > + > let _ = + > (match bla + > with bli) + > EOF + + $ ocp-indent pattern.ml + let f = match x with + | { x = 3 } -> + let x = 4 in + () + + let f = match x with + | (X|Y) | (Z|U) -> 1 + | K -> 2 + + let f = match x with + | X when foo = bar -> + fff + | Y when f = x + && g = 3 -> + z + + let f () = + match s with + (* Parenthesized ident ? *) + | x -> x, d + (* Regular ident *) + | _ -> g + ;; + + match x with + | X | Y -> 1 + | X -> + 2; + 3 + | A -> 2 + ;; + + let f g = + (* haha *) + match z with + | Z | B _ -> x + | A (a, _, _, b) as x -> + let x = f a and hr = f b in + f + + let unwind_to = + match t with KType | KModule -> true | Kblob -> false + | _ -> true + + let f x = match x with + | A | B + | C -> + x + | z -> match z with + | _ -> function + | x -> + x + + let fun_dep ulam = function + | A + | B + | C -> + () + + let fun_dep ulam = function + |A + |B|C + |D -> + () + + let _ = + (match bla + with bli) diff --git a/tests/passing/ppx-string.ml b/tests/passing/ppx-string.ml deleted file mode 100644 index b0b57c9b..00000000 --- a/tests/passing/ppx-string.ml +++ /dev/null @@ -1,47 +0,0 @@ -let s = {| -|} - -let s = {xx| -xx|} - -let s = - {xx| -|} -|xx} - -let s = {| foo -bar -|} - -let s = {| foo - bar -|} - -let s = {| foo -bar - |} - -let s = - {| -|} - -let s = - {| - |} - -let s = - {| foo -|} - -let s = - {xx| foo - bar - |yy} -baz -|xx} - -let s = - {| -foo bar - baz - |} diff --git a/tests/passing/ppx-string.t b/tests/passing/ppx-string.t new file mode 100644 index 00000000..64745671 --- /dev/null +++ b/tests/passing/ppx-string.t @@ -0,0 +1,99 @@ + + $ cat > ppx-string.ml << "EOF" + > let s = {| + > |} + > + > let s = {xx| + > xx|} + > + > let s = + > {xx| + > |} + > |xx} + > + > let s = {| foo + > bar + > |} + > + > let s = {| foo + > bar + > |} + > + > let s = {| foo + > bar + > |} + > + > let s = + > {| + > |} + > + > let s = + > {| + > |} + > + > let s = + > {| foo + > |} + > + > let s = + > {xx| foo + > bar + > |yy} + > baz + > |xx} + > + > let s = + > {| + > foo bar + > baz + > |} + > EOF + + $ ocp-indent ppx-string.ml + let s = {| + |} + + let s = {xx| + xx|} + + let s = + {xx| + |} + |xx} + + let s = {| foo + bar + |} + + let s = {| foo + bar + |} + + let s = {| foo + bar + |} + + let s = + {| + |} + + let s = + {| + |} + + let s = + {| foo + |} + + let s = + {xx| foo + bar + |yy} + baz + |xx} + + let s = + {| + foo bar + baz + |} diff --git a/tests/passing/ppx_expr_ext.ml b/tests/passing/ppx_expr_ext.ml deleted file mode 100644 index 6929e283..00000000 --- a/tests/passing/ppx_expr_ext.ml +++ /dev/null @@ -1,169 +0,0 @@ -let x = - [%x f 3 ] - -let x = - [%x (f - 3 - 5) ] - -let x = - [%x f - 3 - 5 ] - -let x = - [%xy f - 3 - 5 ] - -let x = - [%x fg - 3 - 5 ] - -let x = - [%x f - 3 - 5 ] - -let x = - [%x - f - 3 - 5 - ] - -let x = - 3 + - [%f f ] - -let x = - [%f f ] * [%f f ] - + - [%f f ] - -let x = - [%f f - 4 - 2 ] - * - [%f f - 3 - 4 ] - -let x = - [%f f - 2 - 3 ] * [%f f - 3 - 4 ] + - [%f f - 2 - 3 ] - -let x = - [%f f - 2 - 3 ] * [%f f - 3 - 4 ] - + [%f f - 2 - 3 ] - -let x = - [%f f - 2 - 3 ] + [%f f - 3 - 4 ] * - [%f f - 2 - 3 ] - -let x = - [%f f - 2 - 3 ] + [%f f - 3 - 4 ] - * [%f f - 2 - 3 ] - -let x = - [%f f - 2 - 3 ] + [%f f - 3 - 4 ] - + [%f f - 2 - 3 ] - - -let x = - [% - f f - 4 - 2 ] - * - [% - f - f - 3 - 4 ] - -let x = - [% - f - .u f - 4 - 2 ] - * - [% - f - .u - f - 3 - 4 ] - -let invariant invariant_a t = - Invariant.invariant [%here] t [%sexp_of: _ t] (fun () -> - let check f = Invariant.check_field t f in - Fields.iter - ~has_any_waiters:(check (fun has_any_waiters -> - if Ivar.has_handlers t.ivar - then (assert has_any_waiters))) - ~ivar:(check (fun ivar -> - Ivar.invariant invariant_a ivar; - assert (Ivar.is_empty ivar)))) -;; - -let core_type_of_decl ~options ~path type_decl = - let typ = Ppx_deriving.core_type_of_type_decl type_decl in - Ppx_deriving.poly_arrow_of_type_decl - (fun var -> [%type: [%t var] -> [%t var] -> Ppx_deriving_runtime.bool]) - type_decl - [%type: [%t typ] -> [%t typ] -> Ppx_deriving_runtime.bool] - -module A = struct - let x = 1 - - let%bench_fun "now" [@indexed i = List.range 0 (List.length zones)] = - let time = now () in - fun () -> of_time time ~zone - - let x = 2 -end - -[%%sig: - module type M = sig - val x : int - end - - module S : module type of - struct - let x = 12 - end -] diff --git a/tests/passing/ppx_expr_ext.ml.opts b/tests/passing/ppx_expr_ext.ml.opts deleted file mode 100644 index cd5c61ce..00000000 --- a/tests/passing/ppx_expr_ext.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c JaneStreet diff --git a/tests/passing/ppx_expr_ext.t b/tests/passing/ppx_expr_ext.t new file mode 100644 index 00000000..afdfb8fa --- /dev/null +++ b/tests/passing/ppx_expr_ext.t @@ -0,0 +1,343 @@ + + $ cat > ppx_expr_ext.ml << "EOF" + > let x = + > [%x f 3 ] + > + > let x = + > [%x (f + > 3 + > 5) ] + > + > let x = + > [%x f + > 3 + > 5 ] + > + > let x = + > [%xy f + > 3 + > 5 ] + > + > let x = + > [%x fg + > 3 + > 5 ] + > + > let x = + > [%x f + > 3 + > 5 ] + > + > let x = + > [%x + > f + > 3 + > 5 + > ] + > + > let x = + > 3 + + > [%f f ] + > + > let x = + > [%f f ] * [%f f ] + > + + > [%f f ] + > + > let x = + > [%f f + > 4 + > 2 ] + > * + > [%f f + > 3 + > 4 ] + > + > let x = + > [%f f + > 2 + > 3 ] * [%f f + > 3 + > 4 ] + + > [%f f + > 2 + > 3 ] + > + > let x = + > [%f f + > 2 + > 3 ] * [%f f + > 3 + > 4 ] + > + [%f f + > 2 + > 3 ] + > + > let x = + > [%f f + > 2 + > 3 ] + [%f f + > 3 + > 4 ] * + > [%f f + > 2 + > 3 ] + > + > let x = + > [%f f + > 2 + > 3 ] + [%f f + > 3 + > 4 ] + > * [%f f + > 2 + > 3 ] + > + > let x = + > [%f f + > 2 + > 3 ] + [%f f + > 3 + > 4 ] + > + [%f f + > 2 + > 3 ] + > + > + > let x = + > [% + > f f + > 4 + > 2 ] + > * + > [% + > f + > f + > 3 + > 4 ] + > + > let x = + > [% + > f + > .u f + > 4 + > 2 ] + > * + > [% + > f + > .u + > f + > 3 + > 4 ] + > + > let invariant invariant_a t = + > Invariant.invariant [%here] t [%sexp_of: _ t] (fun () -> + > let check f = Invariant.check_field t f in + > Fields.iter + > ~has_any_waiters:(check (fun has_any_waiters -> + > if Ivar.has_handlers t.ivar + > then (assert has_any_waiters))) + > ~ivar:(check (fun ivar -> + > Ivar.invariant invariant_a ivar; + > assert (Ivar.is_empty ivar)))) + > ;; + > + > let core_type_of_decl ~options ~path type_decl = + > let typ = Ppx_deriving.core_type_of_type_decl type_decl in + > Ppx_deriving.poly_arrow_of_type_decl + > (fun var -> [%type: [%t var] -> [%t var] -> Ppx_deriving_runtime.bool]) + > type_decl + > [%type: [%t typ] -> [%t typ] -> Ppx_deriving_runtime.bool] + > + > module A = struct + > let x = 1 + > + > let%bench_fun "now" [@indexed i = List.range 0 (List.length zones)] = + > let time = now () in + > fun () -> of_time time ~zone + > + > let x = 2 + > end + > + > [%%sig: + > module type M = sig + > val x : int + > end + > + > module S : module type of + > struct + > let x = 12 + > end + > ] + > EOF + + $ ocp-indent -c JaneStreet ppx_expr_ext.ml + let x = + [%x f 3 ] + + let x = + [%x (f + 3 + 5) ] + + let x = + [%x f + 3 + 5 ] + + let x = + [%xy f + 3 + 5 ] + + let x = + [%x fg + 3 + 5 ] + + let x = + [%x f + 3 + 5 ] + + let x = + [%x + f + 3 + 5 + ] + + let x = + 3 + + [%f f ] + + let x = + [%f f ] * [%f f ] + + + [%f f ] + + let x = + [%f f + 4 + 2 ] + * + [%f f + 3 + 4 ] + + let x = + [%f f + 2 + 3 ] * [%f f + 3 + 4 ] + + [%f f + 2 + 3 ] + + let x = + [%f f + 2 + 3 ] * [%f f + 3 + 4 ] + + [%f f + 2 + 3 ] + + let x = + [%f f + 2 + 3 ] + [%f f + 3 + 4 ] * + [%f f + 2 + 3 ] + + let x = + [%f f + 2 + 3 ] + [%f f + 3 + 4 ] + * [%f f + 2 + 3 ] + + let x = + [%f f + 2 + 3 ] + [%f f + 3 + 4 ] + + [%f f + 2 + 3 ] + + + let x = + [% + f f + 4 + 2 ] + * + [% + f + f + 3 + 4 ] + + let x = + [% + f + .u f + 4 + 2 ] + * + [% + f + .u + f + 3 + 4 ] + + let invariant invariant_a t = + Invariant.invariant [%here] t [%sexp_of: _ t] (fun () -> + let check f = Invariant.check_field t f in + Fields.iter + ~has_any_waiters:(check (fun has_any_waiters -> + if Ivar.has_handlers t.ivar + then (assert has_any_waiters))) + ~ivar:(check (fun ivar -> + Ivar.invariant invariant_a ivar; + assert (Ivar.is_empty ivar)))) + ;; + + let core_type_of_decl ~options ~path type_decl = + let typ = Ppx_deriving.core_type_of_type_decl type_decl in + Ppx_deriving.poly_arrow_of_type_decl + (fun var -> [%type: [%t var] -> [%t var] -> Ppx_deriving_runtime.bool]) + type_decl + [%type: [%t typ] -> [%t typ] -> Ppx_deriving_runtime.bool] + + module A = struct + let x = 1 + + let%bench_fun "now" [@indexed i = List.range 0 (List.length zones)] = + let time = now () in + fun () -> of_time time ~zone + + let x = 2 + end + + [%%sig: + module type M = sig + val x : int + end + + module S : module type of + struct + let x = 12 + end + ] diff --git a/tests/passing/ppx_stritem_ext.ml b/tests/passing/ppx_stritem_ext.ml deleted file mode 100644 index d1c6c8b1..00000000 --- a/tests/passing/ppx_stritem_ext.ml +++ /dev/null @@ -1,124 +0,0 @@ -let x = 3 - -[%% a - let x = [ - 3; - 2; - ] -] - -module S = sig - - let x = 3 - - [%% b - let x = [ - 3; - 2; - ] - ] - -end - -[%% c - let x = [ - 3; - 2; - ] - - [%% d - let x = [ - 3; - 2; - ] - ] - -] - -[%% x - 2 * 3 - + - x -] - -[%% x - 2 + 3 - * - x -] - -[%% x - 2 -] - -[%% x - . - y - 2 -] - - -[%% x - .y - 2 -] - -[%% x . - y - 2 -] - -[%% - x - 2 -] - -module S = sig - - let x = 3 - - [%% x - .y - 2 - ] - - [%% x - .y - 2 - ] - - [%% - x - .y - 2 - ] - -end - -[%% client - - open M - let x = 3 - module M = struct end - -] - -[%% client - - let x = 3 - open M - module M = struct end - -] - -[%% client - - module M = struct end - open M - let x = 3 -] - -module M = struct - type a = A of b [@@deriving compare] - and b = B of a -end diff --git a/tests/passing/ppx_stritem_ext.t b/tests/passing/ppx_stritem_ext.t new file mode 100644 index 00000000..5bf6f8e0 --- /dev/null +++ b/tests/passing/ppx_stritem_ext.t @@ -0,0 +1,253 @@ + + $ cat > ppx_stritem_ext.ml << "EOF" + > let x = 3 + > + > [%% a + > let x = [ + > 3; + > 2; + > ] + > ] + > + > module S = sig + > + > let x = 3 + > + > [%% b + > let x = [ + > 3; + > 2; + > ] + > ] + > + > end + > + > [%% c + > let x = [ + > 3; + > 2; + > ] + > + > [%% d + > let x = [ + > 3; + > 2; + > ] + > ] + > + > ] + > + > [%% x + > 2 * 3 + > + + > x + > ] + > + > [%% x + > 2 + 3 + > * + > x + > ] + > + > [%% x + > 2 + > ] + > + > [%% x + > . + > y + > 2 + > ] + > + > + > [%% x + > .y + > 2 + > ] + > + > [%% x . + > y + > 2 + > ] + > + > [%% + > x + > 2 + > ] + > + > module S = sig + > + > let x = 3 + > + > [%% x + > .y + > 2 + > ] + > + > [%% x + > .y + > 2 + > ] + > + > [%% + > x + > .y + > 2 + > ] + > + > end + > + > [%% client + > + > open M + > let x = 3 + > module M = struct end + > + > ] + > + > [%% client + > + > let x = 3 + > open M + > module M = struct end + > + > ] + > + > [%% client + > + > module M = struct end + > open M + > let x = 3 + > ] + > + > module M = struct + > type a = A of b [@@deriving compare] + > and b = B of a + > end + > EOF + + $ ocp-indent ppx_stritem_ext.ml + let x = 3 + + [%% a + let x = [ + 3; + 2; + ] + ] + + module S = sig + + let x = 3 + + [%% b + let x = [ + 3; + 2; + ] + ] + + end + + [%% c + let x = [ + 3; + 2; + ] + + [%% d + let x = [ + 3; + 2; + ] + ] + + ] + + [%% x + 2 * 3 + + + x + ] + + [%% x + 2 + 3 + * + x + ] + + [%% x + 2 + ] + + [%% x + . + y + 2 + ] + + + [%% x + .y + 2 + ] + + [%% x . + y + 2 + ] + + [%% + x + 2 + ] + + module S = sig + + let x = 3 + + [%% x + .y + 2 + ] + + [%% x + .y + 2 + ] + + [%% + x + .y + 2 + ] + + end + + [%% client + + open M + let x = 3 + module M = struct end + + ] + + [%% client + + let x = 3 + open M + module M = struct end + + ] + + [%% client + + module M = struct end + open M + let x = 3 + ] + + module M = struct + type a = A of b [@@deriving compare] + and b = B of a + end diff --git a/tests/passing/quotations2.ml b/tests/passing/quotations2.ml deleted file mode 100644 index f0ba6ecd..00000000 --- a/tests/passing/quotations2.ml +++ /dev/null @@ -1,65 +0,0 @@ -open Util - -let header current categories pages = - let aux short = - let long = match Category.find short with - | None -> failwith ("cannot find category " ^ short) - | Some c -> c in - let url = - try - let first = List.find - (fun p -> p.Page.category = Some short && p.Page.id = 1) - pages in - first.Page.permalink - with Not_found -> - (* we are processing a blog entry - or an index page *) - Config.url short / "index.html" in - if short = current then - <:xhtml<
  • $str:long$
  • &>> - else - <:xhtml<
  • $str:long$
  • &>> in - <:xhtml< - - >> - -let footer current categories pages = - let categories = - List.map (fun short -> - let long = match Category.find short with - | None -> failwith ("cannot find category " ^ short) - | Some c -> c in - short, - long, - List.sort Page.compare (List.filter (fun p -> p.Page.category = Some short) pages) - ) categories in - let aux (short, long, pages) = - let pages = List.map (fun p -> - if p.Page.footer then - <:xhtml< -
  • $str:p.Page.title$
  • - >> else - Xhtml.empty - ) pages in - <:xhtml< - - >> in - <:xhtml< -
    - -
    - >> diff --git a/tests/passing/quotations2.t b/tests/passing/quotations2.t new file mode 100644 index 00000000..83712aa9 --- /dev/null +++ b/tests/passing/quotations2.t @@ -0,0 +1,135 @@ + + $ cat > quotations2.ml << "EOF" + > open Util + > + > let header current categories pages = + > let aux short = + > let long = match Category.find short with + > | None -> failwith ("cannot find category " ^ short) + > | Some c -> c in + > let url = + > try + > let first = List.find + > (fun p -> p.Page.category = Some short && p.Page.id = 1) + > pages in + > first.Page.permalink + > with Not_found -> + > (* we are processing a blog entry + > or an index page *) + > Config.url short / "index.html" in + > if short = current then + > <:xhtml<
  • $str:long$
  • &>> + > else + > <:xhtml<
  • $str:long$
  • &>> in + > <:xhtml< + > + > >> + > + > let footer current categories pages = + > let categories = + > List.map (fun short -> + > let long = match Category.find short with + > | None -> failwith ("cannot find category " ^ short) + > | Some c -> c in + > short, + > long, + > List.sort Page.compare (List.filter (fun p -> p.Page.category = Some short) pages) + > ) categories in + > let aux (short, long, pages) = + > let pages = List.map (fun p -> + > if p.Page.footer then + > <:xhtml< + >
  • $str:p.Page.title$
  • + > >> else + > Xhtml.empty + > ) pages in + > <:xhtml< + > + > >> in + > <:xhtml< + >
    + > + >
    + > >> + > EOF + + $ ocp-indent quotations2.ml + open Util + + let header current categories pages = + let aux short = + let long = match Category.find short with + | None -> failwith ("cannot find category " ^ short) + | Some c -> c in + let url = + try + let first = List.find + (fun p -> p.Page.category = Some short && p.Page.id = 1) + pages in + first.Page.permalink + with Not_found -> + (* we are processing a blog entry + or an index page *) + Config.url short / "index.html" in + if short = current then + <:xhtml<
  • $str:long$
  • &>> + else + <:xhtml<
  • $str:long$
  • &>> in + <:xhtml< + + >> + + let footer current categories pages = + let categories = + List.map (fun short -> + let long = match Category.find short with + | None -> failwith ("cannot find category " ^ short) + | Some c -> c in + short, + long, + List.sort Page.compare (List.filter (fun p -> p.Page.category = Some short) pages) + ) categories in + let aux (short, long, pages) = + let pages = List.map (fun p -> + if p.Page.footer then + <:xhtml< +
  • $str:p.Page.title$
  • + >> else + Xhtml.empty + ) pages in + <:xhtml< + + >> in + <:xhtml< +
    + +
    + >> diff --git a/tests/passing/record-with.ml b/tests/passing/record-with.ml deleted file mode 100644 index baec6986..00000000 --- a/tests/passing/record-with.ml +++ /dev/null @@ -1,48 +0,0 @@ -let a = - { - somerecord - with - a = b; - c = d; - } - -let a = - { - somerecord - with a = b; - c = d; - } - -let z = - { recofzfzfzrd with a = bli; bzeefe = - k - ; efgeg = a - } - -let b = - let z = - { reczfzrd with a = bli; - bzeefe = _; - } - -let b = - let z = - { reczfzrd with a = bli; - bzeefe - } - -let lexbuf = { lexbuf with Lexing.lex_start_p = start_pos; - Lexing.lex_curr_p = start_pos; } - -let () = - { Foo. - foo - ; bar = (fun () -> - if a then b) - } - -let () = - { foo - ; bar = (fun () -> - if a then b) - } diff --git a/tests/passing/record-with.t b/tests/passing/record-with.t new file mode 100644 index 00000000..130032f7 --- /dev/null +++ b/tests/passing/record-with.t @@ -0,0 +1,101 @@ + + $ cat > record-with.ml << "EOF" + > let a = + > { + > somerecord + > with + > a = b; + > c = d; + > } + > + > let a = + > { + > somerecord + > with a = b; + > c = d; + > } + > + > let z = + > { recofzfzfzrd with a = bli; bzeefe = + > k + > ; efgeg = a + > } + > + > let b = + > let z = + > { reczfzrd with a = bli; + > bzeefe = _; + > } + > + > let b = + > let z = + > { reczfzrd with a = bli; + > bzeefe + > } + > + > let lexbuf = { lexbuf with Lexing.lex_start_p = start_pos; + > Lexing.lex_curr_p = start_pos; } + > + > let () = + > { Foo. + > foo + > ; bar = (fun () -> + > if a then b) + > } + > + > let () = + > { foo + > ; bar = (fun () -> + > if a then b) + > } + > EOF + + $ ocp-indent record-with.ml + let a = + { + somerecord + with + a = b; + c = d; + } + + let a = + { + somerecord + with a = b; + c = d; + } + + let z = + { recofzfzfzrd with a = bli; bzeefe = + k + ; efgeg = a + } + + let b = + let z = + { reczfzrd with a = bli; + bzeefe = _; + } + + let b = + let z = + { reczfzrd with a = bli; + bzeefe + } + + let lexbuf = { lexbuf with Lexing.lex_start_p = start_pos; + Lexing.lex_curr_p = start_pos; } + + let () = + { Foo. + foo + ; bar = (fun () -> + if a then b) + } + + let () = + { foo + ; bar = (fun () -> + if a then b) + } diff --git a/tests/passing/record_comments.ml b/tests/passing/record_comments.ml deleted file mode 100644 index 7ab6cc58..00000000 --- a/tests/passing/record_comments.ml +++ /dev/null @@ -1,21 +0,0 @@ -type t = { - a : int ; - (** blablabla *) - b : int ; - (** blublublu *) - - c : int ; - (** ccc *) -} - -let _ = - [ A ; - (* A *) - B ; - (* B *) - ] - -type t = { - x : t1; (* c1 *)(* c2 *) - y : t2; -} diff --git a/tests/passing/record_comments.t b/tests/passing/record_comments.t new file mode 100644 index 00000000..f8b105e1 --- /dev/null +++ b/tests/passing/record_comments.t @@ -0,0 +1,47 @@ + + $ cat > record_comments.ml << "EOF" + > type t = { + > a : int ; + > (** blablabla *) + > b : int ; + > (** blublublu *) + > + > c : int ; + > (** ccc *) + > } + > + > let _ = + > [ A ; + > (* A *) + > B ; + > (* B *) + > ] + > + > type t = { + > x : t1; (* c1 *)(* c2 *) + > y : t2; + > } + > EOF + + $ ocp-indent record_comments.ml + type t = { + a : int ; + (** blablabla *) + b : int ; + (** blublublu *) + + c : int ; + (** ccc *) + } + + let _ = + [ A ; + (* A *) + B ; + (* B *) + ] + + type t = { + x : t1; (* c1 *)(* c2 *) + y : t2; + } diff --git a/tests/passing/records.ml b/tests/passing/records.ml deleted file mode 100644 index 7a65da8f..00000000 --- a/tests/passing/records.ml +++ /dev/null @@ -1,43 +0,0 @@ -let read_raw_gen_ic read_pixel ic l c max = - let img = Index8.create c l in - let greymap = - { Color.max = max; - Color.map = - let make_grey i = {r = i; g = i; b = i} in - Array.init (max + 1) make_grey} in - img.Index8.colormap <- greymap; - for i = 0 to l - 1 do - for j = 0 to c - 1 do - Index8.set img j i (read_pixel ic) - done - done; - img;; - -let func_darken_only org level = - let level = 255 - level in - { r = if org.r > level then level else org.r; - g = if org.g > level then level else org.g; - b = if org.b > level then level else org.b };; - -let f = function - | { f1 = Foo - | Bar; - f2 = _; f3 = Foo - | Bar } - -> { f1 = Foo, - Bar; - f2 = xxx - = yyy; f3 = Foo, - Bar } - -let _ = - match a with - | { kind = - x } -> () - | { LibIndex.kind = - x } -> () - -let x = { kind = - x }, - { LibIndex.kind = - x } diff --git a/tests/passing/records.t b/tests/passing/records.t new file mode 100644 index 00000000..cdc5a3ab --- /dev/null +++ b/tests/passing/records.t @@ -0,0 +1,91 @@ + + $ cat > records.ml << "EOF" + > let read_raw_gen_ic read_pixel ic l c max = + > let img = Index8.create c l in + > let greymap = + > { Color.max = max; + > Color.map = + > let make_grey i = {r = i; g = i; b = i} in + > Array.init (max + 1) make_grey} in + > img.Index8.colormap <- greymap; + > for i = 0 to l - 1 do + > for j = 0 to c - 1 do + > Index8.set img j i (read_pixel ic) + > done + > done; + > img;; + > + > let func_darken_only org level = + > let level = 255 - level in + > { r = if org.r > level then level else org.r; + > g = if org.g > level then level else org.g; + > b = if org.b > level then level else org.b };; + > + > let f = function + > | { f1 = Foo + > | Bar; + > f2 = _; f3 = Foo + > | Bar } + > -> { f1 = Foo, + > Bar; + > f2 = xxx + > = yyy; f3 = Foo, + > Bar } + > + > let _ = + > match a with + > | { kind = + > x } -> () + > | { LibIndex.kind = + > x } -> () + > + > let x = { kind = + > x }, + > { LibIndex.kind = + > x } + > EOF + + $ ocp-indent records.ml + let read_raw_gen_ic read_pixel ic l c max = + let img = Index8.create c l in + let greymap = + { Color.max = max; + Color.map = + let make_grey i = {r = i; g = i; b = i} in + Array.init (max + 1) make_grey} in + img.Index8.colormap <- greymap; + for i = 0 to l - 1 do + for j = 0 to c - 1 do + Index8.set img j i (read_pixel ic) + done + done; + img;; + + let func_darken_only org level = + let level = 255 - level in + { r = if org.r > level then level else org.r; + g = if org.g > level then level else org.g; + b = if org.b > level then level else org.b };; + + let f = function + | { f1 = Foo + | Bar; + f2 = _; f3 = Foo + | Bar } + -> { f1 = Foo, + Bar; + f2 = xxx + = yyy; f3 = Foo, + Bar } + + let _ = + match a with + | { kind = + x } -> () + | { LibIndex.kind = + x } -> () + + let x = { kind = + x }, + { LibIndex.kind = + x } diff --git a/tests/passing/semi.ml b/tests/passing/semi.ml deleted file mode 100644 index abe59b31..00000000 --- a/tests/passing/semi.ml +++ /dev/null @@ -1,23 +0,0 @@ -let f () = - print_endline "a" - ; - print_endline "b" - -let f () = toto - ; blah - -let f () = - { a = 3 - ; b = 4 - ; - } - -module A = struct - - type x = - { a: int - ; b: int - ; - } - -end diff --git a/tests/passing/semi.t b/tests/passing/semi.t new file mode 100644 index 00000000..9437550f --- /dev/null +++ b/tests/passing/semi.t @@ -0,0 +1,51 @@ + + $ cat > semi.ml << "EOF" + > let f () = + > print_endline "a" + > ; + > print_endline "b" + > + > let f () = toto + > ; blah + > + > let f () = + > { a = 3 + > ; b = 4 + > ; + > } + > + > module A = struct + > + > type x = + > { a: int + > ; b: int + > ; + > } + > + > end + > EOF + + $ ocp-indent semi.ml + let f () = + print_endline "a" + ; + print_endline "b" + + let f () = toto + ; blah + + let f () = + { a = 3 + ; b = 4 + ; + } + + module A = struct + + type x = + { a: int + ; b: int + ; + } + + end diff --git a/tests/passing/semisemi.ml b/tests/passing/semisemi.ml deleted file mode 100644 index 74e9f16d..00000000 --- a/tests/passing/semisemi.ml +++ /dev/null @@ -1,10 +0,0 @@ -module M = struct - let () = () - ;; - let f x = 3;; - let () = () -end - -;; - -let () = () diff --git a/tests/passing/semisemi.t b/tests/passing/semisemi.t new file mode 100644 index 00000000..69ff23ce --- /dev/null +++ b/tests/passing/semisemi.t @@ -0,0 +1,25 @@ + + $ cat > semisemi.ml << "EOF" + > module M = struct + > let () = () + > ;; + > let f x = 3;; + > let () = () + > end + > + > ;; + > + > let () = () + > EOF + + $ ocp-indent semisemi.ml + module M = struct + let () = () + ;; + let f x = 3;; + let () = () + end + + ;; + + let () = () diff --git a/tests/passing/sequence.ml b/tests/passing/sequence.ml deleted file mode 100644 index 982bee30..00000000 --- a/tests/passing/sequence.ml +++ /dev/null @@ -1,72 +0,0 @@ -let f = fun x -> - x - -let f x = - x - -let f g = fun x -> g - x - -let f g x = g - x - -let l1 = (a :: - b :: - []) - -let l1 = ( - a :: - b :: - []) - -let l1 = - a :: - b :: - [] - -let l1 = a :: - b :: - [] - -let l1 = [a; - b; - ] - -let l1 = [ - a; - b; -] - -let l1 = - [ a; - b; - ] - -let l1 = - [ a - ; b - ] - -let l1 = [ - a -; b -] - -let l1 = - [ a; - b - ; c - ] - -let f1 = function - | {k=A|B} -> true - | {k=C} -> false - -let overflow_small = - 4611686018427387904 (* max_int (63) + 1 *) -let overflow_big = - 46116860184273879030 - -let ppx_sequence = - ();%ext - () diff --git a/tests/passing/sequence.t b/tests/passing/sequence.t new file mode 100644 index 00000000..f7ddc86c --- /dev/null +++ b/tests/passing/sequence.t @@ -0,0 +1,149 @@ + + $ cat > sequence.ml << "EOF" + > let f = fun x -> + > x + > + > let f x = + > x + > + > let f g = fun x -> g + > x + > + > let f g x = g + > x + > + > let l1 = (a :: + > b :: + > []) + > + > let l1 = ( + > a :: + > b :: + > []) + > + > let l1 = + > a :: + > b :: + > [] + > + > let l1 = a :: + > b :: + > [] + > + > let l1 = [a; + > b; + > ] + > + > let l1 = [ + > a; + > b; + > ] + > + > let l1 = + > [ a; + > b; + > ] + > + > let l1 = + > [ a + > ; b + > ] + > + > let l1 = [ + > a + > ; b + > ] + > + > let l1 = + > [ a; + > b + > ; c + > ] + > + > let f1 = function + > | {k=A|B} -> true + > | {k=C} -> false + > + > let overflow_small = + > 4611686018427387904 (* max_int (63) + 1 *) + > let overflow_big = + > 46116860184273879030 + > + > let ppx_sequence = + > ();%ext + > () + > EOF + + $ ocp-indent sequence.ml + let f = fun x -> + x + + let f x = + x + + let f g = fun x -> g + x + + let f g x = g + x + + let l1 = (a :: + b :: + []) + + let l1 = ( + a :: + b :: + []) + + let l1 = + a :: + b :: + [] + + let l1 = a :: + b :: + [] + + let l1 = [a; + b; + ] + + let l1 = [ + a; + b; + ] + + let l1 = + [ a; + b; + ] + + let l1 = + [ a + ; b + ] + + let l1 = [ + a + ; b + ] + + let l1 = + [ a; + b + ; c + ] + + let f1 = function + | {k=A|B} -> true + | {k=C} -> false + + let overflow_small = + 4611686018427387904 (* max_int (63) + 1 *) + let overflow_big = + 46116860184273879030 + + let ppx_sequence = + ();%ext + () diff --git a/tests/passing/str_else_always.ml b/tests/passing/str_else_always.ml deleted file mode 100644 index 9c3662c1..00000000 --- a/tests/passing/str_else_always.ml +++ /dev/null @@ -1,60 +0,0 @@ -let () = - if true then "bla" else - if true then "bli" else - "blo" - -let () = - if true then "bla" else - if true then "bli" else - begin - "hop" - end - -let () = - if true then "hop" else - if true then "hap" else - ((); "bla") - -let () = - if - x - then - y - else k, - w; - z - -let () = - if x then a - else - let y = x / 42 in - y - -let () = - if x then a - else if y - then b - else begin - blabla - end; - x - -let () = - if x then - a - else match y with - | A -> x - | B -> y - -let () = - if x then - a - else - match y with - | A -> x - | B -> y - -let () = - if x then a else - fun x -> - y diff --git a/tests/passing/str_else_always.ml.opts b/tests/passing/str_else_always.ml.opts deleted file mode 100644 index 5c87fd9d..00000000 --- a/tests/passing/str_else_always.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c strict_else=always diff --git a/tests/passing/str_else_always.t b/tests/passing/str_else_always.t new file mode 100644 index 00000000..0fb707fa --- /dev/null +++ b/tests/passing/str_else_always.t @@ -0,0 +1,125 @@ + + $ cat > str_else_always.ml << "EOF" + > let () = + > if true then "bla" else + > if true then "bli" else + > "blo" + > + > let () = + > if true then "bla" else + > if true then "bli" else + > begin + > "hop" + > end + > + > let () = + > if true then "hop" else + > if true then "hap" else + > ((); "bla") + > + > let () = + > if + > x + > then + > y + > else k, + > w; + > z + > + > let () = + > if x then a + > else + > let y = x / 42 in + > y + > + > let () = + > if x then a + > else if y + > then b + > else begin + > blabla + > end; + > x + > + > let () = + > if x then + > a + > else match y with + > | A -> x + > | B -> y + > + > let () = + > if x then + > a + > else + > match y with + > | A -> x + > | B -> y + > + > let () = + > if x then a else + > fun x -> + > y + > EOF + + $ ocp-indent -c strict_else=always str_else_always.ml + let () = + if true then "bla" else + if true then "bli" else + "blo" + + let () = + if true then "bla" else + if true then "bli" else + begin + "hop" + end + + let () = + if true then "hop" else + if true then "hap" else + ((); "bla") + + let () = + if + x + then + y + else k, + w; + z + + let () = + if x then a + else + let y = x / 42 in + y + + let () = + if x then a + else if y + then b + else begin + blabla + end; + x + + let () = + if x then + a + else match y with + | A -> x + | B -> y + + let () = + if x then + a + else + match y with + | A -> x + | B -> y + + let () = + if x then a else + fun x -> + y diff --git a/tests/passing/str_else_auto.ml b/tests/passing/str_else_auto.ml deleted file mode 100644 index 1ed70205..00000000 --- a/tests/passing/str_else_auto.ml +++ /dev/null @@ -1,60 +0,0 @@ -let () = - if true then "bla" else - if true then "bli" else - "blo" - -let () = - if true then "bla" else - if true then "bli" else - begin - "hop" - end - -let () = - if true then "hop" else - if true then "hap" else - ((); "bla") - -let () = - if - x - then - y - else k, - w; - z - -let () = - if x then a - else - let y = x / 42 in - y - -let () = - if x then a - else if y - then b - else begin - blabla - end; - x - -let () = - if x then - a - else match y with - | A -> x - | B -> y - -let () = - if x then - a - else - match y with - | A -> x - | B -> y - -let () = - if x then a else - fun x -> - y diff --git a/tests/passing/str_else_auto.ml.opts b/tests/passing/str_else_auto.ml.opts deleted file mode 100644 index 4d15fdf7..00000000 --- a/tests/passing/str_else_auto.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c strict_else=auto diff --git a/tests/passing/str_else_auto.t b/tests/passing/str_else_auto.t new file mode 100644 index 00000000..e768065d --- /dev/null +++ b/tests/passing/str_else_auto.t @@ -0,0 +1,125 @@ + + $ cat > str_else_auto.ml << "EOF" + > let () = + > if true then "bla" else + > if true then "bli" else + > "blo" + > + > let () = + > if true then "bla" else + > if true then "bli" else + > begin + > "hop" + > end + > + > let () = + > if true then "hop" else + > if true then "hap" else + > ((); "bla") + > + > let () = + > if + > x + > then + > y + > else k, + > w; + > z + > + > let () = + > if x then a + > else + > let y = x / 42 in + > y + > + > let () = + > if x then a + > else if y + > then b + > else begin + > blabla + > end; + > x + > + > let () = + > if x then + > a + > else match y with + > | A -> x + > | B -> y + > + > let () = + > if x then + > a + > else + > match y with + > | A -> x + > | B -> y + > + > let () = + > if x then a else + > fun x -> + > y + > EOF + + $ ocp-indent -c strict_else=auto str_else_auto.ml + let () = + if true then "bla" else + if true then "bli" else + "blo" + + let () = + if true then "bla" else + if true then "bli" else + begin + "hop" + end + + let () = + if true then "hop" else + if true then "hap" else + ((); "bla") + + let () = + if + x + then + y + else k, + w; + z + + let () = + if x then a + else + let y = x / 42 in + y + + let () = + if x then a + else if y + then b + else begin + blabla + end; + x + + let () = + if x then + a + else match y with + | A -> x + | B -> y + + let () = + if x then + a + else + match y with + | A -> x + | B -> y + + let () = + if x then a else + fun x -> + y diff --git a/tests/passing/str_else_never.ml b/tests/passing/str_else_never.ml deleted file mode 100644 index 6017550f..00000000 --- a/tests/passing/str_else_never.ml +++ /dev/null @@ -1,60 +0,0 @@ -let () = - if true then "bla" else - if true then "bli" else - "blo" - -let () = - if true then "bla" else - if true then "bli" else - begin - "hop" - end - -let () = - if true then "hop" else - if true then "hap" else - ((); "bla") - -let () = - if - x - then - y - else k, - w; - z - -let () = - if x then a - else - let y = x / 42 in - y - -let () = - if x then a - else if y - then b - else begin - blabla - end; - x - -let () = - if x then - a - else match y with - | A -> x - | B -> y - -let () = - if x then - a - else - match y with - | A -> x - | B -> y - -let () = - if x then a else - fun x -> - y diff --git a/tests/passing/str_else_never.ml.opts b/tests/passing/str_else_never.ml.opts deleted file mode 100644 index 1c679fe2..00000000 --- a/tests/passing/str_else_never.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c strict_else=never diff --git a/tests/passing/str_else_never.t b/tests/passing/str_else_never.t new file mode 100644 index 00000000..842e640d --- /dev/null +++ b/tests/passing/str_else_never.t @@ -0,0 +1,125 @@ + + $ cat > str_else_never.ml << "EOF" + > let () = + > if true then "bla" else + > if true then "bli" else + > "blo" + > + > let () = + > if true then "bla" else + > if true then "bli" else + > begin + > "hop" + > end + > + > let () = + > if true then "hop" else + > if true then "hap" else + > ((); "bla") + > + > let () = + > if + > x + > then + > y + > else k, + > w; + > z + > + > let () = + > if x then a + > else + > let y = x / 42 in + > y + > + > let () = + > if x then a + > else if y + > then b + > else begin + > blabla + > end; + > x + > + > let () = + > if x then + > a + > else match y with + > | A -> x + > | B -> y + > + > let () = + > if x then + > a + > else + > match y with + > | A -> x + > | B -> y + > + > let () = + > if x then a else + > fun x -> + > y + > EOF + + $ ocp-indent -c strict_else=never str_else_never.ml + let () = + if true then "bla" else + if true then "bli" else + "blo" + + let () = + if true then "bla" else + if true then "bli" else + begin + "hop" + end + + let () = + if true then "hop" else + if true then "hap" else + ((); "bla") + + let () = + if + x + then + y + else k, + w; + z + + let () = + if x then a + else + let y = x / 42 in + y + + let () = + if x then a + else if y + then b + else begin + blabla + end; + x + + let () = + if x then + a + else match y with + | A -> x + | B -> y + + let () = + if x then + a + else + match y with + | A -> x + | B -> y + + let () = + if x then a else + fun x -> + y diff --git a/tests/passing/traverse.mli b/tests/passing/traverse.mli deleted file mode 100644 index fba27be6..00000000 --- a/tests/passing/traverse.mli +++ /dev/null @@ -1,205 +0,0 @@ -(* - Copyright © 2011 MLstate - - This file is part of OPA. - - OPA is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License, version 3, as published by - the Free Software Foundation. - - OPA is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for - more details. - - You should have received a copy of the GNU Affero General Public License - along with OPA. If not, see . -*) -(** - Generic Ast Rewriter API. - - This module provides all usual traverse functions and some higher-level ones - on any tree structure as long as we consider only one type of nodes - - @author Louis Gesbert - @author Valentin Gatien-Baron - @author Mathieu Barbin -*) - -open TraverseInterface - -(* module type TRAVERSE_LIFT = *) -(* sig *) -(* val foldmap : ('acc -> 'expr -> 'acc * 'expr) -> 'acc -> 'code_elt -> 'acc * 'code_elt *) -(* end *) - - -(** Some Extensions *) -module Utils : sig - - (** A generalisation of the type needed in S - ('a, 'at, 'bt ,'b) sub - 'a may be expressions where identifiers are strings - 'b an expressions where identfiers are uniq - In that case, ('a,'a,'b,'b) represents a function that deconstruct a string expression - into a - - list of string expression - - a function that expects an ident expression list and build you the the 'original' ident expression - - DON'T LOOK at the types, it's too scary - Instead take a look at the following example, where you build the subs_cons function for the expressions - of some ast: - let subs_cons e = - match e with - | Apply (e1,e2) -> - (* (e1,e2) is a pair of expression and you are currently treating - * expressions, you write exactly that: *) - wrap (fun x -> Apply x) ((sub_2 sub_current sub_current) (e1,e2)) - | Match pel -> - (* pel is a list of pattern * expr - * we just ignore the pattern since there is no expression inside them - * we stop the deconstruction on the expression, since it is was we are currently deconstructing *) - wrap (fun x -> Match x) (sub_list (sub_2 sub_ignore sub_current) pel) - | _ -> ... - - *) - - type ('a, 'at, 'bt, 'b) sub = 'a -> ('bt list -> 'b) * 'at list - - val sub_2 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a1 * 'a2, 'at, 'bt, 'b1 * 'b2) sub - val sub_3 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a1 * 'a2 * 'a3, 'at, 'bt, 'b1 * 'b2 * 'b3) sub - val sub_4 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a4, 'at, 'bt, 'b4) sub -> ('a1 * 'a2 * 'a3 * 'a4, 'at, 'bt, 'b1 * 'b2 * 'b3 * 'b4) sub - val sub_list : ('a, 'at, 'bt, 'b) sub -> ('a list, 'at, 'bt, 'b list) sub - val sub_option : ('a, 'at, 'bt, 'b) sub -> ('a option, 'at, 'bt, 'b option) sub - val sub_current : ('a, 'a, 'b, 'b) sub - val sub_ignore : ('a, _, _, 'a) sub - - val wrap : ('a -> 'b) -> ('at list -> 'a) * 't list -> ('at list -> 'b) * 't list -end - -(* HACK: tmp until we merge it into TRAVERSE_CORE for TraverseInterface, - and rename it into TRAVERSE *) -module type OLD_TRAVERSE = -sig - - type 'p t constraint 'p = _ * _ * _ - val traverse_iter : (('p t -> unit) -> 'p t -> unit) -> 'p t -> unit - val traverse_map : (('p t -> 'p t) -> 'p t -> 'p t) -> 'p t -> 'p t - val traverse_fold : (('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a) -> 'a -> 'p t -> 'a - val traverse_foldmap : (('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t - val traverse_exists : (('p t -> bool) -> 'p t -> bool) -> 'p t -> bool - val traverse_forall : (('p t -> bool) -> 'p t -> bool) -> 'p t -> bool - val traverse_fold_context_down : (('env -> 'a -> 'p t -> 'a) -> 'env -> 'a -> 'p t -> 'a) -> 'env -> 'a -> 'p t -> 'a - val iter : ('p t -> unit) -> 'p t -> unit - val iter_up : ('p t -> unit) -> 'p t -> unit - val iter_down : ('p t -> unit) -> 'p t -> unit - val map : ('p t -> 'p t) -> 'p t -> 'p t - val map_up : ('p t -> 'p t) -> 'p t -> 'p t - val map_down : ('p t -> 'p t) -> 'p t -> 'p t - val fold : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a - val fold_up : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a - val fold_down : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a - val foldmap : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t - val foldmap_up : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t - val foldmap_down : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t - val exists : ('p t -> bool) -> 'p t -> bool - val exists_up : ('p t -> bool) -> 'p t -> bool - val exists_down : ('p t -> bool) -> 'p t -> bool - val find : ('p t -> bool) -> 'p t -> 'p t option - val find_up : ('p t -> bool) -> 'p t -> 'p t option - val find_down : ('p t -> bool) -> 'p t -> 'p t option - val findmap : ('p t -> 'a option) -> 'p t -> 'a option - val findmap_up : ('p t -> 'a option) -> 'p t -> 'a option - val findmap_down : ('p t -> 'a option) -> 'p t -> 'a option - - - (** traverse all the nodes of the tree in an unspecified order *) - val traverse_fold_right : (('b t -> 'a -> 'a) -> 'b t -> 'a -> 'a) -> 'b t -> 'a -> 'a - - (** [fold_up_combine ?combine f acc0 t] folds [f] from leaves with [acc0], combining - accumulators from sub-trees with [combine] before calling [f]. - Default value for combine is (fun _ b -> b) - Be carefull be using this function without combine, lots of accs are lost *) - val fold_up_combine : ?combine:('a -> 'a -> 'a) -> ('a -> 'b t -> 'a) -> 'a -> 'b t -> 'a - - (** Folds all the nodes of the tree in an unspecified order *) - val fold_right_down : ('b t -> 'a -> 'a) -> 'b t -> 'a -> 'a - val foldmap_up_combine : ?combine:('a -> 'a -> 'a) -> ('a -> 'b t -> 'a * 'b t) -> 'a -> 'b t -> 'a * 'b t - - (** Non-recursive versions, e.g. if you want to handle recursion yourself and have a default case *) - val map_nonrec : ('b t -> 'b t) -> 'b t -> 'b t - val fold_nonrec : ('a -> 'b t -> 'a) -> 'a -> 'b t -> 'a - val foldmap_nonrec : ('a -> 'b t -> 'a * 'b t) -> 'a -> 'b t -> 'a * 'b t - - (** Just because we had fun writing it. Don't use as is, it's probably very slow. - Applies the rewriting until fixpoint reached *) - val map_down_fix : ('b t -> 'b t) -> 'b t -> 'b t - - (** Additional functions that let you traverse the type 'c t when they are deep into an arbitrary structure 'b - as long as you provide the functions to unbuild/rebuild 'b into t lists *) - type ('b, 'c) sub = ('b, 'c t, 'c t , 'b) Utils.sub - - val lift_iter_up : ('b,'c) sub -> ('c t -> unit) -> ('b -> unit) - val lift_iter_down : ('b,'c) sub -> ('c t -> unit) -> ('b -> unit) - val lift_map_up : ('b,'c) sub -> ('c t -> 'c t) -> ('b -> 'b) - val lift_map_down : ('b,'c) sub -> ('c t -> 'c t) -> ('b -> 'b) - (* like fold_map_up_for_real *) - val lift_fold_up_combine : ('b,'c) sub -> ?combine:('a -> 'a -> 'a) -> ('a -> 'c t -> 'a) -> ('a -> 'b -> 'a) - val lift_fold : ('b,'c) sub -> ('a -> 'c t -> 'a) -> ('a -> 'b -> 'a) - val lift_fold_right_down : ('b,'c) sub -> ('c t -> 'a -> 'a) -> ('b -> 'a -> 'a) - val lift_foldmap_up : ('b,'c) sub -> ('a -> 'c t -> 'a * 'c t) -> ('a -> 'b -> 'a * 'b) - val lift_foldmap_down : ('b,'c) sub -> ('a -> 'c t -> 'a * 'c t) -> ('a -> 'b -> 'a * 'b) - val lift_exists : ('b,'c) sub -> ('c t -> bool) -> ('b -> bool) -end - - -(** {6 First implementation} *) - - -(** Functor giving you the usual traverse functions *) -module Make (X : S) : OLD_TRAVERSE with type 'a t = 'a X.t - -(** Functor for map2, fold2, etc. *) -module MakePair (Fst : S) (Snd : S) : OLD_TRAVERSE with type 'a t = 'a Fst.t * 'a Snd.t - -(** {6 Second implementation} *) - -(** For the second version (S2), you may do not want to write the optimised version of fold, map, iter - in this case you can use this unoptimzed constructors, to get them from the foldmap_children function *) -module Unoptimized : -sig - (** Simple recursion *) - type ('acc, 't, 't2) foldmap = ('acc -> 't -> 'acc * 't) -> 'acc -> 't2 -> 'acc * 't2 - val iter : (unit, 't, 't2) foldmap -> ('t -> unit) -> 't2 -> unit - val map : (unit, 't, 't2) foldmap -> ('t -> 't) -> 't2 -> 't2 - val fold : ('acc, 't, 't2) foldmap -> ('acc -> 't -> 'acc) -> 'acc -> 't2 -> 'acc - - (** Mutual recursion *) - type ('acc, 'tA, 'tB) foldmapAB = - ('acc -> 'tA -> 'acc * 'tA) -> - ('acc -> 'tB -> 'acc * 'tB) -> - 'acc -> 'tA -> 'acc * 'tA - val iterAB : (unit, 'tA, 'tB) foldmapAB -> ('tA -> unit) -> ('tB -> unit) -> 'tA -> unit - val mapAB : (unit, 'tA, 'tB) foldmapAB -> ('tA -> 'tA) -> ('tB -> 'tB) -> 'tA -> 'tA - val foldAB : ('acc, 'tA, 'tB) foldmapAB -> ('acc -> 'tA -> 'acc) -> ('acc -> 'tB -> 'acc) -> 'acc -> 'tA -> 'acc -end - -open TraverseInterface -module Make2 (X : S2) : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a X.t - -module MakeLift1 - (Y : LIFT2) - (X : TRAVERSE with type 'a container = 'a Y.t and type 'a t = 'a Y.t) - : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a Y.container - -module MakeLift2 - (Y : LIFT2) - (X : TRAVERSE with type 'a container = 'a Y.t) - : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a Y.container - -(* From there, you can build Box of Boxes with MakeBox *) -(* for example, for rewriting rules on a tuple of code, etc...*) - -(** {6 Mutual Recursive Trees} *) - -module MakeAB (AB : AB) : TRAVERSE_AB with type 'a tA = 'a AB.tA and type 'a tB = 'a AB.tB diff --git a/tests/passing/traverse.mli.opts b/tests/passing/traverse.mli.opts deleted file mode 100644 index ed28299a..00000000 --- a/tests/passing/traverse.mli.opts +++ /dev/null @@ -1 +0,0 @@ --c in=2,match_clause=4 diff --git a/tests/passing/traverse.t b/tests/passing/traverse.t new file mode 100644 index 00000000..6195cf40 --- /dev/null +++ b/tests/passing/traverse.t @@ -0,0 +1,414 @@ + $ cat > traverse.ml << "EOF" + > (* + > Copyright © 2011 MLstate + > + > This file is part of OPA. + > + > OPA is free software: you can redistribute it and/or modify it under the + > terms of the GNU Affero General Public License, version 3, as published by + > the Free Software Foundation. + > + > OPA is distributed in the hope that it will be useful, but WITHOUT ANY + > WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + > FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + > more details. + > + > You should have received a copy of the GNU Affero General Public License + > along with OPA. If not, see . + > *) + > (** + > Generic Ast Rewriter API. + > + > This module provides all usual traverse functions and some higher-level ones + > on any tree structure as long as we consider only one type of nodes + > + > @author Louis Gesbert + > @author Valentin Gatien-Baron + > @author Mathieu Barbin + > *) + > + > open TraverseInterface + > + > (* module type TRAVERSE_LIFT = *) + > (* sig *) + > (* val foldmap : ('acc -> 'expr -> 'acc * 'expr) -> 'acc -> 'code_elt -> 'acc * 'code_elt *) + > (* end *) + > + > + > (** Some Extensions *) + > module Utils : sig + > + > (** A generalisation of the type needed in S + > ('a, 'at, 'bt ,'b) sub + > 'a may be expressions where identifiers are strings + > 'b an expressions where identfiers are uniq + > In that case, ('a,'a,'b,'b) represents a function that deconstruct a string expression + > into a + > - list of string expression + > - a function that expects an ident expression list and build you the the 'original' ident expression + > + > DON'T LOOK at the types, it's too scary + > Instead take a look at the following example, where you build the subs_cons function for the expressions + > of some ast: + > let subs_cons e = + > match e with + > | Apply (e1,e2) -> + > (* (e1,e2) is a pair of expression and you are currently treating + > * expressions, you write exactly that: *) + > wrap (fun x -> Apply x) ((sub_2 sub_current sub_current) (e1,e2)) + > | Match pel -> + > (* pel is a list of pattern * expr + > * we just ignore the pattern since there is no expression inside them + > * we stop the deconstruction on the expression, since it is was we are currently deconstructing *) + > wrap (fun x -> Match x) (sub_list (sub_2 sub_ignore sub_current) pel) + > | _ -> ... + > + > *) + > + > type ('a, 'at, 'bt, 'b) sub = 'a -> ('bt list -> 'b) * 'at list + > + > val sub_2 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a1 * 'a2, 'at, 'bt, 'b1 * 'b2) sub + > val sub_3 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a1 * 'a2 * 'a3, 'at, 'bt, 'b1 * 'b2 * 'b3) sub + > val sub_4 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a4, 'at, 'bt, 'b4) sub -> ('a1 * 'a2 * 'a3 * 'a4, 'at, 'bt, 'b1 * 'b2 * 'b3 * 'b4) sub + > val sub_list : ('a, 'at, 'bt, 'b) sub -> ('a list, 'at, 'bt, 'b list) sub + > val sub_option : ('a, 'at, 'bt, 'b) sub -> ('a option, 'at, 'bt, 'b option) sub + > val sub_current : ('a, 'a, 'b, 'b) sub + > val sub_ignore : ('a, _, _, 'a) sub + > + > val wrap : ('a -> 'b) -> ('at list -> 'a) * 't list -> ('at list -> 'b) * 't list + > end + > + > (* HACK: tmp until we merge it into TRAVERSE_CORE for TraverseInterface, + > and rename it into TRAVERSE *) + > module type OLD_TRAVERSE = + > sig + > + > type 'p t constraint 'p = _ * _ * _ + > val traverse_iter : (('p t -> unit) -> 'p t -> unit) -> 'p t -> unit + > val traverse_map : (('p t -> 'p t) -> 'p t -> 'p t) -> 'p t -> 'p t + > val traverse_fold : (('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + > val traverse_foldmap : (('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + > val traverse_exists : (('p t -> bool) -> 'p t -> bool) -> 'p t -> bool + > val traverse_forall : (('p t -> bool) -> 'p t -> bool) -> 'p t -> bool + > val traverse_fold_context_down : (('env -> 'a -> 'p t -> 'a) -> 'env -> 'a -> 'p t -> 'a) -> 'env -> 'a -> 'p t -> 'a + > val iter : ('p t -> unit) -> 'p t -> unit + > val iter_up : ('p t -> unit) -> 'p t -> unit + > val iter_down : ('p t -> unit) -> 'p t -> unit + > val map : ('p t -> 'p t) -> 'p t -> 'p t + > val map_up : ('p t -> 'p t) -> 'p t -> 'p t + > val map_down : ('p t -> 'p t) -> 'p t -> 'p t + > val fold : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + > val fold_up : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + > val fold_down : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + > val foldmap : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + > val foldmap_up : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + > val foldmap_down : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + > val exists : ('p t -> bool) -> 'p t -> bool + > val exists_up : ('p t -> bool) -> 'p t -> bool + > val exists_down : ('p t -> bool) -> 'p t -> bool + > val find : ('p t -> bool) -> 'p t -> 'p t option + > val find_up : ('p t -> bool) -> 'p t -> 'p t option + > val find_down : ('p t -> bool) -> 'p t -> 'p t option + > val findmap : ('p t -> 'a option) -> 'p t -> 'a option + > val findmap_up : ('p t -> 'a option) -> 'p t -> 'a option + > val findmap_down : ('p t -> 'a option) -> 'p t -> 'a option + > + > + > (** traverse all the nodes of the tree in an unspecified order *) + > val traverse_fold_right : (('b t -> 'a -> 'a) -> 'b t -> 'a -> 'a) -> 'b t -> 'a -> 'a + > + > (** [fold_up_combine ?combine f acc0 t] folds [f] from leaves with [acc0], combining + > accumulators from sub-trees with [combine] before calling [f]. + > Default value for combine is (fun _ b -> b) + > Be carefull be using this function without combine, lots of accs are lost *) + > val fold_up_combine : ?combine:('a -> 'a -> 'a) -> ('a -> 'b t -> 'a) -> 'a -> 'b t -> 'a + > + > (** Folds all the nodes of the tree in an unspecified order *) + > val fold_right_down : ('b t -> 'a -> 'a) -> 'b t -> 'a -> 'a + > val foldmap_up_combine : ?combine:('a -> 'a -> 'a) -> ('a -> 'b t -> 'a * 'b t) -> 'a -> 'b t -> 'a * 'b t + > + > (** Non-recursive versions, e.g. if you want to handle recursion yourself and have a default case *) + > val map_nonrec : ('b t -> 'b t) -> 'b t -> 'b t + > val fold_nonrec : ('a -> 'b t -> 'a) -> 'a -> 'b t -> 'a + > val foldmap_nonrec : ('a -> 'b t -> 'a * 'b t) -> 'a -> 'b t -> 'a * 'b t + > + > (** Just because we had fun writing it. Don't use as is, it's probably very slow. + > Applies the rewriting until fixpoint reached *) + > val map_down_fix : ('b t -> 'b t) -> 'b t -> 'b t + > + > (** Additional functions that let you traverse the type 'c t when they are deep into an arbitrary structure 'b + > as long as you provide the functions to unbuild/rebuild 'b into t lists *) + > type ('b, 'c) sub = ('b, 'c t, 'c t , 'b) Utils.sub + > + > val lift_iter_up : ('b,'c) sub -> ('c t -> unit) -> ('b -> unit) + > val lift_iter_down : ('b,'c) sub -> ('c t -> unit) -> ('b -> unit) + > val lift_map_up : ('b,'c) sub -> ('c t -> 'c t) -> ('b -> 'b) + > val lift_map_down : ('b,'c) sub -> ('c t -> 'c t) -> ('b -> 'b) + > (* like fold_map_up_for_real *) + > val lift_fold_up_combine : ('b,'c) sub -> ?combine:('a -> 'a -> 'a) -> ('a -> 'c t -> 'a) -> ('a -> 'b -> 'a) + > val lift_fold : ('b,'c) sub -> ('a -> 'c t -> 'a) -> ('a -> 'b -> 'a) + > val lift_fold_right_down : ('b,'c) sub -> ('c t -> 'a -> 'a) -> ('b -> 'a -> 'a) + > val lift_foldmap_up : ('b,'c) sub -> ('a -> 'c t -> 'a * 'c t) -> ('a -> 'b -> 'a * 'b) + > val lift_foldmap_down : ('b,'c) sub -> ('a -> 'c t -> 'a * 'c t) -> ('a -> 'b -> 'a * 'b) + > val lift_exists : ('b,'c) sub -> ('c t -> bool) -> ('b -> bool) + > end + > + > + > (** {6 First implementation} *) + > + > + > (** Functor giving you the usual traverse functions *) + > module Make (X : S) : OLD_TRAVERSE with type 'a t = 'a X.t + > + > (** Functor for map2, fold2, etc. *) + > module MakePair (Fst : S) (Snd : S) : OLD_TRAVERSE with type 'a t = 'a Fst.t * 'a Snd.t + > + > (** {6 Second implementation} *) + > + > (** For the second version (S2), you may do not want to write the optimised version of fold, map, iter + > in this case you can use this unoptimzed constructors, to get them from the foldmap_children function *) + > module Unoptimized : + > sig + > (** Simple recursion *) + > type ('acc, 't, 't2) foldmap = ('acc -> 't -> 'acc * 't) -> 'acc -> 't2 -> 'acc * 't2 + > val iter : (unit, 't, 't2) foldmap -> ('t -> unit) -> 't2 -> unit + > val map : (unit, 't, 't2) foldmap -> ('t -> 't) -> 't2 -> 't2 + > val fold : ('acc, 't, 't2) foldmap -> ('acc -> 't -> 'acc) -> 'acc -> 't2 -> 'acc + > + > (** Mutual recursion *) + > type ('acc, 'tA, 'tB) foldmapAB = + > ('acc -> 'tA -> 'acc * 'tA) -> + > ('acc -> 'tB -> 'acc * 'tB) -> + > 'acc -> 'tA -> 'acc * 'tA + > val iterAB : (unit, 'tA, 'tB) foldmapAB -> ('tA -> unit) -> ('tB -> unit) -> 'tA -> unit + > val mapAB : (unit, 'tA, 'tB) foldmapAB -> ('tA -> 'tA) -> ('tB -> 'tB) -> 'tA -> 'tA + > val foldAB : ('acc, 'tA, 'tB) foldmapAB -> ('acc -> 'tA -> 'acc) -> ('acc -> 'tB -> 'acc) -> 'acc -> 'tA -> 'acc + > end + > + > open TraverseInterface + > module Make2 (X : S2) : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a X.t + > + > module MakeLift1 + > (Y : LIFT2) + > (X : TRAVERSE with type 'a container = 'a Y.t and type 'a t = 'a Y.t) + > : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a Y.container + > + > module MakeLift2 + > (Y : LIFT2) + > (X : TRAVERSE with type 'a container = 'a Y.t) + > : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a Y.container + > + > (* From there, you can build Box of Boxes with MakeBox *) + > (* for example, for rewriting rules on a tuple of code, etc...*) + > + > (** {6 Mutual Recursive Trees} *) + > + > module MakeAB (AB : AB) : TRAVERSE_AB with type 'a tA = 'a AB.tA and type 'a tB = 'a AB.tB + > EOF + + $ ocp-indent -c in=2,match_clause=4 traverse.ml + (* + Copyright © 2011 MLstate + + This file is part of OPA. + + OPA is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License, version 3, as published by + the Free Software Foundation. + + OPA is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + more details. + + You should have received a copy of the GNU Affero General Public License + along with OPA. If not, see . + *) + (** + Generic Ast Rewriter API. + + This module provides all usual traverse functions and some higher-level ones + on any tree structure as long as we consider only one type of nodes + + @author Louis Gesbert + @author Valentin Gatien-Baron + @author Mathieu Barbin + *) + + open TraverseInterface + + (* module type TRAVERSE_LIFT = *) + (* sig *) + (* val foldmap : ('acc -> 'expr -> 'acc * 'expr) -> 'acc -> 'code_elt -> 'acc * 'code_elt *) + (* end *) + + + (** Some Extensions *) + module Utils : sig + + (** A generalisation of the type needed in S + ('a, 'at, 'bt ,'b) sub + 'a may be expressions where identifiers are strings + 'b an expressions where identfiers are uniq + In that case, ('a,'a,'b,'b) represents a function that deconstruct a string expression + into a + - list of string expression + - a function that expects an ident expression list and build you the the 'original' ident expression + + DON'T LOOK at the types, it's too scary + Instead take a look at the following example, where you build the subs_cons function for the expressions + of some ast: + let subs_cons e = + match e with + | Apply (e1,e2) -> + (* (e1,e2) is a pair of expression and you are currently treating + * expressions, you write exactly that: *) + wrap (fun x -> Apply x) ((sub_2 sub_current sub_current) (e1,e2)) + | Match pel -> + (* pel is a list of pattern * expr + * we just ignore the pattern since there is no expression inside them + * we stop the deconstruction on the expression, since it is was we are currently deconstructing *) + wrap (fun x -> Match x) (sub_list (sub_2 sub_ignore sub_current) pel) + | _ -> ... + + *) + + type ('a, 'at, 'bt, 'b) sub = 'a -> ('bt list -> 'b) * 'at list + + val sub_2 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a1 * 'a2, 'at, 'bt, 'b1 * 'b2) sub + val sub_3 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a1 * 'a2 * 'a3, 'at, 'bt, 'b1 * 'b2 * 'b3) sub + val sub_4 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a4, 'at, 'bt, 'b4) sub -> ('a1 * 'a2 * 'a3 * 'a4, 'at, 'bt, 'b1 * 'b2 * 'b3 * 'b4) sub + val sub_list : ('a, 'at, 'bt, 'b) sub -> ('a list, 'at, 'bt, 'b list) sub + val sub_option : ('a, 'at, 'bt, 'b) sub -> ('a option, 'at, 'bt, 'b option) sub + val sub_current : ('a, 'a, 'b, 'b) sub + val sub_ignore : ('a, _, _, 'a) sub + + val wrap : ('a -> 'b) -> ('at list -> 'a) * 't list -> ('at list -> 'b) * 't list + end + + (* HACK: tmp until we merge it into TRAVERSE_CORE for TraverseInterface, + and rename it into TRAVERSE *) + module type OLD_TRAVERSE = + sig + + type 'p t constraint 'p = _ * _ * _ + val traverse_iter : (('p t -> unit) -> 'p t -> unit) -> 'p t -> unit + val traverse_map : (('p t -> 'p t) -> 'p t -> 'p t) -> 'p t -> 'p t + val traverse_fold : (('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + val traverse_foldmap : (('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + val traverse_exists : (('p t -> bool) -> 'p t -> bool) -> 'p t -> bool + val traverse_forall : (('p t -> bool) -> 'p t -> bool) -> 'p t -> bool + val traverse_fold_context_down : (('env -> 'a -> 'p t -> 'a) -> 'env -> 'a -> 'p t -> 'a) -> 'env -> 'a -> 'p t -> 'a + val iter : ('p t -> unit) -> 'p t -> unit + val iter_up : ('p t -> unit) -> 'p t -> unit + val iter_down : ('p t -> unit) -> 'p t -> unit + val map : ('p t -> 'p t) -> 'p t -> 'p t + val map_up : ('p t -> 'p t) -> 'p t -> 'p t + val map_down : ('p t -> 'p t) -> 'p t -> 'p t + val fold : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + val fold_up : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + val fold_down : ('a -> 'p t -> 'a) -> 'a -> 'p t -> 'a + val foldmap : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + val foldmap_up : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + val foldmap_down : ('a -> 'p t -> 'a * 'p t) -> 'a -> 'p t -> 'a * 'p t + val exists : ('p t -> bool) -> 'p t -> bool + val exists_up : ('p t -> bool) -> 'p t -> bool + val exists_down : ('p t -> bool) -> 'p t -> bool + val find : ('p t -> bool) -> 'p t -> 'p t option + val find_up : ('p t -> bool) -> 'p t -> 'p t option + val find_down : ('p t -> bool) -> 'p t -> 'p t option + val findmap : ('p t -> 'a option) -> 'p t -> 'a option + val findmap_up : ('p t -> 'a option) -> 'p t -> 'a option + val findmap_down : ('p t -> 'a option) -> 'p t -> 'a option + + + (** traverse all the nodes of the tree in an unspecified order *) + val traverse_fold_right : (('b t -> 'a -> 'a) -> 'b t -> 'a -> 'a) -> 'b t -> 'a -> 'a + + (** [fold_up_combine ?combine f acc0 t] folds [f] from leaves with [acc0], combining + accumulators from sub-trees with [combine] before calling [f]. + Default value for combine is (fun _ b -> b) + Be carefull be using this function without combine, lots of accs are lost *) + val fold_up_combine : ?combine:('a -> 'a -> 'a) -> ('a -> 'b t -> 'a) -> 'a -> 'b t -> 'a + + (** Folds all the nodes of the tree in an unspecified order *) + val fold_right_down : ('b t -> 'a -> 'a) -> 'b t -> 'a -> 'a + val foldmap_up_combine : ?combine:('a -> 'a -> 'a) -> ('a -> 'b t -> 'a * 'b t) -> 'a -> 'b t -> 'a * 'b t + + (** Non-recursive versions, e.g. if you want to handle recursion yourself and have a default case *) + val map_nonrec : ('b t -> 'b t) -> 'b t -> 'b t + val fold_nonrec : ('a -> 'b t -> 'a) -> 'a -> 'b t -> 'a + val foldmap_nonrec : ('a -> 'b t -> 'a * 'b t) -> 'a -> 'b t -> 'a * 'b t + + (** Just because we had fun writing it. Don't use as is, it's probably very slow. + Applies the rewriting until fixpoint reached *) + val map_down_fix : ('b t -> 'b t) -> 'b t -> 'b t + + (** Additional functions that let you traverse the type 'c t when they are deep into an arbitrary structure 'b + as long as you provide the functions to unbuild/rebuild 'b into t lists *) + type ('b, 'c) sub = ('b, 'c t, 'c t , 'b) Utils.sub + + val lift_iter_up : ('b,'c) sub -> ('c t -> unit) -> ('b -> unit) + val lift_iter_down : ('b,'c) sub -> ('c t -> unit) -> ('b -> unit) + val lift_map_up : ('b,'c) sub -> ('c t -> 'c t) -> ('b -> 'b) + val lift_map_down : ('b,'c) sub -> ('c t -> 'c t) -> ('b -> 'b) + (* like fold_map_up_for_real *) + val lift_fold_up_combine : ('b,'c) sub -> ?combine:('a -> 'a -> 'a) -> ('a -> 'c t -> 'a) -> ('a -> 'b -> 'a) + val lift_fold : ('b,'c) sub -> ('a -> 'c t -> 'a) -> ('a -> 'b -> 'a) + val lift_fold_right_down : ('b,'c) sub -> ('c t -> 'a -> 'a) -> ('b -> 'a -> 'a) + val lift_foldmap_up : ('b,'c) sub -> ('a -> 'c t -> 'a * 'c t) -> ('a -> 'b -> 'a * 'b) + val lift_foldmap_down : ('b,'c) sub -> ('a -> 'c t -> 'a * 'c t) -> ('a -> 'b -> 'a * 'b) + val lift_exists : ('b,'c) sub -> ('c t -> bool) -> ('b -> bool) + end + + + (** {6 First implementation} *) + + + (** Functor giving you the usual traverse functions *) + module Make (X : S) : OLD_TRAVERSE with type 'a t = 'a X.t + + (** Functor for map2, fold2, etc. *) + module MakePair (Fst : S) (Snd : S) : OLD_TRAVERSE with type 'a t = 'a Fst.t * 'a Snd.t + + (** {6 Second implementation} *) + + (** For the second version (S2), you may do not want to write the optimised version of fold, map, iter + in this case you can use this unoptimzed constructors, to get them from the foldmap_children function *) + module Unoptimized : + sig + (** Simple recursion *) + type ('acc, 't, 't2) foldmap = ('acc -> 't -> 'acc * 't) -> 'acc -> 't2 -> 'acc * 't2 + val iter : (unit, 't, 't2) foldmap -> ('t -> unit) -> 't2 -> unit + val map : (unit, 't, 't2) foldmap -> ('t -> 't) -> 't2 -> 't2 + val fold : ('acc, 't, 't2) foldmap -> ('acc -> 't -> 'acc) -> 'acc -> 't2 -> 'acc + + (** Mutual recursion *) + type ('acc, 'tA, 'tB) foldmapAB = + ('acc -> 'tA -> 'acc * 'tA) -> + ('acc -> 'tB -> 'acc * 'tB) -> + 'acc -> 'tA -> 'acc * 'tA + val iterAB : (unit, 'tA, 'tB) foldmapAB -> ('tA -> unit) -> ('tB -> unit) -> 'tA -> unit + val mapAB : (unit, 'tA, 'tB) foldmapAB -> ('tA -> 'tA) -> ('tB -> 'tB) -> 'tA -> 'tA + val foldAB : ('acc, 'tA, 'tB) foldmapAB -> ('acc -> 'tA -> 'acc) -> ('acc -> 'tB -> 'acc) -> 'acc -> 'tA -> 'acc + end + + open TraverseInterface + module Make2 (X : S2) : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a X.t + + module MakeLift1 + (Y : LIFT2) + (X : TRAVERSE with type 'a container = 'a Y.t and type 'a t = 'a Y.t) + : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a Y.container + + module MakeLift2 + (Y : LIFT2) + (X : TRAVERSE with type 'a container = 'a Y.t) + : TRAVERSE with type 'a t = 'a X.t and type 'a container = 'a Y.container + + (* From there, you can build Box of Boxes with MakeBox *) + (* for example, for rewriting rules on a tuple of code, etc...*) + + (** {6 Mutual Recursive Trees} *) + + module MakeAB (AB : AB) : TRAVERSE_AB with type 'a tA = 'a AB.tA and type 'a tB = 'a AB.tB diff --git a/tests/passing/type-and.ml b/tests/passing/type-and.ml deleted file mode 100644 index cd8b11fd..00000000 --- a/tests/passing/type-and.ml +++ /dev/null @@ -1,9 +0,0 @@ -type a = - | A -and b = int - -module M = struct - type s = t and t = { - foo : s; - } -end diff --git a/tests/passing/type-and.t b/tests/passing/type-and.t new file mode 100644 index 00000000..ac86ccf1 --- /dev/null +++ b/tests/passing/type-and.t @@ -0,0 +1,23 @@ + + $ cat > type-and.ml << "EOF" + > type a = + > | A + > and b = int + > + > module M = struct + > type s = t and t = { + > foo : s; + > } + > end + > EOF + + $ ocp-indent type-and.ml + type a = + | A + and b = int + + module M = struct + type s = t and t = { + foo : s; + } + end diff --git a/tests/passing/types.ml b/tests/passing/types.ml deleted file mode 100644 index 54106aa7..00000000 --- a/tests/passing/types.ml +++ /dev/null @@ -1,131 +0,0 @@ -type ('a, 'b) t - = a : 'a - -> ?b : b - -> unit - -type ('a, 'b) t = - | A - | B of ('a, 'b) t * 'k - | C of 'a * 'b - -type t = Foo - | Bar - | Baz - -type t = - | Foo - | Bar - | Baz - -type t = - Foo - | Bar - | Baz - -type t = | Foo - | Bar - | Baz - -type t = Foo | Bar - | Baz - -type t = { - foo: int -> int; - bar: 'a; -} - -type t = { - x: int; -} - -type t = { - x: int; - y: int -> a:string -> ?b:(int -> string) -> unit; - mutable - z: int; - mutable a: - string -> unit A.t; -} - -type t = { - x: int -; y: int -> a:string -> ?b:(int -> string) -> unit -; mutable - z: int; - a: string -> - unit A.t; -} - -type t = - { - x: int - ; y: int -> a:string -> ?b:(int -> string) -> unit - ; mutable - z: int; - a: string -> - unit A.t; - } - -type t = - { x: int - ; y: int -> a:string -> ?b:(int -> string) -> unit - ; mutable - z: int - ; mutable a: string - -> unit A.t - } - -type t = { x: int - ; y: int -> a:string -> ?b:(int -> string) -> unit - ; mutable - z: int - ; mutable a: string -> unit A.t - } - -type t = [ - | `a | `b - | `c -] - -type t = - [ - `a - | `b - | `c - ] - -type t = - [ - | `a - | `b - | `c - ] - -type t = - [ `a - | `b - | `c - ] - -type t = [ `a - | `b - | `c - ] - -type t = [ `a | `b - | `c - ] - -module M = struct - type t = t0 - and t' - and t'' = t - val v: t -end - -module Regression = struct - let f : 'a. - 'a t * some_other_type - -> result_type - = body -end diff --git a/tests/passing/types.t b/tests/passing/types.t new file mode 100644 index 00000000..2b60e7e0 --- /dev/null +++ b/tests/passing/types.t @@ -0,0 +1,267 @@ + + $ cat > types.ml << "EOF" + > type ('a, 'b) t + > = a : 'a + > -> ?b : b + > -> unit + > + > type ('a, 'b) t = + > | A + > | B of ('a, 'b) t * 'k + > | C of 'a * 'b + > + > type t = Foo + > | Bar + > | Baz + > + > type t = + > | Foo + > | Bar + > | Baz + > + > type t = + > Foo + > | Bar + > | Baz + > + > type t = | Foo + > | Bar + > | Baz + > + > type t = Foo | Bar + > | Baz + > + > type t = { + > foo: int -> int; + > bar: 'a; + > } + > + > type t = { + > x: int; + > } + > + > type t = { + > x: int; + > y: int -> a:string -> ?b:(int -> string) -> unit; + > mutable + > z: int; + > mutable a: + > string -> unit A.t; + > } + > + > type t = { + > x: int + > ; y: int -> a:string -> ?b:(int -> string) -> unit + > ; mutable + > z: int; + > a: string -> + > unit A.t; + > } + > + > type t = + > { + > x: int + > ; y: int -> a:string -> ?b:(int -> string) -> unit + > ; mutable + > z: int; + > a: string -> + > unit A.t; + > } + > + > type t = + > { x: int + > ; y: int -> a:string -> ?b:(int -> string) -> unit + > ; mutable + > z: int + > ; mutable a: string + > -> unit A.t + > } + > + > type t = { x: int + > ; y: int -> a:string -> ?b:(int -> string) -> unit + > ; mutable + > z: int + > ; mutable a: string -> unit A.t + > } + > + > type t = [ + > | `a | `b + > | `c + > ] + > + > type t = + > [ + > `a + > | `b + > | `c + > ] + > + > type t = + > [ + > | `a + > | `b + > | `c + > ] + > + > type t = + > [ `a + > | `b + > | `c + > ] + > + > type t = [ `a + > | `b + > | `c + > ] + > + > type t = [ `a | `b + > | `c + > ] + > + > module M = struct + > type t = t0 + > and t' + > and t'' = t + > val v: t + > end + > + > module Regression = struct + > let f : 'a. + > 'a t * some_other_type + > -> result_type + > = body + > end + > EOF + + $ ocp-indent types.ml + type ('a, 'b) t + = a : 'a + -> ?b : b + -> unit + + type ('a, 'b) t = + | A + | B of ('a, 'b) t * 'k + | C of 'a * 'b + + type t = Foo + | Bar + | Baz + + type t = + | Foo + | Bar + | Baz + + type t = + Foo + | Bar + | Baz + + type t = | Foo + | Bar + | Baz + + type t = Foo | Bar + | Baz + + type t = { + foo: int -> int; + bar: 'a; + } + + type t = { + x: int; + } + + type t = { + x: int; + y: int -> a:string -> ?b:(int -> string) -> unit; + mutable + z: int; + mutable a: + string -> unit A.t; + } + + type t = { + x: int + ; y: int -> a:string -> ?b:(int -> string) -> unit + ; mutable + z: int; + a: string -> + unit A.t; + } + + type t = + { + x: int + ; y: int -> a:string -> ?b:(int -> string) -> unit + ; mutable + z: int; + a: string -> + unit A.t; + } + + type t = + { x: int + ; y: int -> a:string -> ?b:(int -> string) -> unit + ; mutable + z: int + ; mutable a: string + -> unit A.t + } + + type t = { x: int + ; y: int -> a:string -> ?b:(int -> string) -> unit + ; mutable + z: int + ; mutable a: string -> unit A.t + } + + type t = [ + | `a | `b + | `c + ] + + type t = + [ + `a + | `b + | `c + ] + + type t = + [ + | `a + | `b + | `c + ] + + type t = + [ `a + | `b + | `c + ] + + type t = [ `a + | `b + | `c + ] + + type t = [ `a | `b + | `c + ] + + module M = struct + type t = t0 + and t' + and t'' = t + val v: t + end + + module Regression = struct + let f : 'a. + 'a t * some_other_type + -> result_type + = body + end diff --git a/tests/passing/unit-classes.ml b/tests/passing/unit-classes.ml deleted file mode 100644 index 7c8f37e1..00000000 --- a/tests/passing/unit-classes.ml +++ /dev/null @@ -1,168 +0,0 @@ -(** ocaml classes - (http://caml.inria.fr/pub/docs/manual-ocaml/manual017.html) -*) - -(* class types *) - -class type c = - object - end - -class type c = - M.cl - -class type c = - ['a, 'b] M.cl - -class type c = - object - ('ty) - inherit cl - val mutable virtual - var : bool - method private bar1 x ~y : bool - method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t - constraint - 'a = 'b - end - -(* class expressions *) - -class c = - ['a, 'b] - M.cl - -class c = - fun a b -> - object - end - -class c = object - val x = true -end - -class c = - object - (_ : - 'a) - inherit Something.someclass - as v - val mutable - var : bool - = true - val mutable virtual var2 - : string - method private bar1 x ~y : bool = - false - method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t - constraint - 'a = 'b - initializer - z - end - -(* method specific expressions *) - -let e = - var <- true - -let e = - {< var = false; - var2 = true; - >} - - -(* class definitions *) - -class cl = - object - val x = true - end -and - virtual ['a, 'b] - cl2 x y : - object - val x : bool - end = fun x y -> - object - val x : bool = true - end - -class cl - : object end - -class type virtual ['a] clty = object - method x : int -end - -(* objects *) -val a : - < > -let () = () - -val a : - < .. > -let () = () - -val a : - < meth: int option; - meth2: 'a. 'a option; - meth3: 'a 'b. ('a,'b) Hashtbl.t > -let () = () - -val a : - < meth: int option; - meth2: 'a. 'a option; - meth3: 'a 'b. ('a,'b) Hashtbl.t; - .. > -let () = () - -(* #-types *) -val a : - #M.meth - -val a : - 'a#M.meth - -val a : - ('a,'b*'c) - #M.meth - -(* object types *) -type a = - < > -let () = () - -type a = - < .. > -let () = () - -type a = - < meth: int option; - meth2: 'a. 'a option; - meth3: 'a 'b. ('a,'b) Hashtbl.t > -let () = () - -type a = - < meth: int option; - meth2: 'a. 'a option; - meth3: 'a 'b. ('a,'b) Hashtbl.t; - .. > -let () = () - -type t = - < a : int; b: - < a: int; b: < c:int > > - > -let () = () - -type t = - < a : int; b: - < a: int; b: < c: int -> int> >; - c: int - > -let () = () - -type 'a t = - | Bla : < x : int > t - | Blo : < y : int > t diff --git a/tests/passing/unit-classes.t b/tests/passing/unit-classes.t new file mode 100644 index 00000000..322ff497 --- /dev/null +++ b/tests/passing/unit-classes.t @@ -0,0 +1,341 @@ + + $ cat > unit-classes.ml << "EOF" + > (** ocaml classes + > (http://caml.inria.fr/pub/docs/manual-ocaml/manual017.html) + > *) + > + > (* class types *) + > + > class type c = + > object + > end + > + > class type c = + > M.cl + > + > class type c = + > ['a, 'b] M.cl + > + > class type c = + > object + > ('ty) + > inherit cl + > val mutable virtual + > var : bool + > method private bar1 x ~y : bool + > method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t + > constraint + > 'a = 'b + > end + > + > (* class expressions *) + > + > class c = + > ['a, 'b] + > M.cl + > + > class c = + > fun a b -> + > object + > end + > + > class c = object + > val x = true + > end + > + > class c = + > object + > (_ : + > 'a) + > inherit Something.someclass + > as v + > val mutable + > var : bool + > = true + > val mutable virtual var2 + > : string + > method private bar1 x ~y : bool = + > false + > method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t + > constraint + > 'a = 'b + > initializer + > z + > end + > + > (* method specific expressions *) + > + > let e = + > var <- true + > + > let e = + > {< var = false; + > var2 = true; + > >} + > + > + > (* class definitions *) + > + > class cl = + > object + > val x = true + > end + > and + > virtual ['a, 'b] + > cl2 x y : + > object + > val x : bool + > end = fun x y -> + > object + > val x : bool = true + > end + > + > class cl + > : object end + > + > class type virtual ['a] clty = object + > method x : int + > end + > + > (* objects *) + > val a : + > < > + > let () = () + > + > val a : + > < .. > + > let () = () + > + > val a : + > < meth: int option; + > meth2: 'a. 'a option; + > meth3: 'a 'b. ('a,'b) Hashtbl.t > + > let () = () + > + > val a : + > < meth: int option; + > meth2: 'a. 'a option; + > meth3: 'a 'b. ('a,'b) Hashtbl.t; + > .. > + > let () = () + > + > (* #-types *) + > val a : + > #M.meth + > + > val a : + > 'a#M.meth + > + > val a : + > ('a,'b*'c) + > #M.meth + > + > (* object types *) + > type a = + > < > + > let () = () + > + > type a = + > < .. > + > let () = () + > + > type a = + > < meth: int option; + > meth2: 'a. 'a option; + > meth3: 'a 'b. ('a,'b) Hashtbl.t > + > let () = () + > + > type a = + > < meth: int option; + > meth2: 'a. 'a option; + > meth3: 'a 'b. ('a,'b) Hashtbl.t; + > .. > + > let () = () + > + > type t = + > < a : int; b: + > < a: int; b: < c:int > > + > > + > let () = () + > + > type t = + > < a : int; b: + > < a: int; b: < c: int -> int> >; + > c: int + > > + > let () = () + > + > type 'a t = + > | Bla : < x : int > t + > | Blo : < y : int > t + > EOF + + $ ocp-indent unit-classes.ml + (** ocaml classes + (http://caml.inria.fr/pub/docs/manual-ocaml/manual017.html) + *) + + (* class types *) + + class type c = + object + end + + class type c = + M.cl + + class type c = + ['a, 'b] M.cl + + class type c = + object + ('ty) + inherit cl + val mutable virtual + var : bool + method private bar1 x ~y : bool + method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t + constraint + 'a = 'b + end + + (* class expressions *) + + class c = + ['a, 'b] + M.cl + + class c = + fun a b -> + object + end + + class c = object + val x = true + end + + class c = + object + (_ : + 'a) + inherit Something.someclass + as v + val mutable + var : bool + = true + val mutable virtual var2 + : string + method private bar1 x ~y : bool = + false + method private virtual bar2 : 'a 'b.('a,'b) Hashtbl.t + constraint + 'a = 'b + initializer + z + end + + (* method specific expressions *) + + let e = + var <- true + + let e = + {< var = false; + var2 = true; + >} + + + (* class definitions *) + + class cl = + object + val x = true + end + and + virtual ['a, 'b] + cl2 x y : + object + val x : bool + end = fun x y -> + object + val x : bool = true + end + + class cl + : object end + + class type virtual ['a] clty = object + method x : int + end + + (* objects *) + val a : + < > + let () = () + + val a : + < .. > + let () = () + + val a : + < meth: int option; + meth2: 'a. 'a option; + meth3: 'a 'b. ('a,'b) Hashtbl.t > + let () = () + + val a : + < meth: int option; + meth2: 'a. 'a option; + meth3: 'a 'b. ('a,'b) Hashtbl.t; + .. > + let () = () + + (* #-types *) + val a : + #M.meth + + val a : + 'a#M.meth + + val a : + ('a,'b*'c) + #M.meth + + (* object types *) + type a = + < > + let () = () + + type a = + < .. > + let () = () + + type a = + < meth: int option; + meth2: 'a. 'a option; + meth3: 'a 'b. ('a,'b) Hashtbl.t > + let () = () + + type a = + < meth: int option; + meth2: 'a. 'a option; + meth3: 'a 'b. ('a,'b) Hashtbl.t; + .. > + let () = () + + type t = + < a : int; b: + < a: int; b: < c:int > > + > + let () = () + + type t = + < a : int; b: + < a: int; b: < c: int -> int> >; + c: int + > + let () = () + + type 'a t = + | Bla : < x : int > t + | Blo : < y : int > t diff --git a/tests/passing/unit-expr.ml b/tests/passing/unit-expr.ml deleted file mode 100644 index 66bf2efb..00000000 --- a/tests/passing/unit-expr.ml +++ /dev/null @@ -1,252 +0,0 @@ -(** ocaml expressions - (http://caml.inria.fr/pub/docs/manual-ocaml/expr.html) -*) - -let e = - Array.make - -let e = - true - -let e = - (true) - -let e = - begin - true - end - -let e = - (true: - bool) - -let e = - true, - false, - true - -let e = - Some - true - -let e = - `_ - true - -let e = - true :: - false :: - true - -let e = - [ true; - false; - true; - ] - -let e = - [| true; - false; - true - |] - -let e = - { f1 = true; - f2 = false; - f3 = true; - } - -let e = - { e with f1 = true; - f2 = false; - } - -let e = - f - true - false - true - -let e = - !? - true - -let e = - true - || false - && true - -let e = - 1 - mod 1 - land 1 - lor 1 - lxor 1 - lsl 1 - lsr 1 - asr 1 - -let e = - re.f1 - -let e = - re.f1 <- - true - -let e = - a.(0) <- - true - -let e = - a.[0] <- - true - -let e = - if - true - then - false - else - true - -let e = - while - true - do - () - done - -let e = - for x = - a - to - b - do - () - done - -let e = - true; - false; - true - -let e = - match - true - with - | true -> - false - | false - -> - true - -let e = match - true - with - | true -> - false - | false - -> - true - -let e = - function - | true -> - false - | false - -> - true - -let e = - fun - x - ~ lbl1 - ~ ( lbl2 : int ) - ~lbl3: _a - ? olbl1 - ? (olbl2 : 'a list = []) - ?olbl3: _c - ?olbl4: ( _d : bool = false ) - () - when - true - -> - true - -let e = - fun x -> - fun ~ lbl1 -> - fun ~ ( lbl2 : int ) -> - fun ~lbl3: _a -> - fun ? olbl1 -> - fun ? (olbl2 : 'a list = []) -> - fun ?olbl3: _c - when true - -> - fun ?olbl4: ( _d : bool = false ) -> - fun () - when - true - -> - true - -let e - x - ~ lbl1 - ~ ( lbl2 : int ) - ~lbl3: _a - ? olbl1 - ? (olbl2 : 'a list = []) - ?olbl3: _c - ?olbl4: ( _d : bool = false ) - () - = - true - -let e = - try - true - with - | Exit -> - true - | _ -> - false - -let e = - let rec - a = - true - and _b = - false - in - true - -let e = - new - foo - -let foo = - object - end - -let e = - foo# - bar1 - -let e = - (true :> - bool) - -let e = - (true : - bool :> - bool) - -let e = - assert - true - -let e = - lazy - true - diff --git a/tests/passing/unit-expr.t b/tests/passing/unit-expr.t new file mode 100644 index 00000000..300941b9 --- /dev/null +++ b/tests/passing/unit-expr.t @@ -0,0 +1,509 @@ + + $ cat > unit-expr.ml << "EOF" + > (** ocaml expressions + > (http://caml.inria.fr/pub/docs/manual-ocaml/expr.html) + > *) + > + > let e = + > Array.make + > + > let e = + > true + > + > let e = + > (true) + > + > let e = + > begin + > true + > end + > + > let e = + > (true: + > bool) + > + > let e = + > true, + > false, + > true + > + > let e = + > Some + > true + > + > let e = + > `_ + > true + > + > let e = + > true :: + > false :: + > true + > + > let e = + > [ true; + > false; + > true; + > ] + > + > let e = + > [| true; + > false; + > true + > |] + > + > let e = + > { f1 = true; + > f2 = false; + > f3 = true; + > } + > + > let e = + > { e with f1 = true; + > f2 = false; + > } + > + > let e = + > f + > true + > false + > true + > + > let e = + > !? + > true + > + > let e = + > true + > || false + > && true + > + > let e = + > 1 + > mod 1 + > land 1 + > lor 1 + > lxor 1 + > lsl 1 + > lsr 1 + > asr 1 + > + > let e = + > re.f1 + > + > let e = + > re.f1 <- + > true + > + > let e = + > a.(0) <- + > true + > + > let e = + > a.[0] <- + > true + > + > let e = + > if + > true + > then + > false + > else + > true + > + > let e = + > while + > true + > do + > () + > done + > + > let e = + > for x = + > a + > to + > b + > do + > () + > done + > + > let e = + > true; + > false; + > true + > + > let e = + > match + > true + > with + > | true -> + > false + > | false + > -> + > true + > + > let e = match + > true + > with + > | true -> + > false + > | false + > -> + > true + > + > let e = + > function + > | true -> + > false + > | false + > -> + > true + > + > let e = + > fun + > x + > ~ lbl1 + > ~ ( lbl2 : int ) + > ~lbl3: _a + > ? olbl1 + > ? (olbl2 : 'a list = []) + > ?olbl3: _c + > ?olbl4: ( _d : bool = false ) + > () + > when + > true + > -> + > true + > + > let e = + > fun x -> + > fun ~ lbl1 -> + > fun ~ ( lbl2 : int ) -> + > fun ~lbl3: _a -> + > fun ? olbl1 -> + > fun ? (olbl2 : 'a list = []) -> + > fun ?olbl3: _c + > when true + > -> + > fun ?olbl4: ( _d : bool = false ) -> + > fun () + > when + > true + > -> + > true + > + > let e + > x + > ~ lbl1 + > ~ ( lbl2 : int ) + > ~lbl3: _a + > ? olbl1 + > ? (olbl2 : 'a list = []) + > ?olbl3: _c + > ?olbl4: ( _d : bool = false ) + > () + > = + > true + > + > let e = + > try + > true + > with + > | Exit -> + > true + > | _ -> + > false + > + > let e = + > let rec + > a = + > true + > and _b = + > false + > in + > true + > + > let e = + > new + > foo + > + > let foo = + > object + > end + > + > let e = + > foo# + > bar1 + > + > let e = + > (true :> + > bool) + > + > let e = + > (true : + > bool :> + > bool) + > + > let e = + > assert + > true + > + > let e = + > lazy + > true + > + > EOF + + $ ocp-indent unit-expr.ml + (** ocaml expressions + (http://caml.inria.fr/pub/docs/manual-ocaml/expr.html) + *) + + let e = + Array.make + + let e = + true + + let e = + (true) + + let e = + begin + true + end + + let e = + (true: + bool) + + let e = + true, + false, + true + + let e = + Some + true + + let e = + `_ + true + + let e = + true :: + false :: + true + + let e = + [ true; + false; + true; + ] + + let e = + [| true; + false; + true + |] + + let e = + { f1 = true; + f2 = false; + f3 = true; + } + + let e = + { e with f1 = true; + f2 = false; + } + + let e = + f + true + false + true + + let e = + !? + true + + let e = + true + || false + && true + + let e = + 1 + mod 1 + land 1 + lor 1 + lxor 1 + lsl 1 + lsr 1 + asr 1 + + let e = + re.f1 + + let e = + re.f1 <- + true + + let e = + a.(0) <- + true + + let e = + a.[0] <- + true + + let e = + if + true + then + false + else + true + + let e = + while + true + do + () + done + + let e = + for x = + a + to + b + do + () + done + + let e = + true; + false; + true + + let e = + match + true + with + | true -> + false + | false + -> + true + + let e = match + true + with + | true -> + false + | false + -> + true + + let e = + function + | true -> + false + | false + -> + true + + let e = + fun + x + ~ lbl1 + ~ ( lbl2 : int ) + ~lbl3: _a + ? olbl1 + ? (olbl2 : 'a list = []) + ?olbl3: _c + ?olbl4: ( _d : bool = false ) + () + when + true + -> + true + + let e = + fun x -> + fun ~ lbl1 -> + fun ~ ( lbl2 : int ) -> + fun ~lbl3: _a -> + fun ? olbl1 -> + fun ? (olbl2 : 'a list = []) -> + fun ?olbl3: _c + when true + -> + fun ?olbl4: ( _d : bool = false ) -> + fun () + when + true + -> + true + + let e + x + ~ lbl1 + ~ ( lbl2 : int ) + ~lbl3: _a + ? olbl1 + ? (olbl2 : 'a list = []) + ?olbl3: _c + ?olbl4: ( _d : bool = false ) + () + = + true + + let e = + try + true + with + | Exit -> + true + | _ -> + false + + let e = + let rec + a = + true + and _b = + false + in + true + + let e = + new + foo + + let foo = + object + end + + let e = + foo# + bar1 + + let e = + (true :> + bool) + + let e = + (true : + bool :> + bool) + + let e = + assert + true + + let e = + lazy + true + diff --git a/tests/passing/unit-extensions.ml b/tests/passing/unit-extensions.ml deleted file mode 100644 index d069f621..00000000 --- a/tests/passing/unit-extensions.ml +++ /dev/null @@ -1,131 +0,0 @@ -(** ocaml language extensions - (http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html) -*) - -(* other integer literals *) -let i = 12l - + 0l - -let i = 12L - + 0l - -let i = 12n - + 0n - -(* range patterns *) -let f = function - | 'a'..'z' -> - e1 - | 'A'..'Z' - | '0'..'9' -> - e2 - -(* local modules *) -let f = - let module M = - F(struct end) - in - M.f x - -(* recursive modules *) -module rec M : S = -struct - ;; -end -and M1 : S1 = -struct - ;; -end - -(* private types *) -type t = private - X of string - | Y - -type t = private - { f1:t1; - f2: t2 } - -type t = - private t' - -(* local opens *) - -let _ = - let open - F(X) - in - () - -(* record shortcuts *) -let _ = - let x = 1 and y = 2 - in - { x; - y - } - -let f = function - | { x; - y; - _ - } -> - () - -(* locally abstract types *) -let f = fun - (type t) - (x: t) - -> - () - -let f - (type t) - (x: t) - = - () - -(* first-class modules *) -type m = - (module M.Sig - with type t = 'b) - * unit - -let x = - let m = - (module M : M.Sig - with type t = 'b) - in - let module M = - (val m : - M.sig - with type t = 'b) - in - M - -(* module type of *) -module type S = sig - include module type of M -end - -(* signature substitution *) -module type S = sig - include - M0 with type t := t - val x : unit -end - -(* class overriding *) -class cl = object - inherit! - cl - val! v = v - method! m = m -end - -(* GADTs *) -type _ t = - A: int t - | B: 'a t * 'b t -> ('a*'b) t - - diff --git a/tests/passing/unit-extensions.t b/tests/passing/unit-extensions.t new file mode 100644 index 00000000..d1c1af2c --- /dev/null +++ b/tests/passing/unit-extensions.t @@ -0,0 +1,267 @@ + + $ cat > unit-extensions.ml << "EOF" + > (** ocaml language extensions + > (http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html) + > *) + > + > (* other integer literals *) + > let i = 12l + > + 0l + > + > let i = 12L + > + 0l + > + > let i = 12n + > + 0n + > + > (* range patterns *) + > let f = function + > | 'a'..'z' -> + > e1 + > | 'A'..'Z' + > | '0'..'9' -> + > e2 + > + > (* local modules *) + > let f = + > let module M = + > F(struct end) + > in + > M.f x + > + > (* recursive modules *) + > module rec M : S = + > struct + > ;; + > end + > and M1 : S1 = + > struct + > ;; + > end + > + > (* private types *) + > type t = private + > X of string + > | Y + > + > type t = private + > { f1:t1; + > f2: t2 } + > + > type t = + > private t' + > + > (* local opens *) + > + > let _ = + > let open + > F(X) + > in + > () + > + > (* record shortcuts *) + > let _ = + > let x = 1 and y = 2 + > in + > { x; + > y + > } + > + > let f = function + > | { x; + > y; + > _ + > } -> + > () + > + > (* locally abstract types *) + > let f = fun + > (type t) + > (x: t) + > -> + > () + > + > let f + > (type t) + > (x: t) + > = + > () + > + > (* first-class modules *) + > type m = + > (module M.Sig + > with type t = 'b) + > * unit + > + > let x = + > let m = + > (module M : M.Sig + > with type t = 'b) + > in + > let module M = + > (val m : + > M.sig + > with type t = 'b) + > in + > M + > + > (* module type of *) + > module type S = sig + > include module type of M + > end + > + > (* signature substitution *) + > module type S = sig + > include + > M0 with type t := t + > val x : unit + > end + > + > (* class overriding *) + > class cl = object + > inherit! + > cl + > val! v = v + > method! m = m + > end + > + > (* GADTs *) + > type _ t = + > A: int t + > | B: 'a t * 'b t -> ('a*'b) t + > + > + > EOF + + $ ocp-indent unit-extensions.ml + (** ocaml language extensions + (http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html) + *) + + (* other integer literals *) + let i = 12l + + 0l + + let i = 12L + + 0l + + let i = 12n + + 0n + + (* range patterns *) + let f = function + | 'a'..'z' -> + e1 + | 'A'..'Z' + | '0'..'9' -> + e2 + + (* local modules *) + let f = + let module M = + F(struct end) + in + M.f x + + (* recursive modules *) + module rec M : S = + struct + ;; + end + and M1 : S1 = + struct + ;; + end + + (* private types *) + type t = private + X of string + | Y + + type t = private + { f1:t1; + f2: t2 } + + type t = + private t' + + (* local opens *) + + let _ = + let open + F(X) + in + () + + (* record shortcuts *) + let _ = + let x = 1 and y = 2 + in + { x; + y + } + + let f = function + | { x; + y; + _ + } -> + () + + (* locally abstract types *) + let f = fun + (type t) + (x: t) + -> + () + + let f + (type t) + (x: t) + = + () + + (* first-class modules *) + type m = + (module M.Sig + with type t = 'b) + * unit + + let x = + let m = + (module M : M.Sig + with type t = 'b) + in + let module M = + (val m : + M.sig + with type t = 'b) + in + M + + (* module type of *) + module type S = sig + include module type of M + end + + (* signature substitution *) + module type S = sig + include + M0 with type t := t + val x : unit + end + + (* class overriding *) + class cl = object + inherit! + cl + val! v = v + method! m = m + end + + (* GADTs *) + type _ t = + A: int t + | B: 'a t * 'b t -> ('a*'b) t + + diff --git a/tests/passing/unit-lex.ml b/tests/passing/unit-lex.ml deleted file mode 100644 index 614e1f4a..00000000 --- a/tests/passing/unit-lex.ml +++ /dev/null @@ -1,115 +0,0 @@ -(* -*- encoding: iso-8859-1 -*- *) - -(** ocaml lexical conventions - (http://caml.inria.fr/pub/docs/manual-ocaml/lex.html) -*) - -(* - *** literals *** -*) - -(* identifiers *) -let _id, - iD', - I9, - _'i, - A_', - u', - éçèæùà (* this file must be iso-8859-1 *) - = - _ -;; - -(* intergers *) -let _ = - -1 - + 0 - + 10_ - + -0xAFfe_0 + 0X1_ - + 0O7_0_1_2 + -0o12__ - - 0B0_1_0 + -0b111_ -;; - -(* floats *) -let _ = - 0. +. - 0.0 +. - 0e12 +. - 0.e1_ +. - 999e+1 +. - -9_99_E-0 +. - -.12. +. - 0_._e-1_2 -;; - -(* chars *) -[ 'a'; - '&'; - 'Ç'; - '§'; - '\\'; - '\"'; - '\''; - '\b'; - '\234'; - '\999'; (* wrong, but yet... *) - '\xAF' ] -;; - -(* strings *) -let _ = "'a';\n\ - \ '&';\ - 'Ç';\ - '§';\ - '\\';\ - '\"';\ - '\'';\ - '\b';\ - '\234';\ - '\999'; (* wrong, but yet... *)\ - '\xAF'" -;; - -(* naming labels *) -val f : - _l1 : int -> - ? _' : float -> - 'a -let rec f - ~ _l1 : int - ? _' : float = - f ~_l1: 0 ?_': 0e1 -;; - -(* prefix and infix symbols *) -_ = _ -<:~ _ -> _ - @ _ - ^$ _ - %% -;; - -!! ( ????: _ ) - -(* keywords *) -(* don't care about indentation, just should'nt crash :) *) -and as assert asr begin class -constraint do done downto else end -exception external false for fun function - functor if in include inherit initializer - land lazy let lor lsl lsr - lxor match method mod module mutable - new object of open or private - rec sig struct then to true - try type val virtual when while -with -;; - -(* line number directives *) -(* should be ignored and not indented: we may still want to indent generated - code for readability *) -#9999 "bla.ml\ \n\999" -let _ = -#9999 "bla.ml\ \n\999" - 0 diff --git a/tests/passing/unit-lex.t b/tests/passing/unit-lex.t new file mode 100644 index 00000000..14d85eb5 --- /dev/null +++ b/tests/passing/unit-lex.t @@ -0,0 +1,235 @@ + + $ cat > unit-lex.ml << "EOF" + > (* -*- encoding: iso-8859-1 -*- *) + > + > (** ocaml lexical conventions + > (http://caml.inria.fr/pub/docs/manual-ocaml/lex.html) + > *) + > + > (* + > *** literals *** + > *) + > + > (* identifiers *) + > let _id, + > iD', + > I9, + > _'i, + > A_', + > u', + > éçèæùà (* this file must be iso-8859-1 *) + > = + > _ + > ;; + > + > (* intergers *) + > let _ = + > -1 + > + 0 + > + 10_ + > + -0xAFfe_0 + 0X1_ + > + 0O7_0_1_2 + -0o12__ + > - 0B0_1_0 + -0b111_ + > ;; + > + > (* floats *) + > let _ = + > 0. +. + > 0.0 +. + > 0e12 +. + > 0.e1_ +. + > 999e+1 +. + > -9_99_E-0 +. + > -.12. +. + > 0_._e-1_2 + > ;; + > + > (* chars *) + > [ 'a'; + > '&'; + > 'Ç'; + > '§'; + > '\\'; + > '\"'; + > '\''; + > '\b'; + > '\234'; + > '\999'; (* wrong, but yet... *) + > '\xAF' ] + > ;; + > + > (* strings *) + > let _ = "'a';\n\ + > \ '&';\ + > 'Ç';\ + > '§';\ + > '\\';\ + > '\"';\ + > '\'';\ + > '\b';\ + > '\234';\ + > '\999'; (* wrong, but yet... *)\ + > '\xAF'" + > ;; + > + > (* naming labels *) + > val f : + > _l1 : int -> + > ? _' : float -> + > 'a + > let rec f + > ~ _l1 : int + > ? _' : float = + > f ~_l1: 0 ?_': 0e1 + > ;; + > + > (* prefix and infix symbols *) + > _ = _ + > <:~ _ + > > _ + > @ _ + > ^$ _ + > %% + > ;; + > + > !! ( ????: _ ) + > + > (* keywords *) + > (* don't care about indentation, just should'nt crash :) *) + > and as assert asr begin class + > constraint do done downto else end + > exception external false for fun function + > functor if in include inherit initializer + > land lazy let lor lsl lsr + > lxor match method mod module mutable + > new object of open or private + > rec sig struct then to true + > try type val virtual when while + > with + > ;; + > + > (* line number directives *) + > (* should be ignored and not indented: we may still want to indent generated + > code for readability *) + > #9999 "bla.ml\ \n\999" + > let _ = + > #9999 "bla.ml\ \n\999" + > 0 + > EOF + + $ ocp-indent unit-lex.ml + (* -*- encoding: iso-8859-1 -*- *) + + (** ocaml lexical conventions + (http://caml.inria.fr/pub/docs/manual-ocaml/lex.html) + *) + + (* + *** literals *** + *) + + (* identifiers *) + let _id, + iD', + I9, + _'i, + A_', + u', + éçèæùà (* this file must be iso-8859-1 *) + = + _ + ;; + + (* intergers *) + let _ = + -1 + + 0 + + 10_ + + -0xAFfe_0 + 0X1_ + + 0O7_0_1_2 + -0o12__ + - 0B0_1_0 + -0b111_ + ;; + + (* floats *) + let _ = + 0. +. + 0.0 +. + 0e12 +. + 0.e1_ +. + 999e+1 +. + -9_99_E-0 +. + -.12. +. + 0_._e-1_2 + ;; + + (* chars *) + [ 'a'; + '&'; + 'Ç'; + '§'; + '\\'; + '\"'; + '\''; + '\b'; + '\234'; + '\999'; (* wrong, but yet... *) + '\xAF' ] + ;; + + (* strings *) + let _ = "'a';\n\ + \ '&';\ + 'Ç';\ + '§';\ + '\\';\ + '\"';\ + '\'';\ + '\b';\ + '\234';\ + '\999'; (* wrong, but yet... *)\ + '\xAF'" + ;; + + (* naming labels *) + val f : + _l1 : int -> + ? _' : float -> + 'a + let rec f + ~ _l1 : int + ? _' : float = + f ~_l1: 0 ?_': 0e1 + ;; + + (* prefix and infix symbols *) + _ = _ + <:~ _ + > _ + @ _ + ^$ _ + %% + ;; + + !! ( ????: _ ) + + (* keywords *) + (* don't care about indentation, just should'nt crash :) *) + and as assert asr begin class + constraint do done downto else end + exception external false for fun function + functor if in include inherit initializer + land lazy let lor lsl lsr + lxor match method mod module mutable + new object of open or private + rec sig struct then to true + try type val virtual when while + with + ;; + + (* line number directives *) + (* should be ignored and not indented: we may still want to indent generated + code for readability *) + #9999 "bla.ml\ \n\999" + let _ = + #9999 "bla.ml\ \n\999" + 0 diff --git a/tests/passing/unit-modexpr.ml b/tests/passing/unit-modexpr.ml deleted file mode 100644 index 3e33cb8b..00000000 --- a/tests/passing/unit-modexpr.ml +++ /dev/null @@ -1,58 +0,0 @@ -(** ocaml module expressions - (http://caml.inria.fr/pub/docs/manual-ocaml/manual019.html) -*) - -module M = -struct -end - -module M = struct - ;; -end - -module M = - functor (M1 : T1) -> functor (M2 : T2) -> - struct - end - -module M = functor (M1 : T1) -> functor (M2 : T2) -> -struct -end - -module M = - functor (M1 : T1) -> - functor (M2 : T2) -> - struct - end - -module M = - functor - (M1 : T1) -> - functor - (M2 : T2) -> - struct - end - -module M = - F - (X) - (Y) - -module M = ( -struct -end : -sig -end -) - -module M : - Sig -= -struct -end - -module M - (X1: T1) - (X2: T2) = -struct end - diff --git a/tests/passing/unit-modexpr.t b/tests/passing/unit-modexpr.t new file mode 100644 index 00000000..489aff5f --- /dev/null +++ b/tests/passing/unit-modexpr.t @@ -0,0 +1,121 @@ + + $ cat > unit-modexpr.ml << "EOF" + > (** ocaml module expressions + > (http://caml.inria.fr/pub/docs/manual-ocaml/manual019.html) + > *) + > + > module M = + > struct + > end + > + > module M = struct + > ;; + > end + > + > module M = + > functor (M1 : T1) -> functor (M2 : T2) -> + > struct + > end + > + > module M = functor (M1 : T1) -> functor (M2 : T2) -> + > struct + > end + > + > module M = + > functor (M1 : T1) -> + > functor (M2 : T2) -> + > struct + > end + > + > module M = + > functor + > (M1 : T1) -> + > functor + > (M2 : T2) -> + > struct + > end + > + > module M = + > F + > (X) + > (Y) + > + > module M = ( + > struct + > end : + > sig + > end + > ) + > + > module M : + > Sig + > = + > struct + > end + > + > module M + > (X1: T1) + > (X2: T2) = + > struct end + > + > EOF + + $ ocp-indent unit-modexpr.ml + (** ocaml module expressions + (http://caml.inria.fr/pub/docs/manual-ocaml/manual019.html) + *) + + module M = + struct + end + + module M = struct + ;; + end + + module M = + functor (M1 : T1) -> functor (M2 : T2) -> + struct + end + + module M = functor (M1 : T1) -> functor (M2 : T2) -> + struct + end + + module M = + functor (M1 : T1) -> + functor (M2 : T2) -> + struct + end + + module M = + functor + (M1 : T1) -> + functor + (M2 : T2) -> + struct + end + + module M = + F + (X) + (Y) + + module M = ( + struct + end : + sig + end + ) + + module M : + Sig + = + struct + end + + module M + (X1: T1) + (X2: T2) = + struct end + diff --git a/tests/passing/unit-modtypes.ml b/tests/passing/unit-modtypes.ml deleted file mode 100644 index 7cc2dc10..00000000 --- a/tests/passing/unit-modtypes.ml +++ /dev/null @@ -1,80 +0,0 @@ -(** ocaml module types - (http://caml.inria.fr/pub/docs/manual-ocaml/manual018.html) -*) - -module type T = - M.T - -module type T = -sig -end - -module type T = sig - ;; -end - -module type T = - functor (M : T) -> - functor (M1 : T1) -> - sig - end - -module type T = -sig end -with type 'a t = 'b - and module M = M'.MF(X) - and type t' = t'' - -module type T = ( -sig -end -) - -module type T = -sig - val v : - t - - external x : 'a = - "stub" - - type t = - int - and t2 = - t - - exception Error - of int - - class virtual ['a] cl : - object - end - and cl2 : - object - end - - class type clt = - object - end - and ['a] clt2 = - object - end - - module M : - Sig - - module M (X) (Y): - Sig - - module type Sig - - module type Sig1 = - sig - end - - open - M - - include - M -end diff --git a/tests/passing/unit-modtypes.t b/tests/passing/unit-modtypes.t new file mode 100644 index 00000000..98beeae0 --- /dev/null +++ b/tests/passing/unit-modtypes.t @@ -0,0 +1,165 @@ + + $ cat > unit-modtypes.ml << "EOF" + > (** ocaml module types + > (http://caml.inria.fr/pub/docs/manual-ocaml/manual018.html) + > *) + > + > module type T = + > M.T + > + > module type T = + > sig + > end + > + > module type T = sig + > ;; + > end + > + > module type T = + > functor (M : T) -> + > functor (M1 : T1) -> + > sig + > end + > + > module type T = + > sig end + > with type 'a t = 'b + > and module M = M'.MF(X) + > and type t' = t'' + > + > module type T = ( + > sig + > end + > ) + > + > module type T = + > sig + > val v : + > t + > + > external x : 'a = + > "stub" + > + > type t = + > int + > and t2 = + > t + > + > exception Error + > of int + > + > class virtual ['a] cl : + > object + > end + > and cl2 : + > object + > end + > + > class type clt = + > object + > end + > and ['a] clt2 = + > object + > end + > + > module M : + > Sig + > + > module M (X) (Y): + > Sig + > + > module type Sig + > + > module type Sig1 = + > sig + > end + > + > open + > M + > + > include + > M + > end + > EOF + + $ ocp-indent unit-modtypes.ml + (** ocaml module types + (http://caml.inria.fr/pub/docs/manual-ocaml/manual018.html) + *) + + module type T = + M.T + + module type T = + sig + end + + module type T = sig + ;; + end + + module type T = + functor (M : T) -> + functor (M1 : T1) -> + sig + end + + module type T = + sig end + with type 'a t = 'b + and module M = M'.MF(X) + and type t' = t'' + + module type T = ( + sig + end + ) + + module type T = + sig + val v : + t + + external x : 'a = + "stub" + + type t = + int + and t2 = + t + + exception Error + of int + + class virtual ['a] cl : + object + end + and cl2 : + object + end + + class type clt = + object + end + and ['a] clt2 = + object + end + + module M : + Sig + + module M (X) (Y): + Sig + + module type Sig + + module type Sig1 = + sig + end + + open + M + + include + M + end diff --git a/tests/passing/unit-patterns.ml b/tests/passing/unit-patterns.ml deleted file mode 100644 index d12f38cb..00000000 --- a/tests/passing/unit-patterns.ml +++ /dev/null @@ -1,46 +0,0 @@ -(** ocaml patterns - (http://caml.inria.fr/pub/docs/manual-ocaml/patterns.html) -*) - -let _ = function - - x -> () | - - _ -> () | - - 'a' -> () | - - x as y -> () | - - (x: 'a -> 'b) -> () | - - x | y -> () | - - Some x -> () | - - `Var x -> () | - - #ty -> () | - - x, y -> () | - - { f1 = x; - f2 = y; - f3 = z; - _ - } -> () | - - [ x; - y; - z; - ] -> () | - - x::y - :: z -> () | - - [| x; - y; - z; - |] -> () | - - lazy w -> () diff --git a/tests/passing/unit-patterns.t b/tests/passing/unit-patterns.t new file mode 100644 index 00000000..9753420f --- /dev/null +++ b/tests/passing/unit-patterns.t @@ -0,0 +1,97 @@ + + $ cat > unit-patterns.ml << "EOF" + > (** ocaml patterns + > (http://caml.inria.fr/pub/docs/manual-ocaml/patterns.html) + > *) + > + > let _ = function + > + > x -> () | + > + > _ -> () | + > + > 'a' -> () | + > + > x as y -> () | + > + > (x: 'a -> 'b) -> () | + > + > x | y -> () | + > + > Some x -> () | + > + > `Var x -> () | + > + > #ty -> () | + > + > x, y -> () | + > + > { f1 = x; + > f2 = y; + > f3 = z; + > _ + > } -> () | + > + > [ x; + > y; + > z; + > ] -> () | + > + > x::y + > :: z -> () | + > + > [| x; + > y; + > z; + > |] -> () | + > + > lazy w -> () + > EOF + + $ ocp-indent unit-patterns.ml + (** ocaml patterns + (http://caml.inria.fr/pub/docs/manual-ocaml/patterns.html) + *) + + let _ = function + + x -> () | + + _ -> () | + + 'a' -> () | + + x as y -> () | + + (x: 'a -> 'b) -> () | + + x | y -> () | + + Some x -> () | + + `Var x -> () | + + #ty -> () | + + x, y -> () | + + { f1 = x; + f2 = y; + f3 = z; + _ + } -> () | + + [ x; + y; + z; + ] -> () | + + x::y + :: z -> () | + + [| x; + y; + z; + |] -> () | + + lazy w -> () diff --git a/tests/passing/unit-typedefs.ml b/tests/passing/unit-typedefs.ml deleted file mode 100644 index 24ae0b61..00000000 --- a/tests/passing/unit-typedefs.ml +++ /dev/null @@ -1,73 +0,0 @@ -(** ocaml type and exception definitions - (http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html) -*) - -type - t - -type - 'a t - -type - +'_a t - -type - -'a t - -type - ('a, - +'b, - (-'c,-'d)) - t - -type t = - t2 - -type t = - A - -type t = - A - | B of 'a - | C of 'a * 'b - | D of ('a) Array.t * 'b list - | E of _ - -type t = - { f1 : t1; - f2 : 'a; - mutable f3: t2; - f4 : - 'a 'b.t2; - } - -type 'a t - constraint 'a = t - constraint 'b = 'a - -type - ('a, - +'b, - (-'c,-'d)) - t - = - { f1 : t1; - f2 : 'a; - mutable f3: t2; - f4 : - t1 * t2; - } - constraint 'a = t - constraint 'b = 'a - - -exception - E - -exception - E of - 'a t * string - -exception - E' = - E diff --git a/tests/passing/unit-typedefs.t b/tests/passing/unit-typedefs.t new file mode 100644 index 00000000..20b6e9c7 --- /dev/null +++ b/tests/passing/unit-typedefs.t @@ -0,0 +1,151 @@ + + $ cat > unit-typedefs.ml << "EOF" + > (** ocaml type and exception definitions + > (http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html) + > *) + > + > type + > t + > + > type + > 'a t + > + > type + > +'_a t + > + > type + > -'a t + > + > type + > ('a, + > +'b, + > (-'c,-'d)) + > t + > + > type t = + > t2 + > + > type t = + > A + > + > type t = + > A + > | B of 'a + > | C of 'a * 'b + > | D of ('a) Array.t * 'b list + > | E of _ + > + > type t = + > { f1 : t1; + > f2 : 'a; + > mutable f3: t2; + > f4 : + > 'a 'b.t2; + > } + > + > type 'a t + > constraint 'a = t + > constraint 'b = 'a + > + > type + > ('a, + > +'b, + > (-'c,-'d)) + > t + > = + > { f1 : t1; + > f2 : 'a; + > mutable f3: t2; + > f4 : + > t1 * t2; + > } + > constraint 'a = t + > constraint 'b = 'a + > + > + > exception + > E + > + > exception + > E of + > 'a t * string + > + > exception + > E' = + > E + > EOF + + $ ocp-indent unit-typedefs.ml + (** ocaml type and exception definitions + (http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html) + *) + + type + t + + type + 'a t + + type + +'_a t + + type + -'a t + + type + ('a, + +'b, + (-'c,-'d)) + t + + type t = + t2 + + type t = + A + + type t = + A + | B of 'a + | C of 'a * 'b + | D of ('a) Array.t * 'b list + | E of _ + + type t = + { f1 : t1; + f2 : 'a; + mutable f3: t2; + f4 : + 'a 'b.t2; + } + + type 'a t + constraint 'a = t + constraint 'b = 'a + + type + ('a, + +'b, + (-'c,-'d)) + t + = + { f1 : t1; + f2 : 'a; + mutable f3: t2; + f4 : + t1 * t2; + } + constraint 'a = t + constraint 'b = 'a + + + exception + E + + exception + E of + 'a t * string + + exception + E' = + E diff --git a/tests/passing/unit-types.ml b/tests/passing/unit-types.ml deleted file mode 100644 index 54797722..00000000 --- a/tests/passing/unit-types.ml +++ /dev/null @@ -1,116 +0,0 @@ -(** ocaml type expressions - (http://caml.inria.fr/pub/docs/manual-ocaml/types.html) -*) - -(* variables *) -val a : - 'ident - -val a : - _ - -(* parentheses *) -val a : - ( t ) - -(* functions *) -val a : - int -> - int -> - t - -> t - -> t - -val a : - lab1: int - -> lab2 : - (t) - -> t - -val a : - ? lab1: - ( ?_ : int -> t ) - -> t - -(* tuples *) -val a : - (t1 * t2) * ( - t - ) - -(* constructed *) -val a : - int - -val a : - ('a -> 'b) Array.t - - -(* aliased *) -val a : - int - as 'bla - -(* polymorphic variants *) -val a : - [ `_ | `_' | - `_00 | - `Aa of int - ] - -val a : [ - | `_ | `_' | - `_00 | - `Aa of int -] - -val a : [< - `_ | `_' | - `_00 | - `Aa of int -] - -val a : - [ - | `_ | `_' | - `_00 | - `Aa of int - ] - -val a : [< - | `Bb of int - & string - & t | - int > - `a `_bbb - `c `d -] - -(* objects *) -val a : - < > - -val a : - < .. > - -val a : - < meth: int option; - meth2: 'a. 'a option; - meth3: 'a 'b. ('a,'b) Hashtbl.t > - -val a : - < meth: int option; - meth2: 'a. 'a option; - meth3: 'a 'b. ('a,'b) Hashtbl.t; - .. > - -(* #-types *) -val a : - #M.meth - -val a : - 'a#M.meth - -val a : - ('a,'b*'c) - #M.meth diff --git a/tests/passing/unit-types.t b/tests/passing/unit-types.t new file mode 100644 index 00000000..1f57325e --- /dev/null +++ b/tests/passing/unit-types.t @@ -0,0 +1,237 @@ + + $ cat > unit-types.ml << "EOF" + > (** ocaml type expressions + > (http://caml.inria.fr/pub/docs/manual-ocaml/types.html) + > *) + > + > (* variables *) + > val a : + > 'ident + > + > val a : + > _ + > + > (* parentheses *) + > val a : + > ( t ) + > + > (* functions *) + > val a : + > int -> + > int -> + > t + > -> t + > -> t + > + > val a : + > lab1: int + > -> lab2 : + > (t) + > -> t + > + > val a : + > ? lab1: + > ( ?_ : int -> t ) + > -> t + > + > (* tuples *) + > val a : + > (t1 * t2) * ( + > t + > ) + > + > (* constructed *) + > val a : + > int + > + > val a : + > ('a -> 'b) Array.t + > + > + > (* aliased *) + > val a : + > int + > as 'bla + > + > (* polymorphic variants *) + > val a : + > [ `_ | `_' | + > `_00 | + > `Aa of int + > ] + > + > val a : [ + > | `_ | `_' | + > `_00 | + > `Aa of int + > ] + > + > val a : [< + > `_ | `_' | + > `_00 | + > `Aa of int + > ] + > + > val a : + > [ + > | `_ | `_' | + > `_00 | + > `Aa of int + > ] + > + > val a : [< + > | `Bb of int + > & string + > & t | + > int > + > `a `_bbb + > `c `d + > ] + > + > (* objects *) + > val a : + > < > + > + > val a : + > < .. > + > + > val a : + > < meth: int option; + > meth2: 'a. 'a option; + > meth3: 'a 'b. ('a,'b) Hashtbl.t > + > + > val a : + > < meth: int option; + > meth2: 'a. 'a option; + > meth3: 'a 'b. ('a,'b) Hashtbl.t; + > .. > + > + > (* #-types *) + > val a : + > #M.meth + > + > val a : + > 'a#M.meth + > + > val a : + > ('a,'b*'c) + > #M.meth + > EOF + + $ ocp-indent unit-types.ml + (** ocaml type expressions + (http://caml.inria.fr/pub/docs/manual-ocaml/types.html) + *) + + (* variables *) + val a : + 'ident + + val a : + _ + + (* parentheses *) + val a : + ( t ) + + (* functions *) + val a : + int -> + int -> + t + -> t + -> t + + val a : + lab1: int + -> lab2 : + (t) + -> t + + val a : + ? lab1: + ( ?_ : int -> t ) + -> t + + (* tuples *) + val a : + (t1 * t2) * ( + t + ) + + (* constructed *) + val a : + int + + val a : + ('a -> 'b) Array.t + + + (* aliased *) + val a : + int + as 'bla + + (* polymorphic variants *) + val a : + [ `_ | `_' | + `_00 | + `Aa of int + ] + + val a : [ + | `_ | `_' | + `_00 | + `Aa of int + ] + + val a : [< + `_ | `_' | + `_00 | + `Aa of int + ] + + val a : + [ + | `_ | `_' | + `_00 | + `Aa of int + ] + + val a : [< + | `Bb of int + & string + & t | + int > + `a `_bbb + `c `d + ] + + (* objects *) + val a : + < > + + val a : + < .. > + + val a : + < meth: int option; + meth2: 'a. 'a option; + meth3: 'a 'b. ('a,'b) Hashtbl.t > + + val a : + < meth: int option; + meth2: 'a. 'a option; + meth3: 'a 'b. ('a,'b) Hashtbl.t; + .. > + + (* #-types *) + val a : + #M.meth + + val a : + 'a#M.meth + + val a : + ('a,'b*'c) + #M.meth diff --git a/tests/passing/unit-values.ml b/tests/passing/unit-values.ml deleted file mode 100644 index ce0b73f8..00000000 --- a/tests/passing/unit-values.ml +++ /dev/null @@ -1,39 +0,0 @@ -(** ocaml values - (http://caml.inria.fr/pub/docs/manual-ocaml/manual010.html) -*) - -(* base values *) -let i32 = −1073741824, 1073741823 -let i32_over = −1073741825, 1073741824 -let i32_over_big = −10737418240, 10737418230 -let i64 = -4611686018427387904, 4611686018427387903 -let i64_over = -4611686018427387905, 4611686018427387904 -let i64_over_big = -46116860184273879040, 46116860184273879030 - -let f = 4611686018427387903e-1022, 4611686018427387903e+1023 -let f_over = 4611686018427387903e-1023, 4611686018427387903e+1024 - -(* tuples *) -let _ = (1, 2, 3, 4, 5, - 1, 2, 3, 4, 5 - , 1, 2, 3, 4, 5) - -(* records *) -let _ = { f1 = 12; f2 = 13; - f3 = 14; f4 = 15; - f5 = 14; f6 = 15; - f7 = 14; f8 = 15; - } -let _ = { f1 = 12; f2 = 13; - M_.f3 = 14; M.f4 = 15; - M'.M3.f5 = 14; Mz.MM.f6 = 15; - Mg.f7 = 14; Fe.f8 = 15 - } -;; - -(* arrays *) -[| 5;468; 68;46;84;684;68;4; - 54;354;384;3;0;76;64;0;6; - 54;354;384;3;0;76;64;0;6; - 54;354;384;3;0;76;64;0;6; -|] diff --git a/tests/passing/unit-values.t b/tests/passing/unit-values.t new file mode 100644 index 00000000..10ce5d2a --- /dev/null +++ b/tests/passing/unit-values.t @@ -0,0 +1,83 @@ + + $ cat > unit-values.ml << "EOF" + > (** ocaml values + > (http://caml.inria.fr/pub/docs/manual-ocaml/manual010.html) + > *) + > + > (* base values *) + > let i32 = −1073741824, 1073741823 + > let i32_over = −1073741825, 1073741824 + > let i32_over_big = −10737418240, 10737418230 + > let i64 = -4611686018427387904, 4611686018427387903 + > let i64_over = -4611686018427387905, 4611686018427387904 + > let i64_over_big = -46116860184273879040, 46116860184273879030 + > + > let f = 4611686018427387903e-1022, 4611686018427387903e+1023 + > let f_over = 4611686018427387903e-1023, 4611686018427387903e+1024 + > + > (* tuples *) + > let _ = (1, 2, 3, 4, 5, + > 1, 2, 3, 4, 5 + > , 1, 2, 3, 4, 5) + > + > (* records *) + > let _ = { f1 = 12; f2 = 13; + > f3 = 14; f4 = 15; + > f5 = 14; f6 = 15; + > f7 = 14; f8 = 15; + > } + > let _ = { f1 = 12; f2 = 13; + > M_.f3 = 14; M.f4 = 15; + > M'.M3.f5 = 14; Mz.MM.f6 = 15; + > Mg.f7 = 14; Fe.f8 = 15 + > } + > ;; + > + > (* arrays *) + > [| 5;468; 68;46;84;684;68;4; + > 54;354;384;3;0;76;64;0;6; + > 54;354;384;3;0;76;64;0;6; + > 54;354;384;3;0;76;64;0;6; + > |] + > EOF + + $ ocp-indent unit-values.ml + (** ocaml values + (http://caml.inria.fr/pub/docs/manual-ocaml/manual010.html) + *) + + (* base values *) + let i32 = −1073741824, 1073741823 + let i32_over = −1073741825, 1073741824 + let i32_over_big = −10737418240, 10737418230 + let i64 = -4611686018427387904, 4611686018427387903 + let i64_over = -4611686018427387905, 4611686018427387904 + let i64_over_big = -46116860184273879040, 46116860184273879030 + + let f = 4611686018427387903e-1022, 4611686018427387903e+1023 + let f_over = 4611686018427387903e-1023, 4611686018427387903e+1024 + + (* tuples *) + let _ = (1, 2, 3, 4, 5, + 1, 2, 3, 4, 5 + , 1, 2, 3, 4, 5) + + (* records *) + let _ = { f1 = 12; f2 = 13; + f3 = 14; f4 = 15; + f5 = 14; f6 = 15; + f7 = 14; f8 = 15; + } + let _ = { f1 = 12; f2 = 13; + M_.f3 = 14; M.f4 = 15; + M'.M3.f5 = 14; Mz.MM.f6 = 15; + Mg.f7 = 14; Fe.f8 = 15 + } + ;; + + (* arrays *) + [| 5;468; 68;46;84;684;68;4; + 54;354;384;3;0;76;64;0;6; + 54;354;384;3;0;76;64;0;6; + 54;354;384;3;0;76;64;0;6; + |] diff --git a/tests/passing/variants.ml b/tests/passing/variants.ml deleted file mode 100644 index 2f95f039..00000000 --- a/tests/passing/variants.ml +++ /dev/null @@ -1,43 +0,0 @@ -type t = [ `aaa - | `bbb - | `ccc - ] - -type t = [ `aaa | `bbb - | `ccc - ] - -type t = - [ `aaa - | `bbb - | `ccc - ] - -type t = - [ `aaa | `bbb - | `ccc - ] - -type t = - [ - `aaa - | `bbb - | `ccc - ] - -type t = - [ - `aaa | `bbb - | `ccc - ] - -type t = [ - `aaa - | `bbb - | `ccc -] - -type t = [ - `aaa | `bbb - | `ccc -] diff --git a/tests/passing/variants.t b/tests/passing/variants.t new file mode 100644 index 00000000..6f9baa99 --- /dev/null +++ b/tests/passing/variants.t @@ -0,0 +1,91 @@ + + $ cat > variants.ml << "EOF" + > type t = [ `aaa + > | `bbb + > | `ccc + > ] + > + > type t = [ `aaa | `bbb + > | `ccc + > ] + > + > type t = + > [ `aaa + > | `bbb + > | `ccc + > ] + > + > type t = + > [ `aaa | `bbb + > | `ccc + > ] + > + > type t = + > [ + > `aaa + > | `bbb + > | `ccc + > ] + > + > type t = + > [ + > `aaa | `bbb + > | `ccc + > ] + > + > type t = [ + > `aaa + > | `bbb + > | `ccc + > ] + > + > type t = [ + > `aaa | `bbb + > | `ccc + > ] + > EOF + + $ ocp-indent variants.ml + type t = [ `aaa + | `bbb + | `ccc + ] + + type t = [ `aaa | `bbb + | `ccc + ] + + type t = + [ `aaa + | `bbb + | `ccc + ] + + type t = + [ `aaa | `bbb + | `ccc + ] + + type t = + [ + `aaa + | `bbb + | `ccc + ] + + type t = + [ + `aaa | `bbb + | `ccc + ] + + type t = [ + `aaa + | `bbb + | `ccc + ] + + type t = [ + `aaa | `bbb + | `ccc + ] diff --git a/tests/passing/with_2.ml b/tests/passing/with_2.ml deleted file mode 100644 index cabe3dcc..00000000 --- a/tests/passing/with_2.ml +++ /dev/null @@ -1,36 +0,0 @@ -let x = - try y with - | A -> _ - | B -> _ - -let x = try y with - | A -> _ - | B -> _ - -let x = - try y with - A -> _ - | B -> _ - -let x = try y with - A -> _ - | B -> _ - -let _ = - let x = - try y with - | A -> _ - | B -> _ - in - let x = try y with - | A -> _ - | B -> _ - in - let x = - try y with - A -> _ - | B -> _ - in - let x = try y with - A -> _ - | B -> _ diff --git a/tests/passing/with_2.ml.opts b/tests/passing/with_2.ml.opts deleted file mode 100644 index 051bd681..00000000 --- a/tests/passing/with_2.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c with=2 diff --git a/tests/passing/with_2.t b/tests/passing/with_2.t new file mode 100644 index 00000000..2f53b099 --- /dev/null +++ b/tests/passing/with_2.t @@ -0,0 +1,77 @@ + + $ cat > with_2.ml << "EOF" + > let x = + > try y with + > | A -> _ + > | B -> _ + > + > let x = try y with + > | A -> _ + > | B -> _ + > + > let x = + > try y with + > A -> _ + > | B -> _ + > + > let x = try y with + > A -> _ + > | B -> _ + > + > let _ = + > let x = + > try y with + > | A -> _ + > | B -> _ + > in + > let x = try y with + > | A -> _ + > | B -> _ + > in + > let x = + > try y with + > A -> _ + > | B -> _ + > in + > let x = try y with + > A -> _ + > | B -> _ + > EOF + + $ ocp-indent -c with=2 with_2.ml + let x = + try y with + | A -> _ + | B -> _ + + let x = try y with + | A -> _ + | B -> _ + + let x = + try y with + A -> _ + | B -> _ + + let x = try y with + A -> _ + | B -> _ + + let _ = + let x = + try y with + | A -> _ + | B -> _ + in + let x = try y with + | A -> _ + | B -> _ + in + let x = + try y with + A -> _ + | B -> _ + in + let x = try y with + A -> _ + | B -> _ diff --git a/tests/passing/with_never.ml b/tests/passing/with_never.ml deleted file mode 100644 index b1f3df69..00000000 --- a/tests/passing/with_never.ml +++ /dev/null @@ -1,58 +0,0 @@ -let f x = match x with -| `A -> "A" -| `B -> "B" - -let f = function -| `A -> "A" -| `B -> "B" - -let f = fun x -> match x with -| `A -> "A" -| `B -> "B" - -let f = - let g x = match x with - | `A -> "A" - | `B -> "B" - in - g - -let f = - let g = function - | `A -> "A" - | `B -> "B" - in - g - -let f = - let g = fun x -> match x with - | `A -> "A" - | `B -> "B" - in - g - -let z = - begin match - x - with - | X -> x - end - -let config_converter = - (fun str -> try (* just check syntax *) - ignore (IndentConfig.update_from_string IndentConfig.default str); - `Ok str - with Invalid_argument s -> `Error s), - ignore (IndentConfig.update_from_string IndentConfig.default str); - `Ok str - -let f = - try match a - with B -> x - with C -> y - -let g = - try match X with - | X -> X - with - | X -> Y diff --git a/tests/passing/with_never.ml.opts b/tests/passing/with_never.ml.opts deleted file mode 100644 index b8c2577d..00000000 --- a/tests/passing/with_never.ml.opts +++ /dev/null @@ -1 +0,0 @@ --c with=0,strict_with=always diff --git a/tests/passing/with_never.t b/tests/passing/with_never.t new file mode 100644 index 00000000..41ae71b2 --- /dev/null +++ b/tests/passing/with_never.t @@ -0,0 +1,121 @@ + + $ cat > with_never.ml << "EOF" + > let f x = match x with + > | `A -> "A" + > | `B -> "B" + > + > let f = function + > | `A -> "A" + > | `B -> "B" + > + > let f = fun x -> match x with + > | `A -> "A" + > | `B -> "B" + > + > let f = + > let g x = match x with + > | `A -> "A" + > | `B -> "B" + > in + > g + > + > let f = + > let g = function + > | `A -> "A" + > | `B -> "B" + > in + > g + > + > let f = + > let g = fun x -> match x with + > | `A -> "A" + > | `B -> "B" + > in + > g + > + > let z = + > begin match + > x + > with + > | X -> x + > end + > + > let config_converter = + > (fun str -> try (* just check syntax *) + > ignore (IndentConfig.update_from_string IndentConfig.default str); + > `Ok str + > with Invalid_argument s -> `Error s), + > ignore (IndentConfig.update_from_string IndentConfig.default str); + > `Ok str + > + > let f = + > try match a + > with B -> x + > with C -> y + > + > let g = + > try match X with + > | X -> X + > with + > | X -> Y + > EOF + + $ ocp-indent -c with=0,strict_with=always with_never.ml + let f x = match x with + | `A -> "A" + | `B -> "B" + + let f = function + | `A -> "A" + | `B -> "B" + + let f = fun x -> match x with + | `A -> "A" + | `B -> "B" + + let f = + let g x = match x with + | `A -> "A" + | `B -> "B" + in + g + + let f = + let g = function + | `A -> "A" + | `B -> "B" + in + g + + let f = + let g = fun x -> match x with + | `A -> "A" + | `B -> "B" + in + g + + let z = + begin match + x + with + | X -> x + end + + let config_converter = + (fun str -> try (* just check syntax *) + ignore (IndentConfig.update_from_string IndentConfig.default str); + `Ok str + with Invalid_argument s -> `Error s), + ignore (IndentConfig.update_from_string IndentConfig.default str); + `Ok str + + let f = + try match a + with B -> x + with C -> y + + let g = + try match X with + | X -> X + with + | X -> Y diff --git a/tests/test.sh b/tests/test.sh deleted file mode 100755 index 1eeb00f8..00000000 --- a/tests/test.sh +++ /dev/null @@ -1,332 +0,0 @@ -#!/bin/bash -ue -# -# Copyright 2012-2013 OCamlPro -# -# All rights reserved.This file is distributed under the terms of the -# GNU Lesser General Public License version 2.1 with linking -# exception. -# -# TypeRex is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# Lesser GNU General Public License for more details. -# - -shopt -s nullglob - -ROOT=$(git rev-parse --show-toplevel | tr -d '\r') -OCP_INDENT=$ROOT/_build/install/default/bin/ocp-indent -cd $ROOT/tests - -UPDATE= -GIT= -SHOW= -SHOWCMD= -HTML= - -usegit() { - printf "%-12s\t\e[34mgit %s\e[m\n" "" "$*"; - git "$@"; -} - -is_file_on_git() { - [ $# -eq 1 ]; f=$1 - git ls-files $f --error-unmatch >/dev/null 2>&1 -} - -while [ $# -gt 0 ]; do - case "$1" in - --update|-u) - UPDATE=1 - ;; - --git-update) - if ! git diff --ignore-cr-at-eol --exit-code -- . >/dev/null; then - echo -e "\e[1mWarning:\e[m unstaged changes in tests/" - echo "You may want to do 'git checkout -- tests/' or"\ - "'git add -u -- tests/' first." - exit 1 - fi - UPDATE=1 - GIT="usegit " - HTML=1 - ;; - --ocp-indent) - if [ $# -le 1 ]; then echo "Error: $1 needs an argument"; exit 1; fi - shift; - OCP_INDENT=$1 - ;; - --show) - SHOW=1 - ;; - --meld) - SHOW=1 - SHOWCMD="meld" - ;; - --html) - HTML=1 - ;; - *) - cat </dev/stderr -Usage: - -u --update update the files according to the current results - --git-update update the files and state the changes in git - --ocp-indent use this ocp-indent exe - --show show a diff of changed results - --meld show progressions/regressions using meld - --html generate an html page showing the diff of failing tests -EOF - exit 1 - esac - shift -done - -TMP=$(mktemp -d /tmp/ocp-indent-test.XXXXX) -trap "rm -rf /tmp/ocp-indent-${TMP#/tmp/ocp-indent-}" EXIT - -ocp-indent() { - [ $# -eq 1 ] - opts=$(cat $1.opts 2>/dev/null || true) - "$OCP_INDENT" $opts "$1" >$TMP/$(basename $1) 2>&1 || true -} - -ocp-indent-i() { - [ $# -eq 1 ] - opts=$(cat $1.opts 2>/dev/null || true) - "$OCP_INDENT" "-i" $opts "$1" >/dev/null 2>&1 || true -} - - - -reffile() { - [ $# -eq 1 ] - if [ -e "$1.ref" ] - then echo "$1.ref" - else echo "$1" - fi -} - -PASSING=("") -FAILING=("") -INPLACE=("") -if [ -n "$GIT" ]; then - PASSING+=($(git ls-files 'passing/*.ml' 'passing/*.ml[iyl]')) - FAILING+=($(git ls-files 'failing/*.ml' 'failing/*.ml[iyl]')) - INPLACE+=($(git ls-files 'inplace/*.ml' 'inplace/*.ml[iyl]')) -else - PASSING+=(passing/*.ml passing/*.ml[iyl]) - FAILING+=(failing/*.ml failing/*.ml[iyl]) - INPLACE+=(inplace/*.ml inplace/*.ml[iyl]) -fi -CHANGES=() - - -for f in ${PASSING[@]}; do - base=$(basename $f) - name=${base%.*} - ocp-indent $f - if diff --strip-trailing-cr -q "$(reffile "$f")" $TMP/$base >/dev/null; then - printf "%-12s\t\e[32m[PASSED]\e[m\n" $name - else - printf "%-12s\t\e[31m[FAILED]\e[m \e[41m\e[30m[REGRESSION]\e[m\n" $name - if [ -n "$UPDATE" ]; then - mkdir -p failing - $GIT mv -f $f* failing/ - f=failing/${f#passing/} - mkdir -p failing-output - cp $TMP/$base failing-output/ - if [ -n "$GIT" ]; then $GIT add failing-output/$base; fi - fi - CHANGES+=($f) - fi -done - -for f in ${FAILING[@]}; do - base=$(basename $f) - name=${base%.*} - ocp-indent $f - if diff --strip-trailing-cr -q $(reffile $f) $TMP/$base >/dev/null; then - printf "%-12s\t\e[32m[PASSED]\e[m \e[42m\e[30m[PROGRESSION]\e[m\n" $name - if [ -n "$UPDATE" ]; then - $GIT mv -f $f* passing/ - $GIT rm -f failing-output/$base - fi - elif [ ! -e failing-output/$base ]; then - printf "%-12s\t\e[33m[FAILED]\e[m \e[43m\e[30m[NEW]\e[m\n" $name - cp $TMP/$base failing-output/ - if [ -n "$GIT" ]; then $GIT add failing-output/$base; fi - elif diff --strip-trailing-cr -q $TMP/$base failing-output/$base >/dev/null; then - printf "%-12s\t\e[33m[FAILED]\e[m\n" $name - if [ -n "$GIT" ] && ! is_file_on_git failing-output/$base; then - $GIT add failing-output/$base; fi - else - refcount=$(diff --strip-trailing-cr -y --suppress-common-lines \ - $(reffile $f) failing-output/$base \ - |wc -l) - curcount=$(diff --strip-trailing-cr -y --suppress-common-lines \ - $(reffile $f) $TMP/$base \ - |wc -l) - progress=$((refcount - curcount)) - printf "%-12s\t\e[33m[FAILED]\e[m \e[%dm\e[30m[CHANGE: %+d]\e[m\n" \ - $name \ - $(if [ $progress -gt 0 ]; then echo 42; \ - elif [ $progress -eq 0 ]; then echo 43; \ - else echo 41; fi) \ - $progress - if [ -n "$UPDATE" ]; then - mkdir -p failing-output - cp $TMP/$base failing-output/ - if [ -n "$GIT" ]; then $GIT add failing-output/$base; fi - fi - CHANGES+=($f) - fi -done - -for f in ${INPLACE[@]}; do - base=$(basename $f) - name=${base%.*} - if [ -L $f ]; then - dest=$(readlink $f) - ocp-indent-i $f - if [ -L $f -a $(readlink $f) = $dest ]; then - printf "%-12s\t\e[32m[PASSED]\e[m\n" $name - else - printf "%-12s\t\e[31m[FAILED]\e[m (nothing will be put in CHANGES)\n" $name - rm -f $f - ln -s $dest $f - fi - else - perm=$(stat -c '%a' $f) - ocp-indent-i $f - if [ $(stat -c '%a' $f) = $perm ]; then - printf "%-12s\t\e[32m[PASSED]\e[m\n" $name - else - printf "%-12s\t\e[31m[FAILED]\e[m (nothing will be put in CHANGES)\n" $name - chmod $perm $f - fi - fi -done - -if [ -n "$SHOW" ] && [ ${#CHANGES[@]} -gt 0 ]; then - if [ -z "$SHOWCMD" ]; then - for f in ${CHANGES[@]}; do - echo - printf "\e[1m=== Showing differences in %s ===\e[m\n" $f - # Custom less buggy version of colordiff -y - diff --strip-trailing-cr -W 130 -ty $(reffile $f) $TMP/$(basename $f) \ - | awk '/^.{64}[^ ].*/ { printf "%s\n",$0; next } 1' \ - || true - done - else - echo - echo "Meld view:" - echo "[reference] [new result] [registered]" - echo "You can update reference and registered status from meld" - cmd=(meld) - for f in ${CHANGES[@]}; do - cur=failing-output/$(basename $f) - if ! [ -e $cur ]; then cur=; fi - cmd+=(--diff $(reffile $f) $TMP/$(basename $f) $cur) - done - ${cmd[*]} - fi -elif [ -n "$SHOW" ]; then - echo - echo "No changes to show. To check the current failures use for example:" - echo " meld tests/failing tests/failing-output" -fi - -diff2html() { - f1=$1; shift - f2=$1; shift - [ $# -eq 0 ] - - echo "
    " - echo "

    Differences in $(basename $f1)

    " - echo "" - echo "" - - { - line=0 - XIFS="$IFS" - IFS= - while read -r l1; do - read -r l2 <&3 || true - class="correct" - if [ "$l1" != "$l2" ]; then - class="different" - l1=$(sed 's/ /·/g' <<<"$l1") - l2=$(sed 's/ /·/g' <<<"$l2") - fi - echo -n '' - echo -n '' - echo -n '' - echo -n '' - echo '' - : $((line++)) - done - while read -r l2 <&3; do - l2=$(sed 's/ /·/g' <<<"$l2") - echo -n '' - echo -n '' - echo -n '' - echo -n '' - echo '' - : $((line++)) - done - IFS="$XIFS" - } <$f1 3<$f2 - - echo "
    ExpectedOcp-indent output
    '$line'
    '"$l1"'
    '"$l2"'
    '$line'
    '"$l2"'
    " - echo "
    " -} - -if [ -n "$HTML" ]; then - VERSION=$($OCP_INDENT --version | awk '{ print $NF; exit }') - if COMMITS_SINCE=$(git log --oneline $VERSION.. 2>/dev/null); then - VERSION="$VERSION+$((1+$(wc -l <<<"$COMMITS_SINCE")))" - fi - VERSION_STRING="$VERSION ($(date +%F))" - echo - echo -n "Generating summary of failures tests/failing.html..." - cat < failing.html - - - - Failing tests, ocp-indent version $VERSION_STRING - - - - -

    Failing tests, ocp-indent version $VERSION_STRING

    -EOF - complete_success="1" - for f in $(git ls-files 'failing/*.ml'); do - complete_success= - diff2html "$(reffile $f)" "failing-output/${f#failing/}" \ - >>failing.html - echo -n "." - done - if [ -n "$complete_success" ]; then - echo "

    All tests pass: no currently known bugs.

    " >>failing.html - fi - cat <>failing.html - - -EOF - - echo " done" - if [ -n "$GIT" ]; then $GIT add failing.html; fi -fi - -exit ${#CHANGES[@]}