Skip to content

Commit

Permalink
Refactor SignatureTests.fs to ArrayTests.fs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 6, 2022
1 parent db8fedd commit 266ac9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
<Compile Include="Signatures\TestHelpers.fs" />
<Compile Include="Signatures\ModuleOrNamespaceTests.fs" />
<Compile Include="Signatures\RecordTests.fs" />
<Compile Include="Signatures\SignatureTests.fs" />
<Compile Include="Signatures\ArrayTests.fs" />
</ItemGroup>
<ItemGroup>
<Content Include="resources\**" CopyToOutputDirectory="Never" CopyToPublishDirectory="PreserveNewest" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
module FSharp.Compiler.ComponentTests.Signatures.SignatureTests

open Xunit
open FSharp.Test.Compiler

[<Fact>]
let ``Very basic signature test`` () =
FSharp "let a = 0"
|> signaturesShouldContain "val a: int"
open FSharp.Compiler.ComponentTests.Signatures.TestHelpers

[<Theory>]
[<InlineData("let a : int[] = [| 1 |]",
Expand All @@ -16,23 +11,25 @@ let ``Very basic signature test`` () =
[<InlineData("let c: array<int> = [| 3 |]",
"val c: int array")>]
let ``Value with int array return type`` implementation expectedSignature =
FSharp implementation
|> signaturesShouldContain expectedSignature
assertSingleSignatureBinding implementation expectedSignature

[<Fact>]
let ``2 dimensional array`` () =
FSharp "let a : int[,] = failwith \"todo\""
|> signaturesShouldContain "val a: int array2d"
assertSingleSignatureBinding
"let a : int[,] = failwith \"todo\""
"val a: int array2d"

[<Fact>]
let ``3 dimensional array`` () =
FSharp "let a : int[,,] = failwith \"todo\""
|> signaturesShouldContain "val a: int array3d"
assertSingleSignatureBinding
"let a : int[,,] = failwith \"todo\""
"val a: int array3d"

[<Fact>]
let ``4 dimensional array`` () =
FSharp "let a : int[,,,] = failwith \"todo\""
|> signaturesShouldContain "val a: int array4d"
assertSingleSignatureBinding
"let a : int[,,,] = failwith \"todo\""
"val a: int array4d"

[<Fact>]
let ``5 till 32 dimensional array`` () =
Expand All @@ -42,11 +39,13 @@ let ``5 till 32 dimensional array`` () =
[ 1 .. idx ]
|> List.fold (fun acc _ -> $"array<{acc}>") "int"

FSharp $"let a : {arrayType} = failwith \"todo\""
|> signaturesShouldContain $"val a: int array{idx}d"
assertSingleSignatureBinding
$"let a : {arrayType} = failwith \"todo\""
$"val a: int array{idx}d"
)

[<Fact>]
let ``Use array2d syntax in implementation`` () =
FSharp "let y : int array2d = Array2D.init 0 0 (fun _ _ -> 0)"
|> signaturesShouldContain "val y: int array2d"
assertSingleSignatureBinding
"let y : int array2d = Array2D.init 0 0 (fun _ _ -> 0)"
"val y: int array2d"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open FsUnit
open FSharp.Test.Compiler

let prependNewline v = String.Concat("\n", v)

Expand All @@ -11,4 +12,9 @@ let equal x =
| :? String as s -> s.Replace("\r\n", "\n") |> box
| x -> x

equal x
equal x

let assertSingleSignatureBinding implementation signature =
FSharp $"module A\n\n{implementation}"
|> printSignatures
|> should equal $"\nmodule A\n\n{signature}"

0 comments on commit 266ac9e

Please sign in to comment.