Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Aug 9, 2024
1 parent c3ace82 commit a78ad9b
Showing 1 changed file with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ let res = { new MyClass() }
|> shouldFail
|> withDiagnostics [
(Error 365, Line 11, Col 11, Line 11, Col 28, "No implementation was given for 'abstract MyClass.M: unit -> unit'")
]
]

[<Fact>]
let ``C# abstract class with protected constructor can be implemented by F# object expression lang version preview`` () =

Expand Down Expand Up @@ -383,6 +384,88 @@ let res = { new Animal() }
|> compile
|> shouldSucceed

[<Fact>]
let ``C# abstract class with protected constructor and abstract method can not be implemented by F# object expression unless the abstract method is implemented in lang version preview.`` () =

let csharp =
CSharp
"""
namespace CSLib
{
using System;
public abstract class Animal
{
protected Animal()
{
Console.WriteLine("Animal is created");
}
public abstract void M();
}
}
"""
|> withName "CSLib"

let fsharp =
FSharp
"""
module FSLib
open CSLib
let res = { new Animal() }
"""
|> withLangVersionPreview
|> withName "FSLib"
|> withReferences [ csharp ]

fsharp
|> compile
|> shouldFail
|> withDiagnostics [
(Error 365, Line 5, Col 11, Line 5, Col 27, "No implementation was given for 'Animal.M() : unit'")
]

[<Fact>]
let ``C# abstract class with protected constructor and abstract method can not be implemented by F# object expression unless the abstract method is implemented.`` () =

let csharp =
CSharp
"""
namespace CSLib
{
using System;
public abstract class Animal
{
protected Animal()
{
Console.WriteLine("Animal is created");
}
public abstract void M();
}
}
"""
|> withName "CSLib"

let fsharp =
FSharp
"""
module FSLib
open CSLib
let res = { new Animal() }
"""
|> withLangVersion80
|> withName "FSLib"
|> withReferences [ csharp ]

fsharp
|> compile
|> shouldFail
|> withDiagnostics [
(Error 365, Line 5, Col 11, Line 5, Col 27, "No implementation was given for 'Animal.M() : unit'")
]

[<Fact>]
let ``Error when object expression does not implement all abstract members of the abstract class`` () =
Fsx """
Expand Down

0 comments on commit a78ad9b

Please sign in to comment.