From a169c107b062485e4529118540e9d4cc951d8cfa Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Sat, 17 Jul 2021 04:19:37 +0300 Subject: [PATCH] Add ocamlformat test case Part of #94. --- .ocamlformat | 10 ++++- Makefile | 10 +++++ test/ocamlformat/test.actual.ml | 68 +++++++++++++++++++++++++++++++ test/ocamlformat/test.expect.ml | 68 +++++++++++++++++++++++++++++++ test/ocamlformat/test.ml | 72 +++++++++++++++++++++++++++++++++ 5 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 test/ocamlformat/test.actual.ml create mode 100644 test/ocamlformat/test.expect.ml create mode 100644 test/ocamlformat/test.ml diff --git a/.ocamlformat b/.ocamlformat index 7fbeb55..a5aa52b 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,13 +1,21 @@ version = 0.18.0 profile = conventional -leading-nested-match-parens = false +leading-nested-match-parens = false align-constructors-decl = true align-variants-decl = true space-around-variants = false space-around-arrays = false +space-around-lists = false +space-around-records = false break-before-in = auto break-infix = fit-or-vertical break-separators = after space-around-records = true break-cases = all +cases-exp-indent = 2 +exp-grouping = preserve +nested-match = align +if-then-else = fit-or-vertical +let-and = sparse +type-decl = sparse diff --git a/Makefile b/Makefile index 01fca83..1638174 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,16 @@ clean : clean-coverage make --no-print-directory -C docs/web clean rm -rf src/graphiql/node_modules dream-* _release +.PHONY : test-ocamlformat +test-ocamlformat : + touch test/ocamlformat/test.expect.ml + ocamlformat test/ocamlformat/test.ml > test/ocamlformat/test.actual.ml + diff -u3 test/ocamlformat/test.expect.ml test/ocamlformat/test.actual.ml + +.PHONY : test-ocamlformat-promote +test-ocamlformat-promote : + ocamlformat test/ocamlformat/test.ml > test/ocamlformat/test.expect.ml + .PHONY : utop utop : dune utop diff --git a/test/ocamlformat/test.actual.ml b/test/ocamlformat/test.actual.ml new file mode 100644 index 0000000..816ded5 --- /dev/null +++ b/test/ocamlformat/test.actual.ml @@ -0,0 +1,68 @@ +(* Failure: space still inserted near delimiters when not type-decl = sparse. *) +type t = { + a : string; + b : string; + c : string; +} + +let t = + { + a = "a_pretty_long_string_to_force_separate_line"; + b = "a_pretty_long_string_to_force_separate_line"; + c = "a_pretty_long_string_to_force_separate_line"; + } + +type t = + | A of int + | B of string + | C of unit + +(* Failure: the bracket is set on the first line rather than having unifrom + lines. *) +type t = + [ `A of int + | `B of string + | `C of unit ] + +let list = [a; b; c] + +let list = + [ + a_very_long_identifier_or_expression_one; + a_very_long_identifier_or_expression_two; + a_very_long_identifier_or_expression_three; + ] + +let bool = + match true with + | true -> false + | false -> true + +let () = + match () with + | () -> + print_endline "foo"; + print_endline "bar" + +(* Failure: begin...end replaced by parentheses. *) +let () = + match true with + | true -> ( + match () with + | () -> + print_endline "foo"; + print_endline "bar") + | () -> + print_endline "foo"; + print_endline "bar" + +let f = function + | () -> + print_endline "foo"; + print_endline "bar" + +let () = + if true then + () + else + () diff --git a/test/ocamlformat/test.expect.ml b/test/ocamlformat/test.expect.ml new file mode 100644 index 0000000..816ded5 --- /dev/null +++ b/test/ocamlformat/test.expect.ml @@ -0,0 +1,68 @@ +(* Failure: space still inserted near delimiters when not type-decl = sparse. *) +type t = { + a : string; + b : string; + c : string; +} + +let t = + { + a = "a_pretty_long_string_to_force_separate_line"; + b = "a_pretty_long_string_to_force_separate_line"; + c = "a_pretty_long_string_to_force_separate_line"; + } + +type t = + | A of int + | B of string + | C of unit + +(* Failure: the bracket is set on the first line rather than having unifrom + lines. *) +type t = + [ `A of int + | `B of string + | `C of unit ] + +let list = [a; b; c] + +let list = + [ + a_very_long_identifier_or_expression_one; + a_very_long_identifier_or_expression_two; + a_very_long_identifier_or_expression_three; + ] + +let bool = + match true with + | true -> false + | false -> true + +let () = + match () with + | () -> + print_endline "foo"; + print_endline "bar" + +(* Failure: begin...end replaced by parentheses. *) +let () = + match true with + | true -> ( + match () with + | () -> + print_endline "foo"; + print_endline "bar") + | () -> + print_endline "foo"; + print_endline "bar" + +let f = function + | () -> + print_endline "foo"; + print_endline "bar" + +let () = + if true then + () + else + () diff --git a/test/ocamlformat/test.ml b/test/ocamlformat/test.ml new file mode 100644 index 0000000..c2b7811 --- /dev/null +++ b/test/ocamlformat/test.ml @@ -0,0 +1,72 @@ +(* Failure: space still inserted near delimiters when not type-decl = sparse. *) +type t = { + a : string; + b : string; + c : string; +} + +let t = { + a = "a_pretty_long_string_to_force_separate_line"; + b = "a_pretty_long_string_to_force_separate_line"; + c = "a_pretty_long_string_to_force_separate_line"; +} + +type t = + | A of int + | B of string + | C of unit + +(* Failure: the bracket is set on the first line rather than having unifrom + lines. *) +type t = [ + | `A of int + | `B of string + | `C of unit +] + +let list = [ + a; + b; + c; +] + +let list = [ + a_very_long_identifier_or_expression_one; + a_very_long_identifier_or_expression_two; + a_very_long_identifier_or_expression_three; +] + +let bool = + match true with + | true -> false + | false -> true + +let () = + match () with + | () -> + print_endline "foo"; + print_endline "bar" + +(* Failure: begin...end replaced by parentheses. *) +let () = + match true with + | true -> + begin match () with + | () -> + print_endline "foo"; + print_endline "bar" + end + | () -> + print_endline "foo"; + print_endline "bar" + +let f = function + | () -> + print_endline "foo"; + print_endline "bar" + +let () = + if true then + () + else + ()