From 59087dc4e84f00a3d2d5ac501ae14f82cd4ef9fb Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 5 Nov 2020 15:17:42 +0100 Subject: [PATCH 1/7] test_comments: init --- lib/Conf.mli | 10 ++++++ test/comments/dune | 3 ++ test/comments/test_comments.ml | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 test/comments/dune create mode 100644 test/comments/test_comments.ml diff --git a/lib/Conf.mli b/lib/Conf.mli index f44bd3428c..5c169c1597 100644 --- a/lib/Conf.mli +++ b/lib/Conf.mli @@ -83,6 +83,16 @@ type t = ; wrap_comments: bool (** Wrap comments at margin. *) ; wrap_fun_args: bool } +val ocamlformat_profile : t + +val conventional_profile : t + +val compact_profile : t + +val sparse_profile : t + +val janestreet_profile : t + type file = Stdin | File of string type kind = Kind : _ list Migrate_ast.Traverse.fragment -> kind diff --git a/test/comments/dune b/test/comments/dune new file mode 100644 index 0000000000..b4be3b4de0 --- /dev/null +++ b/test/comments/dune @@ -0,0 +1,3 @@ +(executable + (name test_comments) + (libraries cmdliner ocamlformat_lib stdio)) diff --git a/test/comments/test_comments.ml b/test/comments/test_comments.ml new file mode 100644 index 0000000000..f6aac57d2d --- /dev/null +++ b/test/comments/test_comments.ml @@ -0,0 +1,57 @@ +open Ocamlformat_lib + +let rec all_tokens acc lexbuf = + let tok = Lexer.token_with_comments lexbuf in + let acc = lexbuf.lex_start_p.pos_cnum :: acc in + if tok = Migrate_ast.Parser.EOF then acc else all_tokens acc lexbuf + +(** Return the offset at which every tokens start. *) +let token_offsets source = + let lexbuf = Lexing.from_string source in + Lexer.init () ; + Lexer.skip_hash_bang lexbuf ; + List.rev (all_tokens [] lexbuf) + +let insert_at_every_offsets insert toffs source ~f = + let ilen = String.length insert and slen = String.length source in + let buff = Bytes.create (ilen + slen) in + Bytes.blit_string source 0 buff ilen slen ; + let rec loop head_i = function + | hd :: tl -> + (* Move previous token from after [insert] to before (overriding it). *) + Bytes.blit buff (head_i + ilen) buff head_i (hd - head_i) ; + (* Blit again [insert]. *) + Bytes.blit_string insert 0 buff hd (String.length insert) ; + f (Bytes.unsafe_to_string buff) ; + loop hd tl + | [] -> () + in + loop 0 toffs + +let run file = + let conf = Conf.conventional_profile + and opts = + Conf.{debug= false; margin_check= false; format_invalid_files= false} + in + let source = Stdio.In_channel.read_all file in + let toffs = token_offsets source in + insert_at_every_offsets "(* toto *)" toffs source ~f:(fun source -> + match + Translation_unit.parse_and_format Migrate_ast.Traverse.Structure + ~input_name:file ~source conf opts + with + | Ok formatted -> Printf.printf "%s\n" formatted + | Error err -> + Translation_unit.print_error ~debug:false ~quiet:true + ~input_name:file err ) + +open Cmdliner + +let cmd = + let a_file = Arg.(required & pos 0 (some file) None & info []) in + let doc = + "Repeatedly test ocamlformat with a comment before every tokens." + in + Term.(const run $ a_file, info ~doc "test_comments") + +let () = Term.exit (Term.eval cmd) From 7cc5e3e402c87ad02641e233b707485dc32f4298 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 5 Nov 2020 18:57:05 +0100 Subject: [PATCH 2/7] test_comments: compute diffs --- test/comments/diff.ml | 277 +++++++++++++++++++++++++++++++++ test/comments/diff.mli | 36 +++++ test/comments/test_comments.ml | 214 +++++++++++++++++++++++-- 3 files changed, 516 insertions(+), 11 deletions(-) create mode 100644 test/comments/diff.ml create mode 100644 test/comments/diff.mli diff --git a/test/comments/diff.ml b/test/comments/diff.ml new file mode 100644 index 0000000000..506ba63c1f --- /dev/null +++ b/test/comments/diff.ml @@ -0,0 +1,277 @@ +(** Thanks @craigfe, https://github.com/CraigFe/diff *) + +type index = int + +type 'a command = + | Insert of { expected : index; actual : index } + (** Insert the element [actual.(actual)] at [expected.(expected)]. *) + | Delete of { expected : index } + (** Delete the element at [expected.(expected)]. *) + | Substitute of { expected : index; actual : index } + (** Set [expected.(expected)) := actual.(actual)]. *) + +let pp_command ppf = function + | Insert { expected; actual } -> + Format.fprintf ppf "Insert { expected = %d; actual = %d }" expected actual + | Delete { expected } -> + Format.fprintf ppf "Delete { expected = %d }" expected + | Substitute { expected; actual } -> + Format.fprintf ppf "Substitute { expected = %d; actual = %d }" expected + actual + +let map_expected f = function + | Insert i -> Insert { i with expected = f i.expected } + | Delete d -> Delete { expected = f d.expected } + | Substitute s -> Substitute { s with expected = f s.expected } + +let map_actual f = function + | Insert i -> Insert { i with actual = f i.actual } + | Substitute s -> Substitute { s with actual = f s.actual } + | Delete _ as d -> d + +let insert expected actual = Insert { expected; actual } +let delete expected = Delete { expected } +let substitute expected actual = Substitute { expected; actual } + +type ('a, _) typ = + | Array : ('a, 'a array) typ + | List : ('a, 'a list) typ + | String : (char, string) typ + +module Subarray : sig + type 'a t + (** Read-only wrapper around an array or a string. Can be {!truncate}d in + [O(1)] time. *) + + val truncate : origin:int -> length:int -> 'a t -> 'a t + (** Return a new subarray with smaller bounds than the previous one. *) + + val empty : _ t + val get : 'a t -> int -> 'a + val length : 'a t -> int + val of_container : ('a, 'container) typ -> 'container -> 'a t +end = struct + type 'a t = { get : int -> 'a; origin : int; length : int } + + let truncate ~origin ~length + {get; origin = prev_origin; length = prev_length} = + if origin < prev_origin || length > prev_length then + failwith + (Format.sprintf + "Cannot expand array during truncation ({ origin = %d; length = %d \ + } -> { origin = %d; length = %d })" + prev_origin prev_length origin length ) ; + {get; origin; length} + + let index_oob = Format.ksprintf invalid_arg "index out of bounds: %d" + let empty = { get = index_oob; origin = 0; length = 0 } + + let get { get; origin; length } i = + if i >= length then index_oob i; + get (i + origin) + + let length { length; _ } = length + let of_array a = { get = Array.get a; origin = 0; length = Array.length a } + let of_list l = Array.of_list l |> of_array + let of_string s = { get = String.get s; origin = 0; length = String.length s } + + let of_container (type a container) : (a, container) typ -> container -> a t = + function + | Array -> of_array + | List -> of_list + | String -> of_string +end + +module Edit_script = struct + type 'a t = 'a command list + + let insert n v t = + let rec inner acc n t = + match (n, t) with + | 0, t -> List.rev_append acc (v :: t) + | _, [] -> List.rev (v :: acc) + | n, x :: xs -> inner (x :: acc) (n - 1) xs + in + inner [] n t + + let delete n t = + let rec inner acc n t = + match (n, t) with + | 0, _ :: xs -> List.rev_append acc xs + | n, x :: xs -> inner (x :: acc) (n - 1) xs + | _ -> assert false + in + inner [] n t + + let substitute n v t = + let rec inner acc n t = + match (n, t) with + | 0, _ :: xs -> List.rev acc @ (v :: xs) + | n, x :: xs -> inner (x :: acc) (n - 1) xs + | _ -> assert false + in + inner [] n t + + let apply (type a container) (typ : (a, container) typ) + ~actual:(t_actual : int -> a) (script : a t) (initial : container) : + a list = + let initial : a list = + match typ with + | List -> initial + | Array -> Array.to_list initial + | String -> List.init (String.length initial) (fun i -> initial.[i]) + in + List.fold_left + (fun (i, acc) -> function + | Insert { expected; actual } -> + (i + 1, insert (expected + i) (t_actual actual) acc) + | Delete { expected } -> (i - 1, delete (expected + i) acc) + | Substitute { expected; actual } -> + (i, substitute (expected + i) (t_actual actual) acc)) + (0, initial) script + |> snd +end + +let triple_minimum (a, b, c) = + min (min a b) c + +let triple_minimum_on f (a, b, c) = + let ab = if f a > f b then b else a in + if f ab > f c then c else ab + +(** Standard dynamic programming algorithm for Levenshtein edit scripts. This + works in two phases: + + 1. construct a {i cost matrix} of edit distances for each _prefix_ of the + two strings; + + 2. reconstruct an edit script from the cost matrix. + + The standard algorithm uses a cost matrix of size [n * m]. If we only care + about edit scripts up to some maximum length [b], the space and time + complexity can be reduced to [O(max (n, m) * b)] (assuming an [O(1)] + equality function). *) + +(** Phase 1: compute the cost matrix, bottom-up. *) +let construct_grid (type a) ~(equal : a -> a -> bool) (a : a Subarray.t) + (b : a Subarray.t) : int array array = + let grid_x_length = Subarray.length a + 1 + and grid_y_length = Subarray.length b + 1 in + let grid = Array.make_matrix grid_x_length grid_y_length 0 in + let get_grid (x, y) = grid.(x).(y) in + + for i = 0 to grid_x_length - 1 do + for j = 0 to grid_y_length - 1 do + let cost = + if min i j = 0 then max i j + else if equal (Subarray.get a (i - 1)) (Subarray.get b (j - 1)) then + get_grid (i - 1, j - 1) + else + triple_minimum + (get_grid (i - 1, j), get_grid (i, j - 1), get_grid (i - 1, j - 1)) + + 1 + in + grid.(i).(j) <- cost + done + done; + grid + +(** Phase 2: reconstruct the edit script from the cost matrix. *) +let reconstruct_edit_script a b grid = + let get_grid (x, y) = grid.(x).(y) in + + (* Reverse-engineer the direction and action towards a given cell *) + let backtrack (i, j) = + let p_sub = (i - 1, j - 1) and p_ins = (i, j - 1) and p_del = (i - 1, j) in + if Subarray.get a (i - 1) = Subarray.get b (j - 1) then (p_sub, []) + else + ( (`Substitute, get_grid p_sub + 1), + (`Insert, get_grid p_ins), + (`Delete, get_grid p_del) ) + |> triple_minimum_on snd + |> function + | `Substitute, _ -> (p_sub, [ substitute (fst p_sub) (snd p_sub) ]) + | `Insert, _ -> (p_ins, [ insert (fst p_ins) (snd p_ins) ]) + | `Delete, _ -> (p_del, [ delete (fst p_del) ]) + in + + let rec aux acc (x, y) = + match (x, y) with + | 0, 0 -> acc + | i, 0 -> List.init i delete @ acc + | 0, j -> List.init j (insert 0) @ acc + | pos -> + let next_coord, action = backtrack pos in + (aux [@tailcall]) (action @ acc) next_coord + in + let x_len, y_len = Array.length grid, Array.length grid.(0) in + aux [] (x_len - 1, y_len - 1) + +let ( >> ) f g x = g (f x) + +let levenshtein_dp ~equal (a_origin, b_origin) a b = + let grid = construct_grid ~equal a b in + reconstruct_edit_script a b grid + (* Map the command indices to the true coordinates *) + |> List.map (map_expected (( + ) a_origin) >> map_actual (( + ) b_origin)) + +(** Strip common prefixes and suffixes of the input sequences can be stripped + (in linear time) to avoid running the full dynamic programming algorithm on + them. *) +let strip_common_outer (type a) ~equal ((a : a Subarray.t), (b : a Subarray.t)) + = + let len_a = Subarray.length a and len_b = Subarray.length b in + + (* Shift the lower indices upwards until they point to non-equal values in the + arrays (or we scan an entire array). *) + let rec raise_lower_bound (i, j) = + match (i >= len_a, j >= len_b) with + | true, true -> `Equal + | false, false when equal (Subarray.get a i) (Subarray.get b j) -> + raise_lower_bound (i + 1, j + 1) + | a_oob, b_oob -> + let i = if a_oob then None else Some i in + let j = if b_oob then None else Some j in + `Non_equal (i, j) + in + match raise_lower_bound (0, 0) with + | `Equal -> `Equal (* The arrays are equal *) + (* One array is a prefix of the other *) + | `Non_equal (None, None) -> + `Non_equal ((0, 0), (Subarray.empty, Subarray.empty)) + | `Non_equal (None, Some j) -> + `Non_equal + ( (j, j), + (Subarray.empty, Subarray.truncate ~origin:j ~length:(len_b - j) b) ) + | `Non_equal (Some i, None) -> + `Non_equal + ( (i, i), + (Subarray.truncate ~origin:i ~length:(len_a - i) a, Subarray.empty) ) + | `Non_equal (Some i_origin, Some j_origin) -> ( + let rec lower_upper_bound (i, j) = + match (i < i_origin, j < j_origin) with + | true, true -> `Equal + | false, false when equal (Subarray.get a i) (Subarray.get b j) -> + lower_upper_bound (i - 1, j - 1) + | _ -> `Non_equal (i, j) + in + match lower_upper_bound (len_a - 1, len_b - 1) with + | `Equal -> + assert false (* We already decided that the arrays are non-equal *) + | `Non_equal (i_last, j_last) -> + `Non_equal + ( (i_origin, j_origin), + ( Subarray.truncate ~origin:i_origin + ~length:(i_last - i_origin + 1) + a, + Subarray.truncate ~origin:j_origin + ~length:(j_last - j_origin + 1) + b ) ) ) + +let levenshtein_script (type a container) (typ : (a, container) typ) + ~(equal : a -> a -> bool) (a : container) (b : container) : a Edit_script.t + = + let a, b = (Subarray.of_container typ a, Subarray.of_container typ b) in + match strip_common_outer ~equal (a, b) with + | `Equal -> [] + | `Non_equal (origin, (a, b)) -> levenshtein_dp ~equal origin a b diff --git a/test/comments/diff.mli b/test/comments/diff.mli new file mode 100644 index 0000000000..10455b2e01 --- /dev/null +++ b/test/comments/diff.mli @@ -0,0 +1,36 @@ +type index := int + +type 'a command = + | Insert of { expected : index; actual : index } + (** Insert the element [actual.(actual)] at [expected.(expected)]. *) + | Delete of { expected : index } + (** Delete the element at [expected.(expected)]. *) + | Substitute of { expected : index; actual : index } + (** Set [expected.(expected)) := actual.(actual)]. *) + +val pp_command : Format.formatter -> 'a command -> unit + +type ('elt, 'container) typ = + | Array : ('a, 'a array) typ + | List : ('a, 'a list) typ + | String : (char, string) typ + +module Edit_script : sig + type 'a t = 'a command list + + val apply : + ('elt, 'container) typ -> + actual:(index -> 'elt) -> + 'elt t -> + 'container -> + 'elt list +end + +val levenshtein_script : + ('a, 'container) typ -> + equal:('a -> 'a -> bool) -> + 'container -> + 'container -> + 'a Edit_script.t +(** [O(n^2)]-space computation of Levenshtein edit scripts. Guarantees to be + [O(n)] time in the case that the containers are equal. *) diff --git a/test/comments/test_comments.ml b/test/comments/test_comments.ml index f6aac57d2d..5768a47929 100644 --- a/test/comments/test_comments.ml +++ b/test/comments/test_comments.ml @@ -1,20 +1,22 @@ open Ocamlformat_lib -let rec all_tokens acc lexbuf = +let rec lex_source acc lexbuf = let tok = Lexer.token_with_comments lexbuf in - let acc = lexbuf.lex_start_p.pos_cnum :: acc in - if tok = Migrate_ast.Parser.EOF then acc else all_tokens acc lexbuf + let tok = Token_latest.of_compiler_libs tok in + let acc = (tok, lexbuf.lex_start_p.pos_cnum) :: acc in + if tok = Migrate_ast.Parser.EOF then acc else lex_source acc lexbuf -(** Return the offset at which every tokens start. *) -let token_offsets source = +(** Return every tokens and the offset at which they start. *) +let lex_source source = let lexbuf = Lexing.from_string source in Lexer.init () ; Lexer.skip_hash_bang lexbuf ; - List.rev (all_tokens [] lexbuf) + List.rev (lex_source [] lexbuf) let insert_at_every_offsets insert toffs source ~f = let ilen = String.length insert and slen = String.length source in let buff = Bytes.create (ilen + slen) in + (* Keep room on the left for [insert]. *) Bytes.blit_string source 0 buff ilen slen ; let rec loop head_i = function | hd :: tl -> @@ -22,25 +24,215 @@ let insert_at_every_offsets insert toffs source ~f = Bytes.blit buff (head_i + ilen) buff head_i (hd - head_i) ; (* Blit again [insert]. *) Bytes.blit_string insert 0 buff hd (String.length insert) ; - f (Bytes.unsafe_to_string buff) ; + f hd (Bytes.unsafe_to_string buff) ; loop hd tl | [] -> () in loop 0 toffs +let unlex_quoted_string ?op str del = + let op_sep = match (op, del) with Some _, Some _ -> " " | _ -> "" + and op = Option.value ~default:"" op + and del = Option.value ~default:"" del in + Format.sprintf "{%s%s%s|%s|%s}" op op_sep del str del + +let unlex_token = function + | Migrate_ast.Parser.AMPERAMPER -> "&&" + | AMPERSAND -> "&" + | AND -> "and" + | AS -> "as" + | ASSERT -> "assert" + | BACKQUOTE -> "`" + | BANG -> "!" + | BAR -> "|" + | BARBAR -> "||" + | BARRBRACKET -> "|]" + | BEGIN -> "begin" + | CHAR c -> Format.sprintf "'%c'" c + | CLASS -> "class" + | COLON -> ":" + | COLONCOLON -> "::" + | COLONEQUAL -> ":=" + | COLONGREATER -> ":>" + | COMMA -> "," + | COMMENT (cmt, _) -> Format.sprintf "(*%s*)" cmt + | CONSTRAINT -> "constraint" + | DOCSTRING d -> Format.sprintf "(**%s*)" (Docstrings.docstring_body d) + | DO -> "do" + | DONE -> "done" + | DOT -> "." + | DOTDOT -> ".." + | DOTOP op -> "." ^ op + | DOWNTO -> "downto" + | ELSE -> "else" + | END -> "end" + | EOF -> "" + | EOL -> "\n" + | EQUAL -> "=" + | EXCEPTION -> "exception" + | EXTERNAL -> "external" + | FALSE -> "false" + | FLOAT (r, None) | INT (r, None) -> r + | FLOAT (r, Some m) | INT (r, Some m) -> r ^ String.make 1 m + | FOR -> "for" + | FUNCTION -> "function" + | FUNCTOR -> "functor" + | FUN -> "fun" + | GREATER -> ">" + | GREATERRBRACE -> ">}" + | GREATERRBRACKET -> ">]" + | HASH -> "#" + | IF -> "if" + | INCLUDE -> "include" + | INHERIT -> "inherit" + | IN -> "in" + | INITIALIZER -> "initializer" + | LABEL n -> Format.sprintf "~%s:" n + | LAZY -> "lazy" + | LBRACE -> "{" + | LBRACELESS -> "{<" + | LBRACKET -> "[" + | LBRACKETAT -> "[@" + | LBRACKETATAT -> "[@@" + | LBRACKETATATAT -> "[@@@" + | LBRACKETBAR -> "[|" + | LBRACKETGREATER -> "[>" + | LBRACKETLESS -> "[<" + | LBRACKETPERCENT -> "[%" + | LBRACKETPERCENTPERCENT -> "[%%" + | LESS -> "<" + | LESSMINUS -> "<-" + | LET -> "let" + | LETOP op + |ANDOP op + |PREFIXOP op + |INFIXOP4 op + |INFIXOP3 op + |INFIXOP2 op + |INFIXOP1 op + |INFIXOP0 op + |HASHOP op -> + op + | LIDENT _1 | UIDENT _1 -> _1 + | LPAREN -> "(" + | MATCH -> "match" + | METHOD -> "method" + | MINUS -> "-" + | MINUSDOT -> "-." + | MINUSGREATER -> "->" + | MODULE -> "module" + | MUTABLE -> "mutable" + | NEW -> "new" + | NONREC -> "nonrec" + | OBJECT -> "object" + | OF -> "of" + | OPEN -> "open" + | OPTLABEL n -> Format.sprintf "?%s:" n + | OR -> "or" + | PERCENT -> "%" + | PLUS -> "+" + | PLUSDOT -> "+." + | PLUSEQ -> "+=" + | PRIVATE -> "private" + | QUESTION -> "?" + | QUOTE -> "\"" + | QUOTED_STRING_EXPR (id, _, str, _, del) -> + unlex_quoted_string ~op:("@" ^ id) str del + | QUOTED_STRING_ITEM (id, _, str, _, del) -> + unlex_quoted_string ~op:("%" ^ id) str del + | RBRACE -> "}" + | RBRACKET -> "]" + | REC -> "rec" + | RPAREN -> ")" + | SEMI -> ";" + | SEMISEMI -> ";;" + | SIG -> "sig" + | STAR -> "*" + | STRING (str, _, None) -> Format.sprintf "%S" str + | STRING (str, _, (Some _ as del)) -> unlex_quoted_string str del + | STRUCT -> "struct" + | THEN -> "then" + | TILDE -> "~" + | TO -> "to" + | TRUE -> "true" + | TRY -> "try" + | TYPE -> "type" + | UNDERSCORE -> "_" + | VAL -> "val" + | VIRTUAL -> "virtual" + | WHEN -> "when" + | WHILE -> "while" + | WITH -> "with" + +(** Ignore location diff *) +let token_equal a b = + let open Migrate_ast.Parser in + match (a, b) with + | STRING (a, _, a'), STRING (b, _, b') -> a = b && a' = b' + | ( QUOTED_STRING_EXPR (a, _, a', _, a'') + , QUOTED_STRING_EXPR (b, _, b', _, b'') ) + |( QUOTED_STRING_ITEM (a, _, a', _, a'') + , QUOTED_STRING_ITEM (b, _, b', _, b'') ) -> + a = b && a' = b' && a'' = b'' + | COMMENT (a, _), COMMENT (b, _) -> a = b + | a, b -> a = b + +let diff_sources a b = + let a, a_offsets = List.split (lex_source a) + and b = List.map fst (lex_source b) in + let a_offsets = Array.of_list a_offsets + and a = Array.of_list a + and b = Array.of_list b in + let add i tok = (`Add, a_offsets.(i), tok) + and del i tok = (`Del, a_offsets.(i), tok) in + let diff = + Diff.(levenshtein_script Array) ~equal:token_equal a b + |> List.fold_left + (fun acc -> function + | Diff.Insert {expected; actual} -> add expected b.(actual) :: acc + | Delete {expected} -> del expected a.(expected) :: acc + | Substitute {expected; actual} -> + del expected a.(expected) :: add expected b.(actual) :: acc ) + [] + in + diff + +(** On top of [unlex_token] with special cases. *) +let print_token = function + | Migrate_ast.Parser.EOL -> "" + | EOF -> "" + | tok -> unlex_token tok + +let print_diff insert_offset insert_len diff = + let pp_diff = + let pp_log fmt (op, offset, tok) = + let op = match op with `Add -> '+' | `Del -> '-' in + Format.fprintf fmt "%d: %c %s" offset op (print_token tok) + in + Format.pp_print_list pp_log + in + Format.printf "@[DIFF (inserted at %d-%d):@ %a@]@\n" insert_offset + (insert_offset + insert_len) + pp_diff diff + let run file = let conf = Conf.conventional_profile and opts = Conf.{debug= false; margin_check= false; format_invalid_files= false} in - let source = Stdio.In_channel.read_all file in - let toffs = token_offsets source in - insert_at_every_offsets "(* toto *)" toffs source ~f:(fun source -> + let initial_source = Stdio.In_channel.read_all file in + let toffs = List.map snd (lex_source initial_source) in + let insert = "(* toto *)" in + insert_at_every_offsets insert toffs initial_source + ~f:(fun insert_offset source -> match Translation_unit.parse_and_format Migrate_ast.Traverse.Structure ~input_name:file ~source conf opts with - | Ok formatted -> Printf.printf "%s\n" formatted + | Ok formatted -> ( + match diff_sources source formatted with + | [] -> () + | diff -> print_diff insert_offset (String.length insert) diff ) | Error err -> Translation_unit.print_error ~debug:false ~quiet:true ~input_name:file err ) From 0c51af6552e16a06ace4c8b401f552ea0426ba66 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 5 Nov 2020 19:11:53 +0100 Subject: [PATCH 3/7] test_comments: setup cram test --- test/comments/dune | 9 +- test/comments/test_comments.t/run.t | 201 ++++++++++++++++++ test/comments/test_comments.t/test.ml | 12 ++ test/comments/{ => test_comments}/diff.ml | 0 test/comments/{ => test_comments}/diff.mli | 0 test/comments/test_comments/dune | 3 + .../{ => test_comments}/test_comments.ml | 0 7 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 test/comments/test_comments.t/run.t create mode 100644 test/comments/test_comments.t/test.ml rename test/comments/{ => test_comments}/diff.ml (100%) rename test/comments/{ => test_comments}/diff.mli (100%) create mode 100644 test/comments/test_comments/dune rename test/comments/{ => test_comments}/test_comments.ml (100%) diff --git a/test/comments/dune b/test/comments/dune index b4be3b4de0..b8e0a0554a 100644 --- a/test/comments/dune +++ b/test/comments/dune @@ -1,3 +1,6 @@ -(executable - (name test_comments) - (libraries cmdliner ocamlformat_lib stdio)) +(env + (_ + (binaries + (test_comments/test_comments.exe as test_comments)))) + +(cram (deps %{bin:test_comments})) diff --git a/test/comments/test_comments.t/run.t b/test/comments/test_comments.t/run.t new file mode 100644 index 0000000000..a86bbcb10a --- /dev/null +++ b/test/comments/test_comments.t/run.t @@ -0,0 +1,201 @@ +For every tokens in the test file, insert a comment at that position, format +then compute the diff at the token level. + +File "test.ml" should contain most syntaxes. + + $ test_comments test.ml + DIFF (inserted at 0-10): + 151: - + 10: + + 10: + + DIFF (inserted at 7-17): + 152: - + DIFF (inserted at 9-19): + 152: - + DIFF (inserted at 11-21): + 152: - + DIFF (inserted at 12-22): + 152: - + DIFF (inserted at 13-23): + 151: - + 23: + (* toto *) + 21: - (* toto *) + 21: + + DIFF (inserted at 14-24): + 151: - + 24: + + 24: + + DIFF (inserted at 21-31): + 152: - + DIFF (inserted at 23-33): + 151: - + 72: + (* toto *) + 31: - (* toto *) + DIFF (inserted at 25-35): + 152: - + DIFF (inserted at 28-38): + 151: - + 38: + (* toto *) + 36: - (* toto *) + 36: + + DIFF (inserted at 31-41): + 151: - + 41: + + 41: + + DIFF (inserted at 36-46): + 151: - + 46: + type + 46: + + 44: - (* toto *) + 31: - type + 31: + (* toto *) + DIFF (inserted at 37-47): + 152: - + DIFF (inserted at 38-48): + 151: - + 48: + (* toto *) + 46: - (* toto *) + 46: + + DIFF (inserted at 41-51): + 151: - + 51: + + 51: + + DIFF (inserted at 45-55): + 152: - + DIFF (inserted at 47-57): + 152: - + DIFF (inserted at 49-59): + 152: - + DIFF (inserted at 51-61): + 152: - + DIFF (inserted at 54-64): + 152: - + DIFF (inserted at 55-65): + 152: - + DIFF (inserted at 56-66): + 151: - + 66: + + 66: + (* toto *) + 64: - (* toto *) + 64: + + DIFF (inserted at 60-70): + 152: - + DIFF (inserted at 62-72): + 152: - + DIFF (inserted at 68-78): + 151: - + 78: + (* toto *) + 76: - (* toto *) + 76: + + DIFF (inserted at 71-81): + 151: - + 81: + + 81: + + DIFF (inserted at 76-86): + 151: - + 86: + type + 86: + + 84: - (* toto *) + 71: - type + 71: + (* toto *) + DIFF (inserted at 78-88): + 151: - + 132: + (* toto *) + 132: + + 132: + + 86: - (* toto *) + DIFF (inserted at 80-90): + 152: - + DIFF (inserted at 82-92): + 151: - + 109: + + 92: + + 92: + (* toto *) + 90: - (* toto *) + 90: + + 80: + | + 80: + + DIFF (inserted at 84-94): + 152: - + DIFF (inserted at 86-96): + 152: - + DIFF (inserted at 89-99): + 152: - + DIFF (inserted at 93-103): + 152: - + DIFF (inserted at 95-105): + 152: - + DIFF (inserted at 99-109): + 151: - + 109: + + 109: + (* toto *) + 107: - (* toto *) + 107: + + 82: + + 80: + | + 80: + + DIFF (inserted at 101-111): + 152: - + DIFF (inserted at 103-113): + 152: - + DIFF (inserted at 106-116): + 151: - + 117: + (* toto *) + 114: - (* toto *) + DIFF (inserted at 107-117): + 152: - + DIFF (inserted at 108-118): + 152: - + DIFF (inserted at 110-120): + 152: - + DIFF (inserted at 113-123): + 151: - + 125: + (* toto *) + 121: - (* toto *) + DIFF (inserted at 115-125): + 152: - + DIFF (inserted at 116-126): + 152: - + DIFF (inserted at 118-128): + 152: - + DIFF (inserted at 121-131): + 152: - + DIFF (inserted at 122-132): + 152: - + DIFF (inserted at 123-133): + 151: - + 133: + (* toto *) + 131: - (* toto *) + 131: + + DIFF (inserted at 126-136): + 151: - + 136: + + 136: + + DIFF (inserted at 130-140): + 152: - + DIFF (inserted at 132-142): + 152: - + DIFF (inserted at 134-144): + 152: - + DIFF (inserted at 136-146): + 152: - + DIFF (inserted at 137-147): + 152: + end + 148: - end + 148: + (* toto *) + 145: - (* toto *) + 145: + + DIFF (inserted at 138-148): + 152: + end + 148: - end + 148: + (* toto *) + 146: - (* toto *) + 146: + + DIFF (inserted at 141-151): + 152: + (* toto *) + 149: - (* toto *) + 149: + + DIFF (inserted at 142-152): + 150: + + DIFF (inserted at 143-153): + 153: + diff --git a/test/comments/test_comments.t/test.ml b/test/comments/test_comments.t/test.ml new file mode 100644 index 0000000000..fd6900435c --- /dev/null +++ b/test/comments/test_comments.t/test.ml @@ -0,0 +1,12 @@ +module M = M + +module M : sig + type t + + val f : t -> t +end = struct + type t = A | B of int * int | C of {a: int; b: int} + + let f x = x +end + diff --git a/test/comments/diff.ml b/test/comments/test_comments/diff.ml similarity index 100% rename from test/comments/diff.ml rename to test/comments/test_comments/diff.ml diff --git a/test/comments/diff.mli b/test/comments/test_comments/diff.mli similarity index 100% rename from test/comments/diff.mli rename to test/comments/test_comments/diff.mli diff --git a/test/comments/test_comments/dune b/test/comments/test_comments/dune new file mode 100644 index 0000000000..b4be3b4de0 --- /dev/null +++ b/test/comments/test_comments/dune @@ -0,0 +1,3 @@ +(executable + (name test_comments) + (libraries cmdliner ocamlformat_lib stdio)) diff --git a/test/comments/test_comments.ml b/test/comments/test_comments/test_comments.ml similarity index 100% rename from test/comments/test_comments.ml rename to test/comments/test_comments/test_comments.ml From 9d87d5bbf8ff2c58fea608082a4ee6a8f505cdd4 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 6 Nov 2020 16:40:59 +0100 Subject: [PATCH 4/7] Better presentation of diffs --- test/comments/test_comments.t/run.t | 264 +++++-------------- test/comments/test_comments.t/test.ml | 1 - test/comments/test_comments/test_comments.ml | 69 +++-- 3 files changed, 100 insertions(+), 234 deletions(-) diff --git a/test/comments/test_comments.t/run.t b/test/comments/test_comments.t/run.t index a86bbcb10a..60d4859a0f 100644 --- a/test/comments/test_comments.t/run.t +++ b/test/comments/test_comments.t/run.t @@ -4,198 +4,72 @@ then compute the diff at the token level. File "test.ml" should contain most syntaxes. $ test_comments test.ml - DIFF (inserted at 0-10): - 151: - - 10: + - 10: + - DIFF (inserted at 7-17): - 152: - - DIFF (inserted at 9-19): - 152: - - DIFF (inserted at 11-21): - 152: - - DIFF (inserted at 12-22): - 152: - - DIFF (inserted at 13-23): - 151: - - 23: + (* toto *) - 21: - (* toto *) - 21: + - DIFF (inserted at 14-24): - 151: - - 24: + - 24: + - DIFF (inserted at 21-31): - 152: - - DIFF (inserted at 23-33): - 151: - - 72: + (* toto *) - 31: - (* toto *) - DIFF (inserted at 25-35): - 152: - - DIFF (inserted at 28-38): - 151: - - 38: + (* toto *) - 36: - (* toto *) - 36: + - DIFF (inserted at 31-41): - 151: - - 41: + - 41: + - DIFF (inserted at 36-46): - 151: - - 46: + type - 46: + - 44: - (* toto *) - 31: - type - 31: + (* toto *) - DIFF (inserted at 37-47): - 152: - - DIFF (inserted at 38-48): - 151: - - 48: + (* toto *) - 46: - (* toto *) - 46: + - DIFF (inserted at 41-51): - 151: - - 51: + - 51: + - DIFF (inserted at 45-55): - 152: - - DIFF (inserted at 47-57): - 152: - - DIFF (inserted at 49-59): - 152: - - DIFF (inserted at 51-61): - 152: - - DIFF (inserted at 54-64): - 152: - - DIFF (inserted at 55-65): - 152: - - DIFF (inserted at 56-66): - 151: - - 66: + - 66: + (* toto *) - 64: - (* toto *) - 64: + - DIFF (inserted at 60-70): - 152: - - DIFF (inserted at 62-72): - 152: - - DIFF (inserted at 68-78): - 151: - - 78: + (* toto *) - 76: - (* toto *) - 76: + - DIFF (inserted at 71-81): - 151: - - 81: + - 81: + - DIFF (inserted at 76-86): - 151: - - 86: + type - 86: + - 84: - (* toto *) - 71: - type - 71: + (* toto *) - DIFF (inserted at 78-88): - 151: - - 132: + (* toto *) - 132: + - 132: + - 86: - (* toto *) - DIFF (inserted at 80-90): - 152: - - DIFF (inserted at 82-92): - 151: - - 109: + - 92: + - 92: + (* toto *) - 90: - (* toto *) - 90: + - 80: + | - 80: + - DIFF (inserted at 84-94): - 152: - - DIFF (inserted at 86-96): - 152: - - DIFF (inserted at 89-99): - 152: - - DIFF (inserted at 93-103): - 152: - - DIFF (inserted at 95-105): - 152: - - DIFF (inserted at 99-109): - 151: - - 109: + - 109: + (* toto *) - 107: - (* toto *) - 107: + - 82: + - 80: + | - 80: + - DIFF (inserted at 101-111): - 152: - - DIFF (inserted at 103-113): - 152: - - DIFF (inserted at 106-116): - 151: - - 117: + (* toto *) - 114: - (* toto *) - DIFF (inserted at 107-117): - 152: - - DIFF (inserted at 108-118): - 152: - - DIFF (inserted at 110-120): - 152: - - DIFF (inserted at 113-123): - 151: - - 125: + (* toto *) - 121: - (* toto *) - DIFF (inserted at 115-125): - 152: - - DIFF (inserted at 116-126): - 152: - - DIFF (inserted at 118-128): - 152: - - DIFF (inserted at 121-131): - 152: - - DIFF (inserted at 122-132): - 152: - - DIFF (inserted at 123-133): - 151: - - 133: + (* toto *) - 131: - (* toto *) - 131: + - DIFF (inserted at 126-136): - 151: - - 136: + - 136: + - DIFF (inserted at 130-140): - 152: - - DIFF (inserted at 132-142): - 152: - - DIFF (inserted at 134-144): - 152: - - DIFF (inserted at 136-146): - 152: - - DIFF (inserted at 137-147): - 152: + end - 148: - end - 148: + (* toto *) - 145: - (* toto *) - 145: + - DIFF (inserted at 138-148): - 152: + end - 148: - end - 148: + (* toto *) - 146: - (* toto *) - 146: + - DIFF (inserted at 141-151): - 152: + (* toto *) - 149: - (* toto *) - 149: + - DIFF (inserted at 142-152): - 150: + - DIFF (inserted at 143-153): - 153: + + insertion offset = 0 + before: (* toto *) module M + after: (* toto *) module M + insertion offset = 13 + before: (* toto *) + after: (* toto *) + insertion offset = 14 + before: (* toto *) module M + after: (* toto *) module M + insertion offset = 23 + before: M (* toto *) : sig type t val f : t -> t end = struct + after: M : sig type t val f : t -> t end = (* toto *) struct + insertion offset = 28 + before: sig (* toto *) + after: sig (* toto *) + insertion offset = 31 + before: (* toto *) type t + after: (* toto *) type t + insertion offset = 36 + before: type (* toto *) t + after: (* toto *) type t + insertion offset = 38 + before: (* toto *) + after: (* toto *) + insertion offset = 41 + before: (* toto *) val f + after: (* toto *) val f + insertion offset = 56 + before: (* toto *) end = + after: (* toto *) end = + insertion offset = 68 + before: struct (* toto *) + after: struct (* toto *) + insertion offset = 71 + before: (* toto *) type t + after: (* toto *) type t + insertion offset = 76 + before: type (* toto *) t = + after: (* toto *) type t = + insertion offset = 78 + before: t (* toto *) = A | B of int * int | C of { a : int ; b : int } + after: t = A | B of int * int | C of { a : int ; b : int } (* toto *) + insertion offset = 82 + before: = A (* toto *) | B of int * int | C + after: = | A (* toto *) | B of int * int | C + insertion offset = 99 + before: = A | B of int * int (* toto *) | C + after: = | A | B of int * int (* toto *) | C + insertion offset = 106 + before: of (* toto *) { a : + after: of { (* toto *) a : + insertion offset = 123 + before: (* toto *) + after: (* toto *) + insertion offset = 126 + before: (* toto *) let f + after: (* toto *) let f + insertion offset = 137 + before: x (* toto *) + after: x (* toto *) + insertion offset = 138 + before: (* toto *) end + after: (* toto *) end + insertion offset = 141 + before: end (* toto *) + after: end (* toto *) + insertion offset = 142 + before: (* toto *) + after: (* toto *) diff --git a/test/comments/test_comments.t/test.ml b/test/comments/test_comments.t/test.ml index fd6900435c..dd85c5f9de 100644 --- a/test/comments/test_comments.t/test.ml +++ b/test/comments/test_comments.t/test.ml @@ -9,4 +9,3 @@ end = struct let f x = x end - diff --git a/test/comments/test_comments/test_comments.ml b/test/comments/test_comments/test_comments.ml index 5768a47929..91d6e38539 100644 --- a/test/comments/test_comments/test_comments.ml +++ b/test/comments/test_comments/test_comments.ml @@ -177,46 +177,37 @@ let token_equal a b = | COMMENT (a, _), COMMENT (b, _) -> a = b | a, b -> a = b -let diff_sources a b = - let a, a_offsets = List.split (lex_source a) - and b = List.map fst (lex_source b) in - let a_offsets = Array.of_list a_offsets - and a = Array.of_list a - and b = Array.of_list b in - let add i tok = (`Add, a_offsets.(i), tok) - and del i tok = (`Del, a_offsets.(i), tok) in - let diff = - Diff.(levenshtein_script Array) ~equal:token_equal a b - |> List.fold_left - (fun acc -> function - | Diff.Insert {expected; actual} -> add expected b.(actual) :: acc - | Delete {expected} -> del expected a.(expected) :: acc - | Substitute {expected; actual} -> - del expected a.(expected) :: add expected b.(actual) :: acc ) - [] - in - diff - -(** On top of [unlex_token] with special cases. *) -let print_token = function - | Migrate_ast.Parser.EOL -> "" - | EOF -> "" - | tok -> unlex_token tok +let print_hunk fmt (tokens, start, end_) = + (* Add a token of context before and after. *) + let start = max 0 (start - 1) + and end_ = min (Array.length tokens - 1) (end_ + 1) in + for i = start to end_ do + let tok_s = + match tokens.(i) with + (* Special case to be able to print on one line *) + | Migrate_ast.Parser.EOL -> "" + | tok -> unlex_token tok + in + Format.fprintf fmt " %s" tok_s + done -let print_diff insert_offset insert_len diff = - let pp_diff = - let pp_log fmt (op, offset, tok) = - let op = match op with `Add -> '+' | `Del -> '-' in - Format.fprintf fmt "%d: %c %s" offset op (print_token tok) +let print_diff ~insert_offset a b script = + let f (a_start, a_end, delta) d = + let i, delta = + match d with + | Diff.Insert {expected; _} -> (expected, delta + 1) + | Delete {expected} -> (expected, delta - 1) + | Substitute {expected; _} -> (expected, delta) in - Format.pp_print_list pp_log + (min i a_start, max i a_end, delta) in - Format.printf "@[DIFF (inserted at %d-%d):@ %a@]@\n" insert_offset - (insert_offset + insert_len) - pp_diff diff + let start, a_end, delta = List.fold_left f (max_int, min_int, 0) script in + Format.printf "insertion offset = %d@\nbefore:%a@\n after:%a@\n" insert_offset + print_hunk (a, start, a_end) print_hunk + (b, start, a_end + delta) let run file = - let conf = Conf.conventional_profile + let conf = Conf.ocamlformat_profile and opts = Conf.{debug= false; margin_check= false; format_invalid_files= false} in @@ -230,9 +221,11 @@ let run file = ~input_name:file ~source conf opts with | Ok formatted -> ( - match diff_sources source formatted with - | [] -> () - | diff -> print_diff insert_offset (String.length insert) diff ) + let lex inp = Array.map fst (Array.of_list (lex_source inp)) in + let a = lex source and b = lex formatted in + match Diff.(levenshtein_script Array) ~equal:token_equal a b with + | [] -> () + | script -> print_diff ~insert_offset a b script ) | Error err -> Translation_unit.print_error ~debug:false ~quiet:true ~input_name:file err ) From 465b2abb971daf97f79cf035e63ab4ce5fc10803 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 6 Nov 2020 17:35:23 +0100 Subject: [PATCH 5/7] Small fixes --- test/comments/test_comments/test_comments.ml | 31 +++++++++----------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/test/comments/test_comments/test_comments.ml b/test/comments/test_comments/test_comments.ml index 91d6e38539..d5cab5230b 100644 --- a/test/comments/test_comments/test_comments.ml +++ b/test/comments/test_comments/test_comments.ml @@ -164,18 +164,8 @@ let unlex_token = function | WHILE -> "while" | WITH -> "with" -(** Ignore location diff *) -let token_equal a b = - let open Migrate_ast.Parser in - match (a, b) with - | STRING (a, _, a'), STRING (b, _, b') -> a = b && a' = b' - | ( QUOTED_STRING_EXPR (a, _, a', _, a'') - , QUOTED_STRING_EXPR (b, _, b', _, b'') ) - |( QUOTED_STRING_ITEM (a, _, a', _, a'') - , QUOTED_STRING_ITEM (b, _, b', _, b'') ) -> - a = b && a' = b' && a'' = b'' - | COMMENT (a, _), COMMENT (b, _) -> a = b - | a, b -> a = b +(** Can't use polymorphic equal because of location arguments in some tokens. *) +let token_equal a b = String.equal (unlex_token a) (unlex_token b) let print_hunk fmt (tokens, start, end_) = (* Add a token of context before and after. *) @@ -191,7 +181,7 @@ let print_hunk fmt (tokens, start, end_) = Format.fprintf fmt " %s" tok_s done -let print_diff ~insert_offset a b script = +let print_diff a b script = let f (a_start, a_end, delta) d = let i, delta = match d with @@ -202,17 +192,23 @@ let print_diff ~insert_offset a b script = (min i a_start, max i a_end, delta) in let start, a_end, delta = List.fold_left f (max_int, min_int, 0) script in - Format.printf "insertion offset = %d@\nbefore:%a@\n after:%a@\n" insert_offset - print_hunk (a, start, a_end) print_hunk + Format.printf "before:%a@\n after:%a@\n" print_hunk (a, start, a_end) + print_hunk (b, start, a_end + delta) let run file = - let conf = Conf.ocamlformat_profile + let conf = + { Conf.ocamlformat_profile with + break_cases= `Fit + ; margin= 77 + ; parse_docstrings= true + ; wrap_comments= true } and opts = Conf.{debug= false; margin_check= false; format_invalid_files= false} in let initial_source = Stdio.In_channel.read_all file in let toffs = List.map snd (lex_source initial_source) in + let pr_ins = Format.printf "insertion offset = %d@\n%!" in let insert = "(* toto *)" in insert_at_every_offsets insert toffs initial_source ~f:(fun insert_offset source -> @@ -225,8 +221,9 @@ let run file = let a = lex source and b = lex formatted in match Diff.(levenshtein_script Array) ~equal:token_equal a b with | [] -> () - | script -> print_diff ~insert_offset a b script ) + | script -> pr_ins insert_offset ; print_diff a b script ) | Error err -> + pr_ins insert_offset ; Translation_unit.print_error ~debug:false ~quiet:true ~input_name:file err ) From 9b446b1045a3c6c543ca4b5a89afe4dd3324ff03 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 6 Nov 2020 17:35:33 +0100 Subject: [PATCH 6/7] Run on a bigger sample --- test/comments/test_comments.t/run.t | 593 ++++++++++++++++++++++++-- test/comments/test_comments.t/test.ml | 71 ++- 2 files changed, 620 insertions(+), 44 deletions(-) diff --git a/test/comments/test_comments.t/run.t b/test/comments/test_comments.t/run.t index 60d4859a0f..2a8cc838b6 100644 --- a/test/comments/test_comments.t/run.t +++ b/test/comments/test_comments.t/run.t @@ -7,69 +7,584 @@ File "test.ml" should contain most syntaxes. insertion offset = 0 before: (* toto *) module M after: (* toto *) module M - insertion offset = 13 - before: (* toto *) - after: (* toto *) + insertion offset = 9 + before: M (* toto *) : sig (** M *) type t class c : " a t -> l : " a t -> ?k: " a t -> object [@@@ attr ] end end = struct + after: M : sig (** M *) type t class c : " a t -> l : " a t -> ?k: " a t -> object [@@@ attr ] end end = (* toto *) struct insertion offset = 14 - before: (* toto *) module M - after: (* toto *) module M - insertion offset = 23 - before: M (* toto *) : sig type t val f : t -> t end = struct - after: M : sig type t val f : t -> t end = (* toto *) struct - insertion offset = 28 before: sig (* toto *) after: sig (* toto *) - insertion offset = 31 + insertion offset = 26 + before: (** M *) (* toto *) type + after: (* toto *) (** M *) type + insertion offset = 29 before: (* toto *) type t after: (* toto *) type t - insertion offset = 36 + insertion offset = 34 before: type (* toto *) t after: (* toto *) type t - insertion offset = 38 + insertion offset = 36 before: (* toto *) after: (* toto *) - insertion offset = 41 - before: (* toto *) val f - after: (* toto *) val f - insertion offset = 56 + insertion offset = 39 + before: (* toto *) class c + after: (* toto *) class c + insertion offset = 48 + before: : (* toto *) + after: : (* toto *) + insertion offset = 54 + before: " (* toto *) a t + after: " a (* toto *) t + insertion offset = 62 + before: t (* toto *) -> l + after: t (* toto *) -> l + insertion offset = 65 + before: -> (* toto *) l : " a + after: -> l : (* toto *) " a + insertion offset = 66 + before: l (* toto *) : " a + after: l : (* toto *) " a + insertion offset = 68 + before: " (* toto *) a t + after: " a (* toto *) t + insertion offset = 76 + before: t (* toto *) -> ?k: + after: t (* toto *) -> ?k: + insertion offset = 79 + before: -> (* toto *) ?k: " a + after: -> ?k: (* toto *) " a + insertion offset = 83 + before: " (* toto *) a t + after: " a (* toto *) t + insertion offset = 91 + before: t (* toto *) -> object + after: t (* toto *) -> object + insertion offset = 94 + before: (* toto *) object + after: (* toto *) object + insertion offset = 100 + before: object (* toto *) + after: object (* toto *) + insertion offset = 127 + before: ] (* toto *) end + after: ] (* toto *) end + insertion offset = 130 + before: end (* toto *) + after: end (* toto *) + insertion offset = 131 before: (* toto *) end = after: (* toto *) end = - insertion offset = 68 + insertion offset = 143 before: struct (* toto *) after: struct (* toto *) - insertion offset = 71 + insertion offset = 146 before: (* toto *) type t after: (* toto *) type t - insertion offset = 76 + insertion offset = 151 before: type (* toto *) t = after: (* toto *) type t = - insertion offset = 78 - before: t (* toto *) = A | B of int * int | C of { a : int ; b : int } - after: t = A | B of int * int | C of { a : int ; b : int } (* toto *) - insertion offset = 82 - before: = A (* toto *) | B of int * int | C - after: = | A (* toto *) | B of int * int | C - insertion offset = 99 - before: = A | B of int * int (* toto *) | C - after: = | A | B of int * int (* toto *) | C - insertion offset = 106 + insertion offset = 153 + before: t (* toto *) = | A (** A *) | B : int * int -> t | C of { a : int (** a *) ; b : int (** b *) } + after: t = | A (** A *) | B : int * int -> t | C of { a : int (** a *) ; b : int (** b *) } (* toto *) + insertion offset = 154 + before: = (* toto *) + after: = (* toto *) + insertion offset = 159 + before: (* toto *) | A + after: (* toto *) | A + insertion offset = 172 + before: (** A *) (* toto *) + after: (** A *) (* toto *) + insertion offset = 177 + before: (* toto *) | B + after: (* toto *) | B + insertion offset = 202 + before: (* toto *) | C + after: (* toto *) | C + insertion offset = 209 before: of (* toto *) { a : after: of { (* toto *) a : - insertion offset = 123 + insertion offset = 226 + before: int (** a *) (* toto *) ; b + after: int (* toto *) (** a *) ; b + insertion offset = 245 + before: } (* toto *) + after: } (* toto *) + insertion offset = 246 + before: } (* toto *) (** f *) + after: } (** f *) (* toto *) + insertion offset = 257 + before: (** f *) (* toto *) let + after: (* toto *) (** f *) let + insertion offset = 260 + before: (** f *) (* toto *) let f + after: (* toto *) (** f *) let f + insertion offset = 279 + before: (* toto *) end + after: (* toto *) end + insertion offset = 282 + before: end (* toto *) + after: end (* toto *) + insertion offset = 283 before: (* toto *) after: (* toto *) - insertion offset = 126 - before: (* toto *) let f - after: (* toto *) let f - insertion offset = 137 + insertion offset = 284 + before: (* toto *) let _ + after: (* toto *) let _ + insertion offset = 291 + before: = (* toto *) + after: = (* toto *) + insertion offset = 341 + before: (* Insert every expressions in sequence here *) (* toto *) + after: (* Insert every expressions in sequence here *) (* toto *) + insertion offset = 344 + before: (* toto *) x ; + after: (* toto *) x ; + insertion offset = 347 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 351 + before: ( (* toto *) module M . + after: ( module (* toto *) M . + insertion offset = 359 + before: M (* toto *) . N ( X + after: M . N (* toto *) ( X + insertion offset = 360 + before: . (* toto *) N ( X + after: . N (* toto *) ( X + insertion offset = 364 + before: X (* toto *) . Y ) : + after: X . Y (* toto *) ) : + insertion offset = 365 + before: . (* toto *) Y ) : + after: . Y (* toto *) ) : + insertion offset = 374 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 377 + before: (* toto *) let rec + after: (* toto *) let rec + insertion offset = 381 + before: let (* toto *) rec x = + after: let rec (* toto *) x = + insertion offset = 393 + before: in (* toto *) + after: in (* toto *) + insertion offset = 396 + before: (* toto *) let _ + after: (* toto *) let _ + insertion offset = 411 + before: ( (* toto *) lazy _ ) + after: ( lazy (* toto *) _ ) + insertion offset = 425 + before: in (* toto *) + after: in (* toto *) + insertion offset = 428 + before: (* toto *) ( function + after: (* toto *) ( function + insertion offset = 429 + before: ( (* toto *) function (* Insert every patterns here *) + after: ( function (* toto *) (* Insert every patterns here *) + insertion offset = 437 + before: function (* toto *) + after: function (* toto *) + insertion offset = 472 + before: (* Insert every patterns here *) (* toto *) + after: (* Insert every patterns here *) (* toto *) + insertion offset = 475 + before: (* toto *) | ( + after: (* toto *) | ( + insertion offset = 477 + before: | (* toto *) ( ( + after: (* toto *) | ( ( + insertion offset = 479 + before: ( ( (* toto *) ( x + after: ( (* toto *) ( ( x + insertion offset = 492 + before: _ | (* toto *) a , b | A , B x | ` A , ` B x | # + after: _ (* toto *) | a , b | A , B x | ` A , ` B x | # + insertion offset = 499 + before: _ | a , b | (* toto *) A , B x | ` A , ` B x | # + after: _ | a , b (* toto *) | A , B x | ` A , ` B x | # + insertion offset = 508 + before: _ | a , b | A , B x | (* toto *) ` A , ` B x | # + after: _ | a , b | A , B x (* toto *) | ` A , ` B x | # + insertion offset = 509 + before: ` (* toto *) A , ` + after: ` A (* toto *) , ` + insertion offset = 513 + before: ` (* toto *) B x | + after: ` B (* toto *) x | + insertion offset = 519 + before: _ | a , b | A , B x | ` A , ` B x | (* toto *) # t + after: _ | a , b | A , B x | ` A , ` B x (* toto *) | # t + insertion offset = 520 + before: _ | a , b | A , B x | ` A , ` B x | # (* toto *) t + after: _ | a , b | A , B x | ` A , ` B x (* toto *) | # t + insertion offset = 523 + before: t ) (* toto *) as x + after: t (* toto *) ) as x + insertion offset = 532 + before: (* toto *) | { + after: (* toto *) | { + insertion offset = 533 + before: | (* toto *) { a + after: (* toto *) | { a + insertion offset = 546 + before: _ ; (* toto *) _ } + after: _ (* toto *) ; _ } + insertion offset = 552 + before: (* toto *) | [| + after: (* toto *) | [| + insertion offset = 553 + before: | (* toto *) [| a + after: (* toto *) | [| a + insertion offset = 565 + before: (* toto *) | A + after: (* toto *) | A + insertion offset = 566 + before: | (* toto *) A | + after: (* toto *) | A | + insertion offset = 570 + before: A | (* toto *) B + after: A (* toto *) | B + insertion offset = 575 + before: (* toto *) | ( + after: (* toto *) | ( + insertion offset = 576 + before: | (* toto *) ( module + after: (* toto *) | ( module + insertion offset = 577 + before: ( (* toto *) module M ) + after: ( module (* toto *) M ) + insertion offset = 590 + before: (* toto *) | ( + after: (* toto *) | ( + insertion offset = 591 + before: | (* toto *) ( module + after: (* toto *) | ( module + insertion offset = 592 + before: ( (* toto *) module M : + after: ( module (* toto *) M : + insertion offset = 605 + before: M : S ) (* toto *) + after: M (* toto *) : S ) + insertion offset = 609 + before: (* toto *) | ( + after: (* toto *) | ( + insertion offset = 610 + before: | (* toto *) ( module + after: (* toto *) | ( module + insertion offset = 611 + before: ( (* toto *) module _ ) + after: ( module (* toto *) _ ) + insertion offset = 624 + before: (* toto *) | ( + after: (* toto *) | ( + insertion offset = 625 + before: | (* toto *) ( exception + after: (* toto *) | ( exception + insertion offset = 626 + before: ( (* toto *) exception E ) + after: ( exception (* toto *) E ) + insertion offset = 642 + before: (* toto *) | [% + after: (* toto *) | [% + insertion offset = 643 + before: | (* toto *) [% ppx + after: (* toto *) | [% ppx + insertion offset = 653 + before: (* toto *) | M + after: (* toto *) | M + insertion offset = 654 + before: | (* toto *) M . + after: (* toto *) | M . + insertion offset = 656 + before: . (* toto *) ( A | + after: . ( (* toto *) A | + insertion offset = 661 + before: A | (* toto *) B ) + after: A (* toto *) | B ) + insertion offset = 666 + before: -> (* toto *) + after: -> (* toto *) + insertion offset = 677 + before: ) (* toto *) ; + after: ) (* toto *) ; + insertion offset = 678 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 681 + before: (* toto *) ( fun + after: (* toto *) ( fun + insertion offset = 682 + before: ( (* toto *) fun ( type t ) + after: ( fun ( type (* toto *) t ) + insertion offset = 686 + before: fun (* toto *) ( type t ) + after: fun ( type (* toto *) t ) + insertion offset = 687 + before: ( (* toto *) type t ) + after: ( type (* toto *) t ) + insertion offset = 697 + before: X (* toto *) ~ a ~b: + after: X ~ (* toto *) a ~b: + insertion offset = 700 + before: a (* toto *) ~b: Y ? + after: a ~b: (* toto *) Y ? + insertion offset = 705 + before: Y (* toto *) ? c ?c: + after: Y ? (* toto *) c ?c: + insertion offset = 708 + before: c (* toto *) ?c: ( Z = + after: c ?c: ( (* toto *) Z = + insertion offset = 711 + before: ?c: (* toto *) ( Z = + after: ?c: ( (* toto *) Z = + insertion offset = 723 + before: a ; (* toto *) _ } + after: a (* toto *) ; _ } + insertion offset = 740 + before: X ~ (* toto *) a ~b: + after: X (* toto *) ~ a ~b: + insertion offset = 746 + before: a ~b: ( (* toto *) x y ) ? c + after: a ~b: ( (* toto *) x y ) ? c + insertion offset = 748 + before: a ~b: ( x (* toto *) y ) ? c + after: a ~b: ( x (* toto *) y ) ? c + insertion offset = 749 + before: a ~b: ( x y (* toto *) ) ? c + after: a ~b: ( x y (* toto *) ) ? c + insertion offset = 752 + before: ) ? (* toto *) c ?c: + after: ) (* toto *) ? c ?c: + insertion offset = 792 + before: ( (* toto *) try a + after: (* toto *) ( try a + insertion offset = 848 + before: c ) (* toto *) |] ; + after: c (* toto *) ) |] ; + insertion offset = 851 + before: |] (* toto *) ; + after: |] (* toto *) ; + insertion offset = 852 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 875 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 878 + before: (* toto *) for i + after: (* toto *) for i + insertion offset = 899 + before: do (* toto *) + after: do (* toto *) + insertion offset = 912 + before: i (* toto *) done ; + after: i (* toto *) done ; + insertion offset = 917 + before: done (* toto *) ; + after: done (* toto *) ; + insertion offset = 918 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 930 + before: m ( (* toto *) new M + after: m (* toto *) ( new M + insertion offset = 934 + before: m ( new (* toto *) M + after: m (* toto *) ( new M + insertion offset = 935 + before: M (* toto *) . c ) {< x + after: M . c ) (* toto *) {< x + insertion offset = 936 + before: . (* toto *) c ) {< x + after: . c ) (* toto *) {< x + insertion offset = 937 + before: c (* toto *) ) {< x + after: c ) (* toto *) {< x + insertion offset = 952 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 955 + before: (* toto *) let module + after: (* toto *) let module + insertion offset = 959 + before: let (* toto *) module M = + after: let module (* toto *) M = + insertion offset = 971 + before: ( (* toto *) val S . + after: ( val (* toto *) S . + insertion offset = 977 + before: . (* toto *) ( M . + after: . ( (* toto *) M . + insertion offset = 979 + before: M (* toto *) . N X . + after: M . N (* toto *) X . + insertion offset = 980 + before: . (* toto *) N X . + after: . N (* toto *) X . + insertion offset = 983 + before: X (* toto *) . Y ) . + after: X . Y (* toto *) ) . + insertion offset = 984 + before: . (* toto *) Y ) . + after: . Y (* toto *) ) . + insertion offset = 992 + before: in (* toto *) + after: in (* toto *) + insertion offset = 995 + before: (* toto *) let exception + after: (* toto *) let exception + insertion offset = 999 + before: let (* toto *) exception E of + after: let exception (* toto *) E of + insertion offset = 1018 + before: in (* toto *) + after: in (* toto *) + insertion offset = 1021 + before: (* toto *) let open + after: (* toto *) let open + insertion offset = 1029 + before: open (* toto *) ! M in + after: open ! (* toto *) M in + insertion offset = 1035 + before: in (* toto *) + after: in (* toto *) + insertion offset = 1038 + before: (* toto *) let* x + after: (* toto *) let* x + insertion offset = 1043 + test_comments: Cannot process "test.ml". + Please report this bug at https://github.com/ocaml-ppx/ocamlformat/issues. + BUG: comments dropped. + insertion offset = 1049 + test_comments: Cannot process "test.ml". + Please report this bug at https://github.com/ocaml-ppx/ocamlformat/issues. + BUG: comments dropped. + insertion offset = 1062 + before: in (* toto *) + after: in (* toto *) + insertion offset = 1071 before: x (* toto *) after: x (* toto *) - insertion offset = 138 - before: (* toto *) end - after: (* toto *) end - insertion offset = 141 + insertion offset = 1072 + before: (* toto *) + after: (* toto *) + insertion offset = 1073 + before: (* toto *) class virtual + after: (* toto *) class virtual + insertion offset = 1079 + before: class (* toto *) virtual c x + after: class virtual (* toto *) c x + insertion offset = 1091 + before: x (* toto *) ~ y ?z: + after: x ~ (* toto *) y ?z: + insertion offset = 1094 + before: y (* toto *) ?z: ( z' = + after: y ?z: ( (* toto *) z' = + insertion offset = 1097 + before: ?z: (* toto *) ( z' = + after: ?z: ( (* toto *) z' = + insertion offset = 1106 + before: ) (* toto *) = let + after: ) = (* toto *) let + insertion offset = 1107 + before: = (* toto *) + after: = (* toto *) + insertion offset = 1110 + before: (* toto *) let open + after: (* toto *) let open + insertion offset = 1114 + before: let (* toto *) open M in + after: let open (* toto *) M in + insertion offset = 1123 + before: in (* toto *) + after: in (* toto *) + insertion offset = 1126 + before: (* toto *) object ( + after: (* toto *) object ( + insertion offset = 1133 + before: object (* toto *) ( self ) + after: object ( (* toto *) self ) + insertion offset = 1138 + before: self (* toto *) ) inherit + after: self ) (* toto *) inherit + insertion offset = 1139 + before: ) (* toto *) + after: ) (* toto *) + insertion offset = 1144 + before: (* toto *) inherit M + after: (* toto *) inherit M + insertion offset = 1153 + before: M (* toto *) . c x + after: M . c (* toto *) x + insertion offset = 1154 + before: . (* toto *) c x + after: . c (* toto *) x + insertion offset = 1157 + before: x (* toto *) val + after: x (* toto *) val + insertion offset = 1158 + before: (* toto *) + after: (* toto *) + insertion offset = 1163 + before: (* toto *) val mutable + after: (* toto *) val mutable + insertion offset = 1167 + before: val (* toto *) mutable y = + after: val mutable (* toto *) y = + insertion offset = 1180 + before: 0 (* toto *) initializer + after: 0 (* toto *) initializer + insertion offset = 1181 + before: (* toto *) + after: (* toto *) + insertion offset = 1186 + before: (* toto *) initializer y + after: (* toto *) initializer y + insertion offset = 1204 + before: x (* toto *) method + after: x (* toto *) method + insertion offset = 1205 + before: (* toto *) + after: (* toto *) + insertion offset = 1210 + before: (* toto *) method m + after: (* toto *) method m + insertion offset = 1228 + before: y (* toto *) method + after: y (* toto *) method + insertion offset = 1229 + before: (* toto *) + after: (* toto *) + insertion offset = 1234 + before: (* toto *) method n + after: (* toto *) method n + insertion offset = 1251 + before: m (* toto *) method + after: m (* toto *) method + insertion offset = 1252 + before: (* toto *) + after: (* toto *) + insertion offset = 1257 + before: (* toto *) method virtual + after: (* toto *) method virtual + insertion offset = 1264 + before: method (* toto *) virtual o : + after: method virtual (* toto *) o : + insertion offset = 1277 + before: : # (* toto *) ct -> + after: : (* toto *) # ct -> + insertion offset = 1286 + before: int (* toto *) + after: int (* toto *) + insertion offset = 1289 + before: (* toto *) end + after: (* toto *) end + insertion offset = 1292 before: end (* toto *) after: end (* toto *) - insertion offset = 142 + insertion offset = 1293 before: (* toto *) after: (* toto *) diff --git a/test/comments/test_comments.t/test.ml b/test/comments/test_comments.t/test.ml index dd85c5f9de..6b6b104369 100644 --- a/test/comments/test_comments.t/test.ml +++ b/test/comments/test_comments.t/test.ml @@ -1,11 +1,72 @@ -module M = M - module M : sig + (** M *) + type t - val f : t -> t + class c : + 'a t + -> l:'a t + -> ?k:'a t + -> object + [@@@attr] + end end = struct - type t = A | B of int * int | C of {a: int; b: int} + type t = + | A (** A *) + | B : int * int -> t + | C of {a: int (** a *); b: int (** b *)} - let f x = x + (** f *) + let f (_ : t) = () end + +let _ = + (* Insert every expressions in sequence here *) + x ; + (module M.N (X.Y) : S) ; + let rec x = x in + let _ = x and (lazy _) = y in + (function + (* Insert every patterns here *) + | (((x : t), _ | a, b | A, B x | `A, `B x | #t) as x) + |{a= _; b= _; _} + |[|a; b|] + |A | B + |(module M) + |(module M : S) + |(module _) + |(exception E) + |[%ppx] + |M.(A | B) -> + . ) ; + (fun (type t) X ~a ~b:Y ?c ?c:(Z = W) {a; _} -> ()) + X ~a ~b:(x y) ?c ?c:(Some x) + {a; b= (u :> t)} + (try a.x <- b.x with Failure msg -> msg) + [|a; (b ; c)|] ; + if x then y else z ; + for i = f x to f y do + do_ i + done ; + (f x)#m (new M.c) {} ; + let module M = (val S.(M.N X.Y).x) in + let exception E of t in + let open! M in + let* x = y and* z = w in + lazy x + +class virtual c x ~y ?z:(z' = 0) = + let open M in + object (self) + inherit M.c x + + val mutable y = 0 + + initializer y <- x + + method m a = a - y + + method n = self#m + + method virtual o : #ct -> int + end From ea3d7e75401ce19071197cbc352796a2a3a66063 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 6 Nov 2020 18:52:28 +0100 Subject: [PATCH 7/7] Increase coverage --- test/comments/test_comments.t/run.t | 789 ++++++++++++++++++-------- test/comments/test_comments.t/test.ml | 77 ++- 2 files changed, 614 insertions(+), 252 deletions(-) diff --git a/test/comments/test_comments.t/run.t b/test/comments/test_comments.t/run.t index 2a8cc838b6..55b79846b6 100644 --- a/test/comments/test_comments.t/run.t +++ b/test/comments/test_comments.t/run.t @@ -8,8 +8,8 @@ File "test.ml" should contain most syntaxes. before: (* toto *) module M after: (* toto *) module M insertion offset = 9 - before: M (* toto *) : sig (** M *) type t class c : " a t -> l : " a t -> ?k: " a t -> object [@@@ attr ] end end = struct - after: M : sig (** M *) type t class c : " a t -> l : " a t -> ?k: " a t -> object [@@@ attr ] end end = (* toto *) struct + before: M (* toto *) : sig (** M *) type " a t class c : " a t -> l : " a t -> ?k: " a t -> object [@@@ attr ] end module type S = sig include module type of struct end end module M : functor ( X : module type of N with type t = t ) ( ) -> S with type t = t and module N = N end = struct + after: M : sig (** M *) type " a t class c : " a t -> l : " a t -> ?k: " a t -> object [@@@ attr ] end module type S = sig include module type of struct end end module M : functor ( X : module type of N with type t = t ) ( ) -> S with type t = t and module N = N end = (* toto *) struct insertion offset = 14 before: sig (* toto *) after: sig (* toto *) @@ -17,574 +17,913 @@ File "test.ml" should contain most syntaxes. before: (** M *) (* toto *) type after: (* toto *) (** M *) type insertion offset = 29 - before: (* toto *) type t - after: (* toto *) type t - insertion offset = 34 - before: type (* toto *) t - after: (* toto *) type t - insertion offset = 36 + before: (* toto *) type " + after: (* toto *) type " + insertion offset = 35 + before: type " (* toto *) a + after: (* toto *) type " a + insertion offset = 37 + before: type " a (* toto *) t + after: (* toto *) type " a t + insertion offset = 39 before: (* toto *) after: (* toto *) - insertion offset = 39 + insertion offset = 42 before: (* toto *) class c after: (* toto *) class c - insertion offset = 48 + insertion offset = 51 before: : (* toto *) after: : (* toto *) - insertion offset = 54 + insertion offset = 57 before: " (* toto *) a t after: " a (* toto *) t - insertion offset = 62 + insertion offset = 65 before: t (* toto *) -> l after: t (* toto *) -> l - insertion offset = 65 + insertion offset = 68 before: -> (* toto *) l : " a after: -> l : (* toto *) " a - insertion offset = 66 + insertion offset = 69 before: l (* toto *) : " a after: l : (* toto *) " a - insertion offset = 68 + insertion offset = 71 before: " (* toto *) a t after: " a (* toto *) t - insertion offset = 76 + insertion offset = 79 before: t (* toto *) -> ?k: after: t (* toto *) -> ?k: - insertion offset = 79 + insertion offset = 82 before: -> (* toto *) ?k: " a after: -> ?k: (* toto *) " a - insertion offset = 83 + insertion offset = 86 before: " (* toto *) a t after: " a (* toto *) t - insertion offset = 91 + insertion offset = 94 before: t (* toto *) -> object after: t (* toto *) -> object - insertion offset = 94 + insertion offset = 97 before: (* toto *) object after: (* toto *) object - insertion offset = 100 + insertion offset = 103 before: object (* toto *) after: object (* toto *) - insertion offset = 127 + insertion offset = 130 before: ] (* toto *) end after: ] (* toto *) end - insertion offset = 130 + insertion offset = 133 + before: end (* toto *) + after: end (* toto *) + insertion offset = 134 + before: (* toto *) + after: (* toto *) + insertion offset = 137 + before: (* toto *) module type + after: (* toto *) module type + insertion offset = 144 + before: module (* toto *) type S = + after: module type (* toto *) S = + insertion offset = 156 + before: sig (* toto *) + after: sig (* toto *) + insertion offset = 161 + before: (* toto *) include module + after: (* toto *) include module + insertion offset = 176 + before: module (* toto *) type of struct end + after: module type of (* toto *) struct end + insertion offset = 181 + before: type (* toto *) of struct end + after: type of (* toto *) struct end + insertion offset = 191 + before: struct (* toto *) end + after: struct (* toto *) end + insertion offset = 197 + before: (* toto *) end + after: (* toto *) end + insertion offset = 200 before: end (* toto *) after: end (* toto *) - insertion offset = 131 + insertion offset = 201 + before: (* toto *) + after: (* toto *) + insertion offset = 204 + before: (* toto *) module M + after: (* toto *) module M + insertion offset = 215 + before: : (* toto *) functor ( X : module type of N with type t = t ) ( ) -> S with type + after: : functor ( X : module type of N with type t = t ) ( ) -> S (* toto *) with type + insertion offset = 223 + before: functor (* toto *) ( X : + after: functor ( (* toto *) X : + insertion offset = 228 + before: : (* toto *) module type of N with type + after: : module type of N (* toto *) with type + insertion offset = 235 + before: module (* toto *) type of N with + after: module type of (* toto *) N with + insertion offset = 240 + before: type (* toto *) of N with + after: type of (* toto *) N with + insertion offset = 262 + before: ) (* toto *) ( ) -> S with type + after: ) ( ) -> S (* toto *) with type + insertion offset = 263 + before: ( (* toto *) ) -> S with type + after: ( ) -> S (* toto *) with type + insertion offset = 265 + before: ) (* toto *) -> S with type + after: ) -> S (* toto *) with type + insertion offset = 267 + before: -> (* toto *) S with type + after: -> S (* toto *) with type + insertion offset = 272 + before: (* toto *) S with type + after: S (* toto *) with type + insertion offset = 294 + before: and (* toto *) module N = + after: and module (* toto *) N = + insertion offset = 306 + before: N (* toto *) + after: N (* toto *) + insertion offset = 307 before: (* toto *) end = after: (* toto *) end = - insertion offset = 143 + insertion offset = 319 before: struct (* toto *) after: struct (* toto *) - insertion offset = 146 + insertion offset = 322 before: (* toto *) type t after: (* toto *) type t - insertion offset = 151 + insertion offset = 327 before: type (* toto *) t = after: (* toto *) type t = - insertion offset = 153 - before: t (* toto *) = | A (** A *) | B : int * int -> t | C of { a : int (** a *) ; b : int (** b *) } - after: t = | A (** A *) | B : int * int -> t | C of { a : int (** a *) ; b : int (** b *) } (* toto *) - insertion offset = 154 + insertion offset = 329 + before: t (* toto *) = | A (** A *) | B : int * int -> t | C of { a : int (** a *) ; b : int (** b *) } constraint " a = [> ` A | b ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: t = | A (** A *) | B : int * int -> t | C of { a : int (** a *) ; b : int (** b *) } constraint " a = [> ` A | b ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a (* toto *) + insertion offset = 330 before: = (* toto *) after: = (* toto *) - insertion offset = 159 + insertion offset = 335 before: (* toto *) | A after: (* toto *) | A - insertion offset = 172 + insertion offset = 348 before: (** A *) (* toto *) after: (** A *) (* toto *) - insertion offset = 177 + insertion offset = 353 before: (* toto *) | B after: (* toto *) | B - insertion offset = 202 + insertion offset = 378 before: (* toto *) | C after: (* toto *) | C - insertion offset = 209 + insertion offset = 385 before: of (* toto *) { a : after: of { (* toto *) a : - insertion offset = 226 + insertion offset = 402 before: int (** a *) (* toto *) ; b after: int (* toto *) (** a *) ; b - insertion offset = 245 - before: } (* toto *) - after: } (* toto *) - insertion offset = 246 - before: } (* toto *) (** f *) - after: } (** f *) (* toto *) - insertion offset = 257 + insertion offset = 426 + before: } (* toto *) constraint + after: } (* toto *) constraint + insertion offset = 436 + before: } constraint (* toto *) + after: } (* toto *) constraint + insertion offset = 443 + before: } constraint (* toto *) " + after: } (* toto *) constraint " + insertion offset = 444 + before: " (* toto *) a = + after: " a (* toto *) = + insertion offset = 446 + before: a (* toto *) = + after: a (* toto *) = + insertion offset = 447 + before: = (* toto *) + after: = (* toto *) + insertion offset = 454 + before: (* toto *) [> ` + after: (* toto *) [> ` + insertion offset = 457 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 458 + before: ` (* toto *) A | b ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ` A (* toto *) | b ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 460 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 462 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 463 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 465 + before: ] (* toto *) * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] (* toto *) * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 467 + before: ] * (* toto *) [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * (* toto *) [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 470 + before: ] * [< (* toto *) ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< (* toto *) ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 471 + before: ] * [< ` (* toto *) A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 473 + before: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 475 + before: ] * [< ` A > (* toto *) ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 476 + before: ] * [< ` A > ` (* toto *) B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 478 + before: ] * [< ` A > ` B (* toto *) ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 479 + before: ] * [< ` A > ` B ` (* toto *) C ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 480 + before: ] * [< ` A > ` B ` C (* toto *) ] * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A (* toto *) > ` B ` C ] * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 482 + before: ] * [< ` A > ` B ` C ] (* toto *) * < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] (* toto *) * < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 484 + before: ] * [< ` A > ` B ` C ] * (* toto *) < m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * (* toto *) < m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 486 + before: ] * [< ` A > ` B ` C ] * < (* toto *) m : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < (* toto *) m : t ; .. > * ( module S ) * t # u as " a + insertion offset = 487 + before: ] * [< ` A > ` B ` C ] * < m (* toto *) : t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m (* toto *) : t ; .. > * ( module S ) * t # u as " a + insertion offset = 489 + before: ] * [< ` A > ` B ` C ] * < m : (* toto *) t ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : (* toto *) t ; .. > * ( module S ) * t # u as " a + insertion offset = 491 + before: ] * [< ` A > ` B ` C ] * < m : t (* toto *) ; .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t (* toto *) ; .. > * ( module S ) * t # u as " a + insertion offset = 493 + before: ] * [< ` A > ` B ` C ] * < m : t ; (* toto *) .. > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t (* toto *) ; .. > * ( module S ) * t # u as " a + insertion offset = 496 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. (* toto *) > * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t (* toto *) ; .. > * ( module S ) * t # u as " a + insertion offset = 498 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > (* toto *) * ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > (* toto *) * ( module S ) * t # u as " a + insertion offset = 500 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * (* toto *) ( module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * (* toto *) ( module S ) * t # u as " a + insertion offset = 501 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( (* toto *) module S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * (* toto *) ( module S ) * t # u as " a + insertion offset = 508 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module (* toto *) S ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * (* toto *) ( module S ) * t # u as " a + insertion offset = 509 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S (* toto *) ) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) (* toto *) * t # u as " a + insertion offset = 511 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) (* toto *) * t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) (* toto *) * t # u as " a + insertion offset = 513 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * (* toto *) t # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * (* toto *) t # u as " a + insertion offset = 515 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t (* toto *) # u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t (* toto *) # u as " a + insertion offset = 516 + before: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t # (* toto *) u as " a + after: ] * [< ` A > ` B ` C ] * < m : t ; .. > * ( module S ) * t (* toto *) # u as " a + insertion offset = 518 + before: u (* toto *) as " a + after: u (* toto *) as " a + insertion offset = 521 + before: u as (* toto *) " a + after: u (* toto *) as " a + insertion offset = 522 + before: u as " (* toto *) a + after: u (* toto *) as " a + insertion offset = 523 + before: a (* toto *) + after: a (* toto *) + insertion offset = 524 + insertion offset = 535 before: (** f *) (* toto *) let after: (* toto *) (** f *) let - insertion offset = 260 + insertion offset = 538 before: (** f *) (* toto *) let f after: (* toto *) (** f *) let f - insertion offset = 279 + insertion offset = 547 + test_comments: Cannot process "test.ml". + Please report this bug at https://github.com/ocaml-ppx/ocamlformat/issues. + BUG: comments dropped. + insertion offset = 548 + test_comments: Cannot process "test.ml". + Please report this bug at https://github.com/ocaml-ppx/ocamlformat/issues. + BUG: comments dropped. + insertion offset = 558 + before: f : " a . [% id ] t (* toto *) = + after: f (* toto *) : " a . [% id ] t = + insertion offset = 563 + before: ( (* toto *) fun X -> + after: ( fun (* toto *) X -> + insertion offset = 586 + before: (* toto *) + after: (* toto *) + insertion offset = 589 + before: (* toto *) module M + after: (* toto *) module M + insertion offset = 607 + before: ( (* toto *) ) = struct end + after: ( ) = (* toto *) struct end + insertion offset = 609 + before: ) (* toto *) = struct end + after: ) = (* toto *) struct end + insertion offset = 618 + before: struct (* toto *) end + after: struct (* toto *) end + insertion offset = 622 before: (* toto *) end after: (* toto *) end - insertion offset = 282 + insertion offset = 625 before: end (* toto *) after: end (* toto *) - insertion offset = 283 + insertion offset = 626 before: (* toto *) after: (* toto *) - insertion offset = 284 + insertion offset = 627 before: (* toto *) let _ after: (* toto *) let _ - insertion offset = 291 + insertion offset = 634 before: = (* toto *) after: = (* toto *) - insertion offset = 341 + insertion offset = 684 before: (* Insert every expressions in sequence here *) (* toto *) after: (* Insert every expressions in sequence here *) (* toto *) - insertion offset = 344 - before: (* toto *) x ; - after: (* toto *) x ; - insertion offset = 347 - before: ; (* toto *) - after: ; (* toto *) - insertion offset = 351 + insertion offset = 687 + before: (* toto *) ( module + after: (* toto *) ( module + insertion offset = 688 before: ( (* toto *) module M . after: ( module (* toto *) M . - insertion offset = 359 + insertion offset = 696 before: M (* toto *) . N ( X after: M . N (* toto *) ( X - insertion offset = 360 + insertion offset = 697 before: . (* toto *) N ( X after: . N (* toto *) ( X - insertion offset = 364 + insertion offset = 701 before: X (* toto *) . Y ) : after: X . Y (* toto *) ) : - insertion offset = 365 + insertion offset = 702 before: . (* toto *) Y ) : after: . Y (* toto *) ) : - insertion offset = 374 + insertion offset = 711 before: ; (* toto *) after: ; (* toto *) - insertion offset = 377 + insertion offset = 714 before: (* toto *) let rec after: (* toto *) let rec - insertion offset = 381 + insertion offset = 718 before: let (* toto *) rec x = after: let rec (* toto *) x = - insertion offset = 393 - before: in (* toto *) - after: in (* toto *) - insertion offset = 396 - before: (* toto *) let _ - after: (* toto *) let _ - insertion offset = 411 + insertion offset = 733 before: ( (* toto *) lazy _ ) after: ( lazy (* toto *) _ ) - insertion offset = 425 + insertion offset = 747 before: in (* toto *) after: in (* toto *) - insertion offset = 428 - before: (* toto *) ( function - after: (* toto *) ( function - insertion offset = 429 + insertion offset = 750 + before: (* toto *) f + after: (* toto *) f + insertion offset = 757 before: ( (* toto *) function (* Insert every patterns here *) after: ( function (* toto *) (* Insert every patterns here *) - insertion offset = 437 + insertion offset = 765 before: function (* toto *) after: function (* toto *) - insertion offset = 472 + insertion offset = 804 before: (* Insert every patterns here *) (* toto *) after: (* Insert every patterns here *) (* toto *) - insertion offset = 475 + insertion offset = 811 before: (* toto *) | ( after: (* toto *) | ( - insertion offset = 477 + insertion offset = 813 before: | (* toto *) ( ( after: (* toto *) | ( ( - insertion offset = 479 + insertion offset = 815 before: ( ( (* toto *) ( x after: ( (* toto *) ( ( x - insertion offset = 492 + insertion offset = 828 before: _ | (* toto *) a , b | A , B x | ` A , ` B x | # after: _ (* toto *) | a , b | A , B x | ` A , ` B x | # - insertion offset = 499 + insertion offset = 835 before: _ | a , b | (* toto *) A , B x | ` A , ` B x | # after: _ | a , b (* toto *) | A , B x | ` A , ` B x | # - insertion offset = 508 + insertion offset = 844 before: _ | a , b | A , B x | (* toto *) ` A , ` B x | # after: _ | a , b | A , B x (* toto *) | ` A , ` B x | # - insertion offset = 509 + insertion offset = 845 before: ` (* toto *) A , ` after: ` A (* toto *) , ` - insertion offset = 513 + insertion offset = 849 before: ` (* toto *) B x | after: ` B (* toto *) x | - insertion offset = 519 + insertion offset = 855 before: _ | a , b | A , B x | ` A , ` B x | (* toto *) # t after: _ | a , b | A , B x | ` A , ` B x (* toto *) | # t - insertion offset = 520 + insertion offset = 856 before: _ | a , b | A , B x | ` A , ` B x | # (* toto *) t after: _ | a , b | A , B x | ` A , ` B x (* toto *) | # t - insertion offset = 523 + insertion offset = 859 before: t ) (* toto *) as x after: t (* toto *) ) as x - insertion offset = 532 + insertion offset = 872 before: (* toto *) | { after: (* toto *) | { - insertion offset = 533 + insertion offset = 873 before: | (* toto *) { a after: (* toto *) | { a - insertion offset = 546 + insertion offset = 886 before: _ ; (* toto *) _ } after: _ (* toto *) ; _ } - insertion offset = 552 + insertion offset = 896 before: (* toto *) | [| after: (* toto *) | [| - insertion offset = 553 + insertion offset = 897 before: | (* toto *) [| a after: (* toto *) | [| a - insertion offset = 565 + insertion offset = 913 before: (* toto *) | A after: (* toto *) | A - insertion offset = 566 + insertion offset = 914 before: | (* toto *) A | after: (* toto *) | A | - insertion offset = 570 + insertion offset = 918 before: A | (* toto *) B after: A (* toto *) | B - insertion offset = 575 + insertion offset = 927 before: (* toto *) | ( after: (* toto *) | ( - insertion offset = 576 + insertion offset = 928 before: | (* toto *) ( module after: (* toto *) | ( module - insertion offset = 577 + insertion offset = 929 before: ( (* toto *) module M ) after: ( module (* toto *) M ) - insertion offset = 590 + insertion offset = 946 before: (* toto *) | ( after: (* toto *) | ( - insertion offset = 591 + insertion offset = 947 before: | (* toto *) ( module after: (* toto *) | ( module - insertion offset = 592 + insertion offset = 948 before: ( (* toto *) module M : after: ( module (* toto *) M : - insertion offset = 605 + insertion offset = 961 before: M : S ) (* toto *) after: M (* toto *) : S ) - insertion offset = 609 + insertion offset = 969 before: (* toto *) | ( after: (* toto *) | ( - insertion offset = 610 + insertion offset = 970 before: | (* toto *) ( module after: (* toto *) | ( module - insertion offset = 611 + insertion offset = 971 before: ( (* toto *) module _ ) after: ( module (* toto *) _ ) - insertion offset = 624 + insertion offset = 988 before: (* toto *) | ( after: (* toto *) | ( - insertion offset = 625 + insertion offset = 989 before: | (* toto *) ( exception after: (* toto *) | ( exception - insertion offset = 626 + insertion offset = 990 before: ( (* toto *) exception E ) after: ( exception (* toto *) E ) - insertion offset = 642 + insertion offset = 1010 before: (* toto *) | [% after: (* toto *) | [% - insertion offset = 643 + insertion offset = 1011 before: | (* toto *) [% ppx after: (* toto *) | [% ppx - insertion offset = 653 + insertion offset = 1025 before: (* toto *) | M after: (* toto *) | M - insertion offset = 654 + insertion offset = 1026 before: | (* toto *) M . after: (* toto *) | M . - insertion offset = 656 + insertion offset = 1028 before: . (* toto *) ( A | after: . ( (* toto *) A | - insertion offset = 661 + insertion offset = 1033 before: A | (* toto *) B ) after: A (* toto *) | B ) - insertion offset = 666 + insertion offset = 1043 + before: (* toto *) | { + after: (* toto *) | { + insertion offset = 1044 + before: | (* toto *) { x + after: (* toto *) | { x + insertion offset = 1048 + before: = (* toto *) ( module M : + after: = ( module (* toto *) M : + insertion offset = 1049 + before: ( (* toto *) module M : + after: ( module (* toto *) M : + insertion offset = 1062 + before: M : S ) (* toto *) } + after: M (* toto *) : S ) } + insertion offset = 1071 + before: (* toto *) | { + after: (* toto *) | { + insertion offset = 1072 + before: | (* toto *) { x + after: (* toto *) | { x + insertion offset = 1076 + before: { x = (* toto *) ( + after: { (* toto *) x = ( + insertion offset = 1093 + before: (* toto *) | { + after: (* toto *) | { + insertion offset = 1094 + before: | (* toto *) { x + after: (* toto *) | { x + insertion offset = 1098 + before: { x = (* toto *) ( + after: { (* toto *) x = ( + insertion offset = 1114 + before: (* toto *) | { + after: (* toto *) | { + insertion offset = 1115 + before: | (* toto *) { x + after: (* toto *) | { x + insertion offset = 1120 + before: ( (* toto *) ( x' : + after: ( ( (* toto *) x' : + insertion offset = 1140 before: -> (* toto *) after: -> (* toto *) - insertion offset = 677 - before: ) (* toto *) ; - after: ) (* toto *) ; - insertion offset = 678 - before: ; (* toto *) - after: ; (* toto *) - insertion offset = 681 - before: (* toto *) ( fun - after: (* toto *) ( fun - insertion offset = 682 + insertion offset = 1160 before: ( (* toto *) fun ( type t ) after: ( fun ( type (* toto *) t ) - insertion offset = 686 + insertion offset = 1164 before: fun (* toto *) ( type t ) after: fun ( type (* toto *) t ) - insertion offset = 687 + insertion offset = 1165 before: ( (* toto *) type t ) after: ( type (* toto *) t ) - insertion offset = 697 + insertion offset = 1175 before: X (* toto *) ~ a ~b: after: X ~ (* toto *) a ~b: - insertion offset = 700 + insertion offset = 1178 before: a (* toto *) ~b: Y ? after: a ~b: (* toto *) Y ? - insertion offset = 705 + insertion offset = 1183 before: Y (* toto *) ? c ?c: after: Y ? (* toto *) c ?c: - insertion offset = 708 + insertion offset = 1186 before: c (* toto *) ?c: ( Z = after: c ?c: ( (* toto *) Z = - insertion offset = 711 + insertion offset = 1189 before: ?c: (* toto *) ( Z = after: ?c: ( (* toto *) Z = - insertion offset = 723 + insertion offset = 1201 before: a ; (* toto *) _ } after: a (* toto *) ; _ } - insertion offset = 740 + insertion offset = 1218 before: X ~ (* toto *) a ~b: after: X (* toto *) ~ a ~b: - insertion offset = 746 + insertion offset = 1224 before: a ~b: ( (* toto *) x y ) ? c after: a ~b: ( (* toto *) x y ) ? c - insertion offset = 748 + insertion offset = 1226 before: a ~b: ( x (* toto *) y ) ? c after: a ~b: ( x (* toto *) y ) ? c - insertion offset = 749 + insertion offset = 1227 before: a ~b: ( x y (* toto *) ) ? c after: a ~b: ( x y (* toto *) ) ? c - insertion offset = 752 + insertion offset = 1230 before: ) ? (* toto *) c ?c: after: ) (* toto *) ? c ?c: - insertion offset = 792 + insertion offset = 1275 + before: ( (* toto *) module M : + after: ( module (* toto *) M : + insertion offset = 1295 before: ( (* toto *) try a after: (* toto *) ( try a - insertion offset = 848 - before: c ) (* toto *) |] ; - after: c (* toto *) ) |] ; - insertion offset = 851 + insertion offset = 1356 before: |] (* toto *) ; after: |] (* toto *) ; - insertion offset = 852 + insertion offset = 1357 before: ; (* toto *) after: ; (* toto *) - insertion offset = 875 + insertion offset = 1365 + before: . (* toto *) { a , + after: . { (* toto *) a , + insertion offset = 1380 + before: .* (* toto *) ( 0 ) + after: .* ( (* toto *) 0 ) + insertion offset = 1384 + before: ( 0 ) (* toto *) else + after: ( (* toto *) 0 ) else + insertion offset = 1392 + before: .* (* toto *) ( a ; + after: .* ( (* toto *) a ; + insertion offset = 1399 + before: ( a ; b ) (* toto *) ; + after: ( (* toto *) a ; b ) ; + insertion offset = 1400 before: ; (* toto *) after: ; (* toto *) - insertion offset = 878 + insertion offset = 1403 before: (* toto *) for i after: (* toto *) for i - insertion offset = 899 + insertion offset = 1424 before: do (* toto *) after: do (* toto *) - insertion offset = 912 - before: i (* toto *) done ; - after: i (* toto *) done ; - insertion offset = 917 + insertion offset = 1436 + before: . (* toto *) ( i ) + after: . ( (* toto *) i ) + insertion offset = 1442 + before: ) (* toto *) done ; + after: ) (* toto *) done ; + insertion offset = 1447 before: done (* toto *) ; after: done (* toto *) ; - insertion offset = 918 + insertion offset = 1448 before: ; (* toto *) after: ; (* toto *) - insertion offset = 930 + insertion offset = 1460 before: m ( (* toto *) new M after: m (* toto *) ( new M - insertion offset = 934 + insertion offset = 1464 before: m ( new (* toto *) M after: m (* toto *) ( new M - insertion offset = 935 + insertion offset = 1465 before: M (* toto *) . c ) {< x after: M . c ) (* toto *) {< x - insertion offset = 936 + insertion offset = 1466 before: . (* toto *) c ) {< x after: . c ) (* toto *) {< x - insertion offset = 937 + insertion offset = 1467 before: c (* toto *) ) {< x after: c ) (* toto *) {< x - insertion offset = 952 + insertion offset = 1504 before: ; (* toto *) after: ; (* toto *) - insertion offset = 955 + insertion offset = 1507 before: (* toto *) let module after: (* toto *) let module - insertion offset = 959 + insertion offset = 1511 before: let (* toto *) module M = after: let module (* toto *) M = - insertion offset = 971 + insertion offset = 1523 before: ( (* toto *) val S . after: ( val (* toto *) S . - insertion offset = 977 + insertion offset = 1529 before: . (* toto *) ( M . after: . ( (* toto *) M . - insertion offset = 979 + insertion offset = 1531 before: M (* toto *) . N X . after: M . N (* toto *) X . - insertion offset = 980 + insertion offset = 1532 before: . (* toto *) N X . after: . N (* toto *) X . - insertion offset = 983 + insertion offset = 1535 before: X (* toto *) . Y ) . after: X . Y (* toto *) ) . - insertion offset = 984 + insertion offset = 1536 before: . (* toto *) Y ) . after: . Y (* toto *) ) . - insertion offset = 992 + insertion offset = 1544 before: in (* toto *) after: in (* toto *) - insertion offset = 995 + insertion offset = 1547 before: (* toto *) let exception after: (* toto *) let exception - insertion offset = 999 + insertion offset = 1551 before: let (* toto *) exception E of after: let exception (* toto *) E of - insertion offset = 1018 + insertion offset = 1570 before: in (* toto *) after: in (* toto *) - insertion offset = 1021 + insertion offset = 1573 before: (* toto *) let open after: (* toto *) let open - insertion offset = 1029 + insertion offset = 1581 before: open (* toto *) ! M in after: open ! (* toto *) M in - insertion offset = 1035 + insertion offset = 1587 before: in (* toto *) after: in (* toto *) - insertion offset = 1038 + insertion offset = 1590 before: (* toto *) let* x after: (* toto *) let* x - insertion offset = 1043 + insertion offset = 1595 test_comments: Cannot process "test.ml". Please report this bug at https://github.com/ocaml-ppx/ocamlformat/issues. BUG: comments dropped. - insertion offset = 1049 + insertion offset = 1603 test_comments: Cannot process "test.ml". Please report this bug at https://github.com/ocaml-ppx/ocamlformat/issues. BUG: comments dropped. - insertion offset = 1062 + insertion offset = 1613 + before: = ( (* toto *) w [@ + after: = (* toto *) ( w [@ + insertion offset = 1626 before: in (* toto *) after: in (* toto *) - insertion offset = 1071 - before: x (* toto *) - after: x (* toto *) - insertion offset = 1072 + insertion offset = 1629 + before: (* toto *) lazy ( + after: (* toto *) lazy ( + insertion offset = 1637 + before: ( (* toto *) let* ) ( + after: ( let* (* toto *) ) ( + insertion offset = 1645 + before: ( (* toto *) function X -> + after: ( function (* toto *) X -> + insertion offset = 1659 + before: -> (* toto *) ( + ) ) + after: -> ( + (* toto *) ) ) + insertion offset = 1661 + before: ( (* toto *) + ) ) + after: ( + (* toto *) ) ) + insertion offset = 1664 + before: + ) (* toto *) ) ( + after: + (* toto *) ) ) ( + insertion offset = 1667 + before: ) ( (* toto *) ( * + after: ) (* toto *) ( ( * + insertion offset = 1669 + before: ( (* toto *) * ) [@ attr ] ) ) ; + after: ( * ) [@ attr ] ) (* toto *) ) ; + insertion offset = 1671 + before: * (* toto *) ) [@ attr ] ) ) ; + after: * ) [@ attr ] ) (* toto *) ) ; + insertion offset = 1684 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 1689 + before: 1 (* toto *) :: ~- + after: (* toto *) 1 :: ~- + insertion offset = 1697 + before: ; (* toto *) + after: ; (* toto *) + insertion offset = 1706 + before: ] (* toto *) + after: ] (* toto *) + insertion offset = 1707 before: (* toto *) after: (* toto *) - insertion offset = 1073 + insertion offset = 1708 before: (* toto *) class virtual after: (* toto *) class virtual - insertion offset = 1079 + insertion offset = 1714 before: class (* toto *) virtual c x after: class virtual (* toto *) c x - insertion offset = 1091 + insertion offset = 1726 before: x (* toto *) ~ y ?z: after: x ~ (* toto *) y ?z: - insertion offset = 1094 + insertion offset = 1729 before: y (* toto *) ?z: ( z' = after: y ?z: ( (* toto *) z' = - insertion offset = 1097 + insertion offset = 1732 before: ?z: (* toto *) ( z' = after: ?z: ( (* toto *) z' = - insertion offset = 1106 + insertion offset = 1741 before: ) (* toto *) = let after: ) = (* toto *) let - insertion offset = 1107 + insertion offset = 1742 before: = (* toto *) after: = (* toto *) - insertion offset = 1110 + insertion offset = 1745 before: (* toto *) let open after: (* toto *) let open - insertion offset = 1114 + insertion offset = 1749 before: let (* toto *) open M in after: let open (* toto *) M in - insertion offset = 1123 + insertion offset = 1758 before: in (* toto *) after: in (* toto *) - insertion offset = 1126 + insertion offset = 1761 before: (* toto *) object ( after: (* toto *) object ( - insertion offset = 1133 + insertion offset = 1768 before: object (* toto *) ( self ) after: object ( (* toto *) self ) - insertion offset = 1138 + insertion offset = 1773 before: self (* toto *) ) inherit after: self ) (* toto *) inherit - insertion offset = 1139 + insertion offset = 1774 before: ) (* toto *) after: ) (* toto *) - insertion offset = 1144 + insertion offset = 1779 before: (* toto *) inherit M after: (* toto *) inherit M - insertion offset = 1153 + insertion offset = 1788 before: M (* toto *) . c x after: M . c (* toto *) x - insertion offset = 1154 + insertion offset = 1789 before: . (* toto *) c x after: . c (* toto *) x - insertion offset = 1157 + insertion offset = 1792 before: x (* toto *) val after: x (* toto *) val - insertion offset = 1158 + insertion offset = 1793 before: (* toto *) after: (* toto *) - insertion offset = 1163 + insertion offset = 1798 before: (* toto *) val mutable after: (* toto *) val mutable - insertion offset = 1167 + insertion offset = 1802 before: val (* toto *) mutable y = after: val mutable (* toto *) y = - insertion offset = 1180 + insertion offset = 1815 before: 0 (* toto *) initializer after: 0 (* toto *) initializer - insertion offset = 1181 + insertion offset = 1816 before: (* toto *) after: (* toto *) - insertion offset = 1186 + insertion offset = 1821 before: (* toto *) initializer y after: (* toto *) initializer y - insertion offset = 1204 + insertion offset = 1839 before: x (* toto *) method after: x (* toto *) method - insertion offset = 1205 + insertion offset = 1840 before: (* toto *) after: (* toto *) - insertion offset = 1210 + insertion offset = 1845 before: (* toto *) method m after: (* toto *) method m - insertion offset = 1228 + insertion offset = 1863 before: y (* toto *) method after: y (* toto *) method - insertion offset = 1229 + insertion offset = 1864 before: (* toto *) after: (* toto *) - insertion offset = 1234 + insertion offset = 1869 before: (* toto *) method n after: (* toto *) method n - insertion offset = 1251 - before: m (* toto *) method - after: m (* toto *) method - insertion offset = 1252 + insertion offset = 1891 + before: >} (* toto *) method + after: >} (* toto *) method + insertion offset = 1892 before: (* toto *) after: (* toto *) - insertion offset = 1257 + insertion offset = 1897 before: (* toto *) method virtual after: (* toto *) method virtual - insertion offset = 1264 + insertion offset = 1904 before: method (* toto *) virtual o : after: method virtual (* toto *) o : - insertion offset = 1277 + insertion offset = 1917 before: : # (* toto *) ct -> after: : (* toto *) # ct -> - insertion offset = 1286 + insertion offset = 1926 before: int (* toto *) after: int (* toto *) - insertion offset = 1289 + insertion offset = 1929 before: (* toto *) end after: (* toto *) end - insertion offset = 1292 + insertion offset = 1932 before: end (* toto *) after: end (* toto *) - insertion offset = 1293 + insertion offset = 1933 + before: (* toto *) + after: (* toto *) + insertion offset = 1934 + before: (* toto *) type t + after: (* toto *) type t + insertion offset = 1939 + before: type (* toto *) t = + after: (* toto *) type t = + insertion offset = 1941 + before: t (* toto *) = .. + after: t = .. (* toto *) + insertion offset = 1943 + before: = (* toto *) .. + after: = .. (* toto *) + insertion offset = 1946 + before: (* toto *) + after: (* toto *) + insertion offset = 1947 + before: (* toto *) type t + after: (* toto *) type t + insertion offset = 1968 + before: (* toto *) + after: (* toto *) + insertion offset = 1969 + before: (* toto *) exception E + after: (* toto *) exception E + insertion offset = 1985 + before: t (* toto *) + after: t (* toto *) + insertion offset = 1986 before: (* toto *) after: (* toto *) diff --git a/test/comments/test_comments.t/test.ml b/test/comments/test_comments.t/test.ml index 6b6b104369..03efecb51b 100644 --- a/test/comments/test_comments.t/test.ml +++ b/test/comments/test_comments.t/test.ml @@ -1,7 +1,7 @@ module M : sig (** M *) - type t + type 'a t class c : 'a t @@ -10,50 +10,67 @@ module M : sig -> object [@@@attr] end + + module type S = sig + include module type of struct end + end + + module M : functor (X : module type of N with type t = t) () -> + S with type t = t and module N = N end = struct type t = | A (** A *) | B : int * int -> t | C of {a: int (** a *); b: int (** b *)} + constraint + 'a = + [> `A | b] * [< `A > `B `C] * < m: t ; .. > * (module S) * t #u as 'a (** f *) - let f (_ : t) = () + let f : 'a. [%id] t = f (fun X -> assert false) + + module M (X : S) () = struct end end let _ = (* Insert every expressions in sequence here *) - x ; (module M.N (X.Y) : S) ; - let rec x = x in - let _ = x and (lazy _) = y in - (function - (* Insert every patterns here *) - | (((x : t), _ | a, b | A, B x | `A, `B x | #t) as x) - |{a= _; b= _; _} - |[|a; b|] - |A | B - |(module M) - |(module M : S) - |(module _) - |(exception E) - |[%ppx] - |M.(A | B) -> - . ) ; - (fun (type t) X ~a ~b:Y ?c ?c:(Z = W) {a; _} -> ()) + let rec x = x and (lazy _) = y in + f + (function + (* Insert every patterns here *) + | (((x : t), _ | a, b | A, B x | `A, `B x | #t) as x) + |{a= _; b= _; _} + |[|a; b|] + |A | B + |(module M) + |(module M : S) + |(module _) + |(exception E) + |[%ppx] + |M.(A | B) + |{x= (module M : S)} + |{x= (x' : t)} + |{x= (P : t)} + |{x= ((x' : t)[@attr])} -> + . ) + (fun (type t) X ~a ~b:Y ?c ?c:(Z = W) {a; _} -> ()) X ~a ~b:(x y) ?c ?c:(Some x) - {a; b= (u :> t)} + {a; b= (u :> t); c: t; d= (module M : S)} (try a.x <- b.x with Failure msg -> msg) - [|a; (b ; c)|] ; - if x then y else z ; + [|a; b + c + d|] ; + if x.{a, b} then y.*(0) else z.*(a; b) ; for i = f x to f y do - do_ i + r := x.(i) done ; - (f x)#m (new M.c) {} ; + (f x)#m (new M.c) {} ; let module M = (val S.(M.N X.Y).x) in let exception E of t in let open! M in - let* x = y and* z = w in - lazy x + let* x = ~-y and* z = (w [@attr]) in + lazy (( let* ) (function X -> ( + )) (( * ) [@attr])) ; + 1 :: ~-2 ; + [1; 2] class virtual c x ~y ?z:(z' = 0) = let open M in @@ -66,7 +83,13 @@ class virtual c x ~y ?z:(z' = 0) = method m a = a - y - method n = self#m + method n = self#m {<>} method virtual o : #ct -> int end + +type t = .. + +type t += X : t -> t + +exception E of t