From 236a561d3293adb28650e80d310c0407498045c2 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 14 Mar 2018 22:17:49 +0100 Subject: [PATCH] Removed whitespaces around type provider arguments. #131 --- src/Fantomas.Tests/TypeDeclarationTests.fs | 13 +++++++++++-- src/Fantomas.Tests/TypeProviderTests.fs | 13 +++++++++++-- src/Fantomas/CodePrinter.fs | 7 ++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Fantomas.Tests/TypeDeclarationTests.fs b/src/Fantomas.Tests/TypeDeclarationTests.fs index 344e4568fd..f3aa066c27 100644 --- a/src/Fantomas.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Tests/TypeDeclarationTests.fs @@ -628,12 +628,21 @@ type BlobHelper(Account : CloudStorageAccount) = [] let ``^a needs spaces when used as a type parameter``() = formatSourceString false """ -let inline tryAverage(seq: seq< ^a >): ^a option = 1""" config +let inline tryAverage(seq: seq< ^a >): ^a option = None""" config |> prepend newline |> should equal """ -let inline tryAverage (seq : seq< ^a >) : ^a option = 1 +let inline tryAverage (seq : seq< ^a >) : ^a option = None """ +[] +let ``multiple hats need spaces`` () = + formatSourceString false """ +let inline tryAverage(map: Map< ^a,^b>): ^a option = None""" config + |> prepend newline + |> should equal """ +let inline tryAverage (map : Map< ^a, ^b >) : ^a option = None +""" + [] let ``should preserve orders on field declarations``() = formatSourceString false """ diff --git a/src/Fantomas.Tests/TypeProviderTests.fs b/src/Fantomas.Tests/TypeProviderTests.fs index 6dc3249742..2af104a912 100644 --- a/src/Fantomas.Tests/TypeProviderTests.fs +++ b/src/Fantomas.Tests/TypeProviderTests.fs @@ -12,7 +12,7 @@ let ``type providers``() = type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/">""" config |> prepend newline |> should equal """ -type Northwind = ODataService< "http://services.odata.org/Northwind/Northwind.svc/" > +type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/"> """ [] @@ -21,7 +21,7 @@ let ``should add space before type provider params``() = type IntegerRegex = FSharpx.Regex< @"(?\d+)" >""" config |> prepend newline |> should equal """ -type IntegerRegex = FSharpx.Regex< @"(?\d+)" > +type IntegerRegex = FSharpx.Regex<@"(?\d+)"> """ [)>] @@ -48,4 +48,13 @@ let ``should handle lines with more than 512 characters``() = CommonRuntime.GetOptionalValue((let _, _, x = row x))) |]), (ProviderFileSystem.readTextAtRunTimeWithDesignTimeOptions @"C:\Dev\FSharp.Data-master\src\..\tests\FSharp.Data.Tests\Data" "" "SmallTest.csv"), "", '"', true, false)) .Cache() +""" + +[] +let ``multiple arguments in type provider``() = + formatSourceString false """ +type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/", "password">""" config + |> prepend newline + |> should equal """ +type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc/", "password"> """ \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 2baa58c40d..3c2e9dca19 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -914,10 +914,11 @@ and genType astContext outerBracket t = and genPrefixTypes astContext = function | [] -> sepNone - // Some patterns without spaces could cause a parsing error - | (TStaticConstant _ | TStaticConstantExpr _ | TStaticConstantNamed _ | TVar(Typar(_, true)) as t)::ts -> + // Where < and ^ meet, we need an extra space. For example: seq< ^a > + | (TVar(Typar(_, true)) as t)::ts -> !- "< " +> col sepComma (t::ts) (genType astContext false) -- " >" - | ts -> !- "<" +> col sepComma ts (genType astContext false) -- ">" + | ts -> + !- "<" +> col sepComma ts (genType astContext false) -- ">" and genTypeList astContext = function | [] -> sepNone