-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MaxValueBindingWidth and MaxFunctionBindingWidth settings (#866)
* Rename MaxLetBindingWidth setting to MaxBindingWidth * Implement MaxBindingWidth for members and update existing tests Some of the existing tests were not passing after MaxBindingWidth was implemented for members. The reason is that members did not respect MaxLetBindingWidth before, only PageWidth. Since members now also respect MaxBindingWidth, some results of existing tests are different. * Keep existing tests unmodified where possible * Use a simpler implementation for MaxBindingWidth * Add typed member binding tests * Split MaxBindingWidth setting into MaxValueBindingWidth and MaxFunctionBindingWidth * Use List.isNotEmpty instead of List.length > 0 * Update active pattern test to use a smaller MaxFunctionBindingWidth * Remove unused helper function in SourceParser.fs Co-authored-by: Florian Verdonck <florian.verdonck@outlook.com>
- Loading branch information
Showing
26 changed files
with
196 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Fantomas.Tests.MaxFunctionBindingWidthTests | ||
|
||
open NUnit.Framework | ||
open FsUnit | ||
open Fantomas.Tests.TestHelper | ||
|
||
let config = { config with MaxFunctionBindingWidth = 20 } | ||
|
||
[<Test>] | ||
let ``should apply to function definition``() = | ||
formatSourceString false """let a bbbbbbbbbbbbbbbbbbbbbbbbbb = bbbbbbbbbbbbbbbbbbbbbbbbbb + 1""" config | ||
|> should equal """let a bbbbbbbbbbbbbbbbbbbbbbbbbb = | ||
bbbbbbbbbbbbbbbbbbbbbbbbbb + 1 | ||
""" | ||
|
||
[<Test>] | ||
let ``should not apply to short function definition``() = | ||
formatSourceString false """let a b = b + 1""" config | ||
|> should equal """let a b = b + 1 | ||
""" | ||
|
||
[<Test>] | ||
let ``should apply to member function definition``() = | ||
formatSourceString false """type T = | ||
let aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbb = bbbbbbbbbbbbbbbbbbb + 1 | ||
member this.cccccccccccccc dddddddddddddd = dddddddddddddd + 2 | ||
""" config | ||
|> should equal """type T = | ||
let aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbb = | ||
bbbbbbbbbbbbbbbbbbb + 1 | ||
member this.cccccccccccccc dddddddddddddd = dddddddddddddd + 2 | ||
""" | ||
|
||
[<Test>] | ||
let ``should apply to typed member function definition``() = | ||
formatSourceString false """type T = | ||
let aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbb = bbbbbbbbbbbbbbbbbbb + 1 | ||
member this.cccccccccccccc dddddddddddddd: int = dddddddddddddd + 2 | ||
""" config | ||
|> should equal """type T = | ||
let aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbb = | ||
bbbbbbbbbbbbbbbbbbb + 1 | ||
member this.cccccccccccccc dddddddddddddd: int = dddddddddddddd + 2 | ||
""" | ||
|
||
[<Test>] | ||
let ``should not apply to short member function definition``() = | ||
formatSourceString false """type T = | ||
let a b = b + 1 | ||
member this.c d = d + 2 | ||
""" { config with MaxFunctionBindingWidth = 30 } | ||
|> should equal """type T = | ||
let a b = b + 1 | ||
member this.c d = d + 2 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module Fantomas.Tests.MaxValueBindingWidthTests | ||
|
||
open NUnit.Framework | ||
open FsUnit | ||
open Fantomas.Tests.TestHelper | ||
|
||
let config = { config with MaxValueBindingWidth = 20; } | ||
|
||
[<Test>] | ||
let ``should apply to value definition``() = | ||
formatSourceString false """let a = bbbbbbbbbbbbbbbbbbbbbbbbbb""" config | ||
|> should equal """let a = | ||
bbbbbbbbbbbbbbbbbbbbbbbbbb | ||
""" | ||
|
||
[<Test>] | ||
let ``should not apply to short value definition``() = | ||
formatSourceString false """let a = b""" config | ||
|> should equal """let a = b | ||
""" | ||
|
||
[<Test>] | ||
let ``should apply to member value definition``() = | ||
formatSourceString false """type T = | ||
let aaaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbbbbbb + 1 | ||
member this.ccccccccccccccccccccccccccccccc = dddddddddddddddddddddddddddd + 2 | ||
""" config | ||
|> should equal """type T = | ||
let aaaaaaaaaaaaaaaaaaaa = | ||
bbbbbbbbbbbbbbbbbbb + 1 | ||
member this.ccccccccccccccccccccccccccccccc = | ||
dddddddddddddddddddddddddddd + 2 | ||
""" | ||
|
||
[<Test>] | ||
let ``should apply to typed member value definition``() = | ||
formatSourceString false """type T = | ||
let aaaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbbbbbb + 1 | ||
member (this.ccccccccccccccccccccccccccccccc: int)= dddddddddddddddddddddddddddd + 2 | ||
""" config | ||
|> should equal """type T = | ||
let aaaaaaaaaaaaaaaaaaaa = | ||
bbbbbbbbbbbbbbbbbbb + 1 | ||
member (this.ccccccccccccccccccccccccccccccc: int) = | ||
dddddddddddddddddddddddddddd + 2 | ||
""" | ||
|
||
[<Test>] | ||
let ``should not apply to short member value definition``() = | ||
formatSourceString false """type T = | ||
let a = b + 1 | ||
member this.c = d + 2 | ||
""" { config with MaxFunctionBindingWidth = 30 } | ||
|> should equal """type T = | ||
let a = b + 1 | ||
member this.c = d + 2 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.