Skip to content

Commit

Permalink
Add tests for new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 13, 2024
1 parent ec0ad23 commit 3116d69
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 4 deletions.
37 changes: 37 additions & 0 deletions src/Fantomas.Core.Tests/AutoPropertiesTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Fantomas.Core.Tests.AutoPropertiesTests

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

[<Test>]
let ``public get, private set`` () =
formatSourceString
"""
type X() =
member val Y: int = 7 with public get, private set
"""
config
|> prepend newline
|> should
equal
"""
"""

[<Test>]
let ``public get, private set in signature`` () =
formatSignatureString
"""
module A
type X() =
member val internal Y: int = 7 with public get, private set
"""
config
|> prepend newline
|> should
equal
"""
"""
1 change: 1 addition & 0 deletions src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<Compile Include="ConstraintIntersectionTests.fs" />
<Compile Include="BeginEndTests.fs" />
<Compile Include="NullnessTests.fs" />
<Compile Include="AutoPropertiesTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />
Expand Down
93 changes: 89 additions & 4 deletions src/Fantomas.Core.Tests/NullnessTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,97 @@ open FsUnit
open Fantomas.Core.Tests.TestHelpers

[<Test>]
let ``abstract property`` () =
let ``du case of string or null`` () =
formatSourceString
"""
[<AbstractClass>]
type AbstractBase() =
abstract Property1 : string | null with get, set
type DU = MyCase of (string | null)
"""
config
|> prepend newline
|> should
equal
"""
"""

[<Test>]
let ``multiple or type`` () =
formatSourceString
"""
let myFunc ("abc" | "" : string | null | "123") = 15
"""
config
|> prepend newline
|> should
equal
"""
"""

[<Test>]
let ``null type constraint`` () =
formatSourceString
"""
let myFunc() : 'T when 'T : not struct and 'T:null = null
"""
config
|> prepend newline
|> should
equal
"""
"""

[<Test>]
let ``not null type constraint`` () =
formatSourceString
"""
let myFunc (x: 'T when 'T: not null) = 42
"""
config
|> prepend newline
|> should
equal
"""
"""

[<Test>]
let ``not null in type constraints`` () =
formatSourceString
"""
type C<'T when 'T: not null> = class end
"""
config
|> prepend newline
|> should
equal
"""
"""

[<Test>]
let ``or null pattern`` () =
formatSourceString
"""
match x with
| :? string | null -> ()
"""
config
|> prepend newline
|> should
equal
"""
"""

[<Test>]
let ``nullness in signature file`` () =
formatSignatureString
"""
namespace Meh
type DU = MyCase of (string | null)
"""
config
|> prepend newline
Expand Down

0 comments on commit 3116d69

Please sign in to comment.