diff --git a/.ci/esy-build-steps.yml b/.ci/esy-build-steps.yml index 7c63d636e..4084ca182 100644 --- a/.ci/esy-build-steps.yml +++ b/.ci/esy-build-steps.yml @@ -11,5 +11,7 @@ steps: - template: utils/publish-build-cache.yml - script: esy x refmt --version displayName: 'esy x refmt --version' + - script: esy make test + displayName: 'esy make test' # Run tests or any additional steps here # - script: esy b dune runtest diff --git a/formatTest/errorTests/expected_output/syntaxError.re b/formatTest/errorTests/expected_output/syntaxError.re index 4f9ab58b4..258b460c8 100644 --- a/formatTest/errorTests/expected_output/syntaxError.re +++ b/formatTest/errorTests/expected_output/syntaxError.re @@ -1,3 +1,3 @@ File "syntaxError.re", line 1, characters 9-10: Error: File "syntaxError.re", line 1, characters 9-10: -Error: Syntax error + Error: Syntax error diff --git a/formatTest/errorTests/expected_output/syntaxError.re.4.06.0 b/formatTest/errorTests/expected_output/syntaxError.re.4.06.0 new file mode 100644 index 000000000..258b460c8 --- /dev/null +++ b/formatTest/errorTests/expected_output/syntaxError.re.4.06.0 @@ -0,0 +1,3 @@ +File "syntaxError.re", line 1, characters 9-10: +Error: File "syntaxError.re", line 1, characters 9-10: + Error: Syntax error diff --git a/formatTest/test.sh b/formatTest/test.sh index a7b9516dd..f3b97e804 100755 --- a/formatTest/test.sh +++ b/formatTest/test.sh @@ -13,6 +13,8 @@ VERBOSE=${VERBOSE:-} OCAML_VERSION=`echo $(ocaml -version) | egrep -o '[0-9]+.[0-9]+.[0-9]+' | head -1` OCAML_VERSION=${OCAML_VERSION:-"4.02.3"} +echo "Testing with OCaml Version: $OCAML_VERSION" + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REFMT="$DIR/../_build/install/default/bin/refmt" diff --git a/formatTest/typeCheckedTests/expected_output/unary.re b/formatTest/typeCheckedTests/expected_output/unary.re new file mode 100644 index 000000000..232b8c9e6 --- /dev/null +++ b/formatTest/typeCheckedTests/expected_output/unary.re @@ -0,0 +1,88 @@ +type result('a, 'b) = + | Ok('a) + | Error('b); + +let returnsAResultToBeUnwrapped = (a, b, c) => + switch (a, b, c) { + | (None, Some(i), Some(j)) => Ok((i, j)) + | (Some(i), Some(j), None) => + Ok(("hi", "bye")) + | _ => + Error( + Invalid_argument( + "This is not a valid argument", + ), + ) + }; + +let returnsAnIntegerResultNotWrapped = (a, b, c) => + switch (a, b, c) { + | (None, Some(i), Some(j)) => 0 + | (Some(i), Some(j), None) => (-1) + | _ => 100 + }; + +let returnsABoolReturnValueNoResult = (a, b, c) => + switch (a, b, c) { + | (None, Some(i), Some(j)) => true + | (Some(i), Some(j), None) => false + | _ => false + }; + +let (!!) = res => + switch (res) { + | Ok(o) => o + | Error(e) => raise(e) + }; + +let result = + !!returnsAResultToBeUnwrapped( + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + ); + +let result = + - returnsAnIntegerResultNotWrapped( + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + ); + +let result = + + returnsAnIntegerResultNotWrapped( + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + ); + +let result = + !returnsABoolReturnValueNoResult( + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + Some( + "this realy long string will make things wrap", + ), + ); diff --git a/formatTest/typeCheckedTests/input/unary.re b/formatTest/typeCheckedTests/input/unary.re new file mode 100644 index 000000000..6b6dd3a02 --- /dev/null +++ b/formatTest/typeCheckedTests/input/unary.re @@ -0,0 +1,51 @@ + + +type result('a, 'b) = Ok('a) | Error('b); + +let returnsAResultToBeUnwrapped = (a, b, c) => switch(a, b, c) { + | (None, Some(i), Some(j)) => Ok((i, j)); + | (Some(i), Some(j), None) => Ok(("hi", "bye")); + | _ => Error(Invalid_argument("This is not a valid argument")) +}; + +let returnsAnIntegerResultNotWrapped = (a, b, c) => switch(a,b, c) { + | (None, Some(i), Some(j)) => 0 + | (Some(i), Some(j), None) => -1 + | _ => 100 +}; + +let returnsABoolReturnValueNoResult = (a, b, c) => switch(a,b, c) { + | (None, Some(i), Some(j)) => true + | (Some(i), Some(j), None) => false + | _ => false +}; + +let (!!) = res => switch(res) { + | Ok(o) => o + | Error(e) => raise(e) +}; + + +let result = !!returnsAResultToBeUnwrapped( + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap") +); + +let result = -returnsAnIntegerResultNotWrapped( + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap") +) + +let result = +returnsAnIntegerResultNotWrapped( + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap") +) + +let result = !returnsABoolReturnValueNoResult( + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap"), + Some("this realy long string will make things wrap") +); diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index a02699219..94443d196 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -4068,7 +4068,7 @@ let printer = object(self:'self) self#ensureContainingRule ~withPrecedence:prec ~reducesAfterRight:rightExpr () ) in SpecificInfixPrecedence - ({reducePrecedence=prec; shiftPrecedence = prec}, LayoutNode (label ~space:forceSpace (atom prefixStr) rightItm)) + ({reducePrecedence=prec; shiftPrecedence = prec}, LayoutNode (label ~indent:0 ~break:`Never ~space:forceSpace (atom prefixStr) rightItm)) | (UnaryPostfix postfixStr, [(Nolabel, leftExpr)]) -> let forceSpace = match leftExpr.pexp_desc with | Pexp_apply (ee, _) -> @@ -4118,7 +4118,7 @@ let printer = object(self:'self) let rightItm = self#unparseResolvedRule ( self#ensureContainingRule ~withPrecedence:prec ~reducesAfterRight:rightExpr () ) in - let expr = label ~space:true (atom printedIdent) rightItm in + let expr = label ~indent:0 ~break:`Never ~space:true (atom printedIdent) rightItm in SpecificInfixPrecedence ({reducePrecedence=prec; shiftPrecedence=Token printedIdent}, LayoutNode expr) | (UnaryMinusPrefix printedIdent as x, [(Nolabel, rightExpr)]) | (UnaryNotPrefix printedIdent as x, [(Nolabel, rightExpr)]) -> @@ -4133,7 +4133,7 @@ let printer = object(self:'self) let rightItm = self#unparseResolvedRule ( self#ensureContainingRule ~withPrecedence:prec ~reducesAfterRight:rightExpr () ) in - let expr = label ~space:forceSpace (atom printedIdent) rightItm in + let expr = label ~break:`Never ~indent:0 ~space:forceSpace (atom printedIdent) rightItm in SpecificInfixPrecedence ({reducePrecedence=prec; shiftPrecedence=Token printedIdent}, LayoutNode expr) (* Will need to be rendered in self#expression as (~-) x y z. *) | (_, _) ->