Skip to content

Commit

Permalink
Merge pull request #235 from nojaf/fix-131
Browse files Browse the repository at this point in the history
Removed whitespaces around type provider arguments. #131
  • Loading branch information
dungpa committed Mar 16, 2018
2 parents 7b133fa + 236a561 commit 9b68333
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,21 @@ type BlobHelper(Account : CloudStorageAccount) =
[<Test>]
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
"""

[<Test>]
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
"""

[<Test>]
let ``should preserve orders on field declarations``() =
formatSourceString false """
Expand Down
13 changes: 11 additions & 2 deletions src/Fantomas.Tests/TypeProviderTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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/">
"""

[<Test>]
Expand All @@ -21,7 +21,7 @@ let ``should add space before type provider params``() =
type IntegerRegex = FSharpx.Regex< @"(?<value>\d+)" >""" config
|> prepend newline
|> should equal """
type IntegerRegex = FSharpx.Regex< @"(?<value>\d+)" >
type IntegerRegex = FSharpx.Regex<@"(?<value>\d+)">
"""

[<Test; ExpectedException(typeof<Fantomas.FormatConfig.FormatException>)>]
Expand All @@ -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()
"""

[<Test>]
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">
"""
7 changes: 4 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,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
Expand Down

0 comments on commit 9b68333

Please sign in to comment.