From 266ac9e8b8e833debc6be1a03b3ca754c3f5dc9a Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 1 Sep 2022 10:05:42 +0200 Subject: [PATCH] Refactor SignatureTests.fs to ArrayTests.fs. --- .../FSharp.Compiler.ComponentTests.fsproj | 2 +- .../{SignatureTests.fs => ArrayTests.fs} | 35 +++++++++---------- .../Signatures/TestHelpers.fs | 8 ++++- 3 files changed, 25 insertions(+), 20 deletions(-) rename tests/FSharp.Compiler.ComponentTests/Signatures/{SignatureTests.fs => ArrayTests.fs} (51%) diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 17948072e17..e6e08b27af7 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -199,7 +199,7 @@ - + diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/SignatureTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs similarity index 51% rename from tests/FSharp.Compiler.ComponentTests/Signatures/SignatureTests.fs rename to tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs index 462a4dca13f..2317005032f 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/SignatureTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/ArrayTests.fs @@ -1,12 +1,7 @@ module FSharp.Compiler.ComponentTests.Signatures.SignatureTests open Xunit -open FSharp.Test.Compiler - -[] -let ``Very basic signature test`` () = - FSharp "let a = 0" - |> signaturesShouldContain "val a: int" +open FSharp.Compiler.ComponentTests.Signatures.TestHelpers [] [ = [| 3 |]", "val c: int array")>] let ``Value with int array return type`` implementation expectedSignature = - FSharp implementation - |> signaturesShouldContain expectedSignature + assertSingleSignatureBinding implementation expectedSignature [] 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" [] 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" [] 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" [] let ``5 till 32 dimensional array`` () = @@ -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" ) [] let ``Use array2d syntax in implementation`` () = - FSharp "let y : int array2d = Array2D.init 0 0 (fun _ _ -> 0)" - |> signaturesShouldContain "val y: int array2d" \ No newline at end of file + assertSingleSignatureBinding + "let y : int array2d = Array2D.init 0 0 (fun _ _ -> 0)" + "val y: int array2d" diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs index 23ad4176c8b..b7fd2f13742 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TestHelpers.fs @@ -2,6 +2,7 @@ open System open FsUnit +open FSharp.Test.Compiler let prependNewline v = String.Concat("\n", v) @@ -11,4 +12,9 @@ let equal x = | :? String as s -> s.Replace("\r\n", "\n") |> box | x -> x - equal x \ No newline at end of file + equal x + +let assertSingleSignatureBinding implementation signature = + FSharp $"module A\n\n{implementation}" + |> printSignatures + |> should equal $"\nmodule A\n\n{signature}"