Skip to content

Commit

Permalink
Initial chain proof of concept. (#2696)
Browse files Browse the repository at this point in the history
* Initial chain proof of concept.

* Update test result according to proposal.

* Trivia inside chain.

* Remove obsolete ExprDotGetAppWithLambdaNode

* Excluded ExprAppWithLambdaNode in Chain.

* Update src/Fantomas.Core.Tests/ChainTests.fs

Co-authored-by: dawe <[email protected]>

* Add release notes for 5.2.0-alpha-011.

Co-authored-by: dawe <[email protected]>
  • Loading branch information
nojaf and dawedawe authored Jan 12, 2023
1 parent d228149 commit b6f7ecf
Show file tree
Hide file tree
Showing 18 changed files with 898 additions and 704 deletions.
10 changes: 4 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## [5.2.0-alpha-011] - 2023-01-12

### Fixes
* Stroustrup: Two lists given directly as parameters, break code [#2681](https://github.com/fsprojects/fantomas/issues/2681)
Expand All @@ -10,11 +10,9 @@
* Piped multiline application is indented too far. [#2682](https://github.com/fsprojects/fantomas/issues/2682)
* Comment not assigned to first parameter in constructor. [#2692](https://github.com/fsprojects/fantomas/issues/2692)
* Stroustrup: Type alias for anonymous record type. [#2179](https://github.com/fsprojects/fantomas/issues/2179)

## [5.2.0-beta-001] - 2023-01-02

### Changed
* Consider v5.2 to be stable and production ready.
* Space before lambda should not occur in chain. [#2685](https://github.com/fsprojects/fantomas/issues/2685)
* Trivia inside chained lambda is not restored correctly. [#2686](https://github.com/fsprojects/fantomas/issues/2686)
* SpaceBeforeUppercaseInvocation not respected in TypeApp DotGet. [#2700](https://github.com/fsprojects/fantomas/issues/2700)

## [5.2.0-alpha-010] - 2022-12-30

Expand Down
282 changes: 282 additions & 0 deletions src/Fantomas.Core.Tests/ChainTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
module Fantomas.Core.Tests.ChainTests

open NUnit.Framework
open FsUnit
open Fantomas.Core.Tests.TestHelper

[<Test>]
let ``appUnit dot identifier`` () =
formatSourceString
false
"""
X().Y
"""
config
|> prepend newline
|> should
equal
"""
X().Y
"""

[<Test>]
let ``appParen dot identifier`` () =
formatSourceString
false
"""
X(a).Y
"""
config
|> prepend newline
|> should
equal
"""
X(a).Y
"""

[<Test>]
let ``appUnit dot appUnit`` () =
formatSourceString
false
"""
X().Y()
"""
config
|> prepend newline
|> should
equal
"""
X().Y()
"""

[<Test>]
let ``typed appUnit dot identifier`` () =
formatSourceString
false
"""
X<a>().Y
X<a>().Y<b>()
"""
config
|> prepend newline
|> should
equal
"""
X<a>().Y
X<a>().Y<b>()
"""

[<Test>]
let ``appParenLambda dot identifier`` () =
formatSourceString
false
"""
X(fun x -> x).Y
"""
config
|> prepend newline
|> should
equal
"""
X(fun x -> x).Y
"""

[<Test>]
let ``identifier dot appUnit dot identifier`` () =
formatSourceString
false
"""
X.Y().Z
"""
config
|> prepend newline
|> should
equal
"""
X.Y().Z
"""

[<Test>]
let ``identifier dot indexed expr dot identifier`` () =
formatSourceString
false
"""
A.[0].B
"""
config
|> prepend newline
|> should
equal
"""
A.[0].B
"""

[<Test>]
let ``identifier dot indexed expr dot appParenExpr`` () =
formatSourceString
false
"""
A.[0].B(1)
"""
config
|> prepend newline
|> should
equal
"""
A.[0].B(1)
"""

[<Test>]
let ``identifier dot typed appUnit dot identifier`` () =
formatSourceString
false
"""
X.Y<a>().Z
"""
config
|> prepend newline
|> should
equal
"""
X.Y<a>().Z
"""

[<Test>]
let ``identifier dot typed identifier dot identifier`` () =
formatSourceString
false
"""
X.Y<a>.Z
"""
config
|> prepend newline
|> should
equal
"""
X.Y<a>.Z
"""

[<Test>]
let ``appUnit dot appParen`` () =
formatSourceString
false
"""
A().B(fun b -> b)
"""
config
|> prepend newline
|> should
equal
"""
A().B(fun b -> b)
"""

[<Test>]
let ``identifier dot appUnit dot typed appUnit `` () =
formatSourceString
false
"""
A.B().C<'d>()
"""
{ config with
MaxDotGetExpressionWidth = 0 }
|> prepend newline
|> should
equal
"""
A
.B()
.C<'d>()
"""

[<Test>]
let ``identifier dot appUnit dot typed identifier `` () =
formatSourceString
false
"""
A.B().C<'d>
"""
{ config with
MaxDotGetExpressionWidth = 0 }
|> prepend newline
|> should
equal
"""
A
.B()
.C<'d>
"""

[<Test>]
let ``identifier dot identifier dot appExpr dot appUnit dot index expr`` () =
formatSourceString
false
"""
A.B.C(D).E().[0]
"""
{ config with
MaxDotGetExpressionWidth = 0 }
|> prepend newline
|> should
equal
"""
A.B
.C(D)
.E()
.[0]
"""

[<Test>]
let ``identifier dot identifier dot appExpr dot identifier dot index expr`` () =
formatSourceString
false
"""
A.B.C(D).E.[0]
"""
{ config with
MaxDotGetExpressionWidth = 0 }
|> prepend newline
|> should
equal
"""
A.B
.C(D)
.E.[0]
"""

[<Test>]
let ``trivia inside chain, 2686`` () =
formatSourceString
false
"""
builder.
FirstThing<X>(fun lambda ->
// aaaaaa
()
)
.SecondThing<Y>(fun next ->
// bbbbb
next
)
// ccccc
.ThirdThing<Z>().X
"""
{ config with
MultiLineLambdaClosingNewline = true }
|> prepend newline
|> should
equal
"""
builder
.FirstThing<X>(fun lambda ->
// aaaaaa
()
)
.SecondThing<Y>(fun next ->
// bbbbb
next
)
// ccccc
.ThirdThing<Z>()
.X
"""
4 changes: 1 addition & 3 deletions src/Fantomas.Core.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,9 +2287,7 @@ let loader (projectRoot: string) (siteContent: SiteContents) =
"""
let loadFile n =
let file =
System
.IO
.Path
System.IO.Path
.Combine(
contentDir,
(n |> System.IO.Path.GetFileNameWithoutExtension)
Expand Down
Loading

0 comments on commit b6f7ecf

Please sign in to comment.