Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed whitespaces around type provider arguments. #131 #235

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,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 @@ -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
Expand Down