From b15f804a6f24a12d3dd5d4b2900e70eb57cddc9e Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 20:17:39 +0200 Subject: [PATCH 01/12] Migrated AbsOnIntegers01.fs test case --- .../Libraries/Core/Operators/AbsTests.fs | 21 +++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Core/Operators/AbsOnIntegers01.fs | 15 ------------- .../Source/Libraries/Core/Operators/env.lst | 3 +-- 4 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs new file mode 100644 index 00000000000..26d1af738fa --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Test.Utilities +open FSharp.Compiler.SourceCodeServices + +[] +module ``Abs Tests`` = + + [] + let ``Abs of integral types``() = + // Regression test for FSHARP1.0:3470 - exception on abs of native integer + + Assert.areEqual (abs -1y) 1y // signed byte + Assert.areEqual (abs -1s) 1s // int16 + Assert.areEqual (abs -1l) 1l // int32 + Assert.areEqual (abs -1n) 1n // nativeint + Assert.areEqual (abs -1L) 1L // int64 + Assert.areEqual (abs -1I) 1I // bigint \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 374a27b68cb..776ba3944f2 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -68,6 +68,7 @@ + diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs deleted file mode 100644 index 76687657876..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs +++ /dev/null @@ -1,15 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:3470 - exception on abs of native integer - -#light - -let res = - abs -1y = 1y // signed byte - && abs -1s = 1s // int16 - && abs -1l = 1l // int32 - && abs -1n = 1n // nativeint - && abs -1L = 1L // int64 - && abs -1I = 1I // bigint - -if not res then exit 1 -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index 3b893973508..b2825f967b6 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -3,11 +3,10 @@ SOURCE=E_sign02.fs SCFLAGS=--test:ErrorRanges # E_sign02.fs SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs - SOURCE=AbsOnIntegers01.fs # AbsOnIntegers01.fs SOURCE=E_AbsOnIntegers02.fs SCFLAGS="--test:ErrorRanges --nowarn:20" # E_AbsOnIntegers02.fs SOURCE=CastOperator.fs # CastOperator.fs SOURCE=EqualityAndUncheckedHash01.fs SCFLAGS=-a # EqualityAndUncheckedHash01.fs SOURCE=E_EqualityAndHash01.fs SCFLAGS=--test:ErrorRanges # E_EqualityAndHash01.fs - + SOURCE=StringOnEnum01.fs # StringOnEnum01.fs \ No newline at end of file From 056896c988920282f966fc11e0a4f359f1dca9b0 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 20:22:56 +0200 Subject: [PATCH 02/12] Cleanup --- tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs index 26d1af738fa..1d35f72127e 100644 --- a/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs @@ -4,7 +4,6 @@ namespace FSharp.Compiler.UnitTests open NUnit.Framework open FSharp.Test.Utilities -open FSharp.Compiler.SourceCodeServices [] module ``Abs Tests`` = From 0bae86416d9ff81d05bd48a22df7199aa92b25d7 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 20:23:11 +0200 Subject: [PATCH 03/12] Migrated CastOperator.fs test case --- .../Libraries/Core/Operators/CastTests.fs | 19 +++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Libraries/Core/Operators/CastOperator.fs | 11 ----------- .../Source/Libraries/Core/Operators/env.lst | 1 - 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs new file mode 100644 index 00000000000..5f4d34df153 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Test.Utilities +open System + +[] +module ``Cast Tests`` = + + [] + let ``Cast precedence over expression forms``() = + // Regression test for FSHARP1.0:1247 + // Precedence of type annotations :> and :?> over preceeding expression forms, e.g. if-then-else etc. + + Assert.IsInstanceOf (2 :> Object) + Assert.IsInstanceOf [(2 :> Object)] + Assert.IsInstanceOf [2 :> Object] \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 776ba3944f2..cda142e2208 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -69,6 +69,7 @@ + diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs deleted file mode 100644 index a79a04119b2..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs +++ /dev/null @@ -1,11 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:1247 -// Precedence of type annotations :> and :?> over preceeding expression forms, e.g. if-then-else etc. -// - -open System -let x = 2 :> Object -let y = [(2 :> Object)] -let z = [2 :> Object] - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index b2825f967b6..c2423af0a39 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -4,7 +4,6 @@ SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs SOURCE=E_AbsOnIntegers02.fs SCFLAGS="--test:ErrorRanges --nowarn:20" # E_AbsOnIntegers02.fs - SOURCE=CastOperator.fs # CastOperator.fs SOURCE=EqualityAndUncheckedHash01.fs SCFLAGS=-a # EqualityAndUncheckedHash01.fs SOURCE=E_EqualityAndHash01.fs SCFLAGS=--test:ErrorRanges # E_EqualityAndHash01.fs From 82c6b1c6f21aa868afb13ab335922daf9e243173 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 20:47:47 +0200 Subject: [PATCH 04/12] Migrated e_AbsOnIntegers02.fs test case --- .../Libraries/Core/Operators/AbsTests.fs | 78 ++++++++++++++++++- .../Core/Operators/e_AbsOnIntegers02.fs | 17 ---- .../Source/Libraries/Core/Operators/env.lst | 1 - 3 files changed, 76 insertions(+), 20 deletions(-) delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs index 1d35f72127e..806c93b7dba 100644 --- a/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs @@ -3,13 +3,14 @@ namespace FSharp.Compiler.UnitTests open NUnit.Framework +open FSharp.Compiler.SourceCodeServices open FSharp.Test.Utilities [] module ``Abs Tests`` = [] - let ``Abs of integral types``() = + let ``Abs of signed integral types``() = // Regression test for FSHARP1.0:3470 - exception on abs of native integer Assert.areEqual (abs -1y) 1y // signed byte @@ -17,4 +18,77 @@ module ``Abs Tests`` = Assert.areEqual (abs -1l) 1l // int32 Assert.areEqual (abs -1n) 1n // nativeint Assert.areEqual (abs -1L) 1L // int64 - Assert.areEqual (abs -1I) 1I // bigint \ No newline at end of file + Assert.areEqual (abs -1I) 1I // bigint + + [] + let ``Abs of byte``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1uy |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'byte' does not support the operator 'Abs'" + + [] + let ``Abs of uint16``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1us |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint16' does not support the operator 'Abs'" + + [] + let ``Abs of uint32``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1ul |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint32' does not support the operator 'Abs'" + + CompilerAssert.TypeCheckSingleError + """ +abs -1u |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 8) + "The type 'uint32' does not support the operator 'Abs'" + + [] + let ``Abs of unativeint``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1un |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'unativeint' does not support the operator 'Abs'" + + [] + let ``Abs of uint64``() = + CompilerAssert.TypeCheckSingleError + """ +abs -1uL |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint64' does not support the operator 'Abs'" + + CompilerAssert.TypeCheckSingleError + """ +abs -1UL |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint64' does not support the operator 'Abs'" \ No newline at end of file diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs deleted file mode 100644 index 60ec1eb5da6..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs +++ /dev/null @@ -1,17 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:3470 - exception on abs of native integer -//The type 'byte' does not support the operator 'Abs'$ -//The type 'uint16' does not support the operator 'Abs'$ -//The type 'uint32' does not support the operator 'Abs'$ -//The type 'uint32' does not support the operator 'Abs'$ -//The type 'unativeint' does not support the operator 'Abs'$ -//The type 'uint64' does not support the operator 'Abs'$ -//The type 'uint64' does not support the operator 'Abs'$ - -abs -1uy // byte -abs -1us // uint16 -abs -1ul // uint32 -abs -1u // uint32 -abs -1un // unativeint -abs -1uL // uint64 -abs -1UL // uint64 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index c2423af0a39..b6e9d3f057e 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -3,7 +3,6 @@ SOURCE=E_sign02.fs SCFLAGS=--test:ErrorRanges # E_sign02.fs SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs - SOURCE=E_AbsOnIntegers02.fs SCFLAGS="--test:ErrorRanges --nowarn:20" # E_AbsOnIntegers02.fs SOURCE=EqualityAndUncheckedHash01.fs SCFLAGS=-a # EqualityAndUncheckedHash01.fs SOURCE=E_EqualityAndHash01.fs SCFLAGS=--test:ErrorRanges # E_EqualityAndHash01.fs From e33748ebdae606ce3a10e59bc105714e00e1406d Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 20:52:19 +0200 Subject: [PATCH 05/12] Migrated E_EqualityAndHash01.fs test case --- .../Libraries/Core/Operators/HashTests.fs | 26 +++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Core/Operators/E_EqualityAndHash01.fs | 8 ------ .../Source/Libraries/Core/Operators/env.lst | 1 - 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs new file mode 100644 index 00000000000..f7f89140255 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Compiler.SourceCodeServices +open FSharp.Test.Utilities + +[] +module ``Hash Tests`` = + + [] + let ``Hash of function values``() = + // Regression test for FSHARP1.0:5436 + // You should not be able to hash F# function values) + // Note: most positive cases already covered under fsharp\typecheck\sigs + // I'm adding this simple one since I did not see it there. + + CompilerAssert.TypeCheckSingleError + """ +hash id |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 8) + "The type '('a -> 'a)' does not support the 'equality' constraint because it is a function type" \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index cda142e2208..ba10f0f2618 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -70,6 +70,7 @@ + diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs deleted file mode 100644 index 46f3d2cd725..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs +++ /dev/null @@ -1,8 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:5436 -// You should not be able to hash F# function values) -// Note: most positive cases already covered under fsharp\typecheck\sigs -// I'm adding this simple one since I did not see it there. -//The type '\('a -> 'a\)' does not support the 'equality' constraint because it is a function type - -let q = hash id diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index b6e9d3f057e..669dc84e258 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -5,6 +5,5 @@ SOURCE=string01.fs # string01.fs SOURCE=EqualityAndUncheckedHash01.fs SCFLAGS=-a # EqualityAndUncheckedHash01.fs - SOURCE=E_EqualityAndHash01.fs SCFLAGS=--test:ErrorRanges # E_EqualityAndHash01.fs SOURCE=StringOnEnum01.fs # StringOnEnum01.fs \ No newline at end of file From c93e07f7d3e62a8272c287d08c462889c89457b9 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 20:58:59 +0200 Subject: [PATCH 06/12] Migrated E_sign02.fs test case --- .../Libraries/Core/Operators/SignTests.fs | 57 +++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Libraries/Core/Operators/E_sign02.fs | 12 ---- .../Source/Libraries/Core/Operators/env.lst | 1 - 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs new file mode 100644 index 00000000000..b1bda270920 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Compiler.SourceCodeServices +open FSharp.Test.Utilities + +[] +module ``Sign Tests`` = + + // #Regression #Libraries #Operators + // Test sign function on unsigned primitives, should get error. + + [] + let ``Sign of byte``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0uy |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'byte' does not support the operator 'get_Sign'" + + [] + let ``Sign of uint16``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0us |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint16' does not support the operator 'get_Sign'" + + [] + let ``Sign of uint32``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0u |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 8) + "The type 'uint32' does not support the operator 'get_Sign'" + + [] + let ``Sign of uint64``() = + CompilerAssert.TypeCheckSingleError + """ +sign 0uL |> ignore + """ + FSharpErrorSeverity.Error + 1 + (2, 6, 2, 9) + "The type 'uint64' does not support the operator 'get_Sign'" \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index ba10f0f2618..78bf4a5e0cc 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -71,6 +71,7 @@ + diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs deleted file mode 100644 index 7a368182e02..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs +++ /dev/null @@ -1,12 +0,0 @@ -// #Regression #Libraries #Operators -// Test sign function on unsigned primitives, should get error. - -//The type 'byte' does not support the operator 'get_Sign'$ -//The type 'uint16' does not support the operator 'get_Sign'$ -//The type 'uint32' does not support the operator 'get_Sign'$ -//The type 'uint64' does not support the operator 'get_Sign'$ - -if sign 0uy <> 0 then exit 1 // byte -if sign 0us <> 0 then exit 1 // int16 -if sign 0u <> 0 then exit 1 // int32 -if sign 0uL <> 0 then exit 1 // int64 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index 669dc84e258..3ef70034bf7 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -1,6 +1,5 @@ SOURCE=Pow_Constrains.fs SCFLAGS=--warnaserror # Pow_Constrains.fs SOURCE=sign01.fs # sign01.fs - SOURCE=E_sign02.fs SCFLAGS=--test:ErrorRanges # E_sign02.fs SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs From 00594c6991be7084cd604ec3f225437d9938c686 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 21:04:06 +0200 Subject: [PATCH 07/12] Migrated sign01.fs test case --- .../Libraries/Core/Operators/SignTests.fs | 24 +++++++++++++ .../Source/Libraries/Core/Operators/env.lst | 1 - .../Source/Libraries/Core/Operators/sign01.fs | 34 ------------------- 3 files changed, 24 insertions(+), 35 deletions(-) delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs index b1bda270920..751e535d531 100644 --- a/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs @@ -9,6 +9,30 @@ open FSharp.Test.Utilities [] module ``Sign Tests`` = + [] + let ``Sign of signed types``() = + Assert.areEqual (sign 1y) 1 // byte + Assert.areEqual (sign 1s) 1 // int16 + Assert.areEqual (sign 1) 1 // int32 + Assert.areEqual (sign 1L) 1 // int64 + Assert.areEqual (sign 1.0f) 1 // float + Assert.areEqual (sign 1.0) 1 // double + Assert.areEqual (sign 1.0m) 1 // decimal + Assert.areEqual (sign 0y) 0 // byte + Assert.areEqual (sign 0s) 0 // int16 + Assert.areEqual (sign 0) 0 // int32 + Assert.areEqual (sign 0L) 0 // int64 + Assert.areEqual (sign 0.0f) 0 // float + Assert.areEqual (sign 0.0) 0 // double + Assert.areEqual (sign 0.0m) 0 // decimal + Assert.areEqual (sign -1y) -1 // byte + Assert.areEqual (sign -1s) -1 // int16 + Assert.areEqual (sign -1) -1 // int32 + Assert.areEqual (sign -1L) -1 // int64 + Assert.areEqual (sign -1.0f) -1 // float + Assert.areEqual (sign -1.0) -1 // double + Assert.areEqual (sign -1.0m) -1 // decimal + // #Regression #Libraries #Operators // Test sign function on unsigned primitives, should get error. diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index 3ef70034bf7..de95916b136 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -1,5 +1,4 @@ SOURCE=Pow_Constrains.fs SCFLAGS=--warnaserror # Pow_Constrains.fs - SOURCE=sign01.fs # sign01.fs SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs deleted file mode 100644 index f181ba4ca89..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs +++ /dev/null @@ -1,34 +0,0 @@ -// #Libraries #Operators -#light - -// Test the 'sign' library function - -// Positive sign -if sign 1y <> 1 then exit 1 // byte -if sign 1s <> 1 then exit 1 // int16 -if sign 1 <> 1 then exit 1 // int32 -if sign 1L <> 1 then exit 1 // int64 -if sign 1.0f <> 1 then exit 1 // float -if sign 1.0 <> 1 then exit 1 // double -if sign 1.0m <> 1 then exit 1 // decimal - -// Zero -if sign 0y <> 0 then exit 1 // byte -if sign 0s <> 0 then exit 1 // int16 -if sign 0 <> 0 then exit 1 // int32 -if sign 0L <> 0 then exit 1 // int64 -if sign 0.0f <> 0 then exit 1 // float -if sign 0.0 <> 0 then exit 1 // double -if sign 0.0m <> 0 then exit 1 // decimal - -// Negative sign -if sign -1y <> -1 then exit 1 // byte -if sign -1s <> -1 then exit 1 // int16 -if sign -1 <> -1 then exit 1 // int32 -if sign -1L <> -1 then exit 1 // int64 -if sign -1.0f <> -1 then exit 1 // float -if sign -1.0 <> -1 then exit 1 // double -if sign -1.0m <> -1 then exit 1 // decimal - -// All clear! -exit 0 From cc0dc60e143af47b6b79785a7dd778c71d73b57b Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 21:08:06 +0200 Subject: [PATCH 08/12] Migrated EqualityAndUncheckedHash01.fs test case --- .../Libraries/Core/Operators/HashTests.fs | 18 ++++++++++++++++-- .../Operators/EqualityAndUncheckedHash01.fs | 10 ---------- .../Source/Libraries/Core/Operators/env.lst | 1 - 3 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs index f7f89140255..8958cd5b8e9 100644 --- a/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs @@ -12,7 +12,7 @@ module ``Hash Tests`` = [] let ``Hash of function values``() = // Regression test for FSHARP1.0:5436 - // You should not be able to hash F# function values) + // You should not be able to hash F# function values // Note: most positive cases already covered under fsharp\typecheck\sigs // I'm adding this simple one since I did not see it there. @@ -23,4 +23,18 @@ hash id |> ignore FSharpErrorSeverity.Error 1 (2, 6, 2, 8) - "The type '('a -> 'a)' does not support the 'equality' constraint because it is a function type" \ No newline at end of file + "The type '('a -> 'a)' does not support the 'equality' constraint because it is a function type" + + [] + let ``Unchecked hash of function values``() = + // Regression test for FSHARP1.0:5436 + // You should not be able to hash F# function values + // Note: most positive cases already covered under fsharp\typecheck\sigs + // I'm adding this simple one since I did not see it there. + + // This is ok (unchecked) + CompilerAssert.TypeCheckWithErrors + """ +Unchecked.hash id |> ignore + """ + [||] \ No newline at end of file diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs deleted file mode 100644 index 7ae622955eb..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs +++ /dev/null @@ -1,10 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:5436 -// You should not be able to hash F# function values -// Note: most positive cases already covered under fsharp\typecheck\sigs -// I'm adding this simple one since I did not see it there. -// -module TestModule - -// This is ok (unchecked) -let p = Unchecked.hash id diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index de95916b136..0a3711c45e2 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -2,6 +2,5 @@ SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs - SOURCE=EqualityAndUncheckedHash01.fs SCFLAGS=-a # EqualityAndUncheckedHash01.fs SOURCE=StringOnEnum01.fs # StringOnEnum01.fs \ No newline at end of file From 62d9890ee61e5157dedcffb038aee0cbfe5d76f4 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 21:16:47 +0200 Subject: [PATCH 09/12] Migrated Pow_Constrains.fs test case --- .../Libraries/Core/Operators/PowTests.fs | 25 +++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Core/Operators/Pow_Constrains.fs | 16 ------------ .../Source/Libraries/Core/Operators/env.lst | 1 - 4 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs new file mode 100644 index 00000000000..4bdb77bca28 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``Pow Tests`` = + + type T() = + static let mutable m = false + static member Pow (g: T, _: float) = + m <- true + g + static member Check() = m + + [] + let ``Pow of custom type``() = + // Regression test for FSHARP1.0:4487 + // Feature request: loosen Pow operator constraints + + let t = T() + let _ = t ** 3. + + Assert.IsTrue (T.Check()) \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 78bf4a5e0cc..d7b804b6b4b 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -71,6 +71,7 @@ + diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs deleted file mode 100644 index f54171f6ccf..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs +++ /dev/null @@ -1,16 +0,0 @@ -// #Regression #Libraries #Operators -// Regression test for FSHARP1.0:4487 -// Feature request: loosen Pow operator constraints - -type T(x : float, y : float) = - static let mutable m = false - static member Pow (g: T, e: float) = m <- true - g - static member Check() = m - -let t = new T(1.,2.) - -let c = t ** 3. // OK! - -exit <| if T.Check() then 0 else 1 - diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index 0a3711c45e2..c166978edae 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -1,4 +1,3 @@ - SOURCE=Pow_Constrains.fs SCFLAGS=--warnaserror # Pow_Constrains.fs SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs From 0fb88711d0cd331cb6855ae5bea7bd17f638e5d6 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 21:22:52 +0200 Subject: [PATCH 10/12] Migrated round01.fs test case --- .../Libraries/Core/Operators/RoundTests.fs | 58 ++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Source/Libraries/Core/Operators/env.lst | 1 - .../Libraries/Core/Operators/round01.fs | 60 ------------------- 4 files changed, 59 insertions(+), 61 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs new file mode 100644 index 00000000000..bdb8e321823 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``Round Tests`` = + + [] + let ``Round of integers``() = + for i in [1 .. 10000] do + Assert.areEqual (i |> float |> round) (float i) + Assert.areEqual (i |> float32 |> round) (float32 i) + Assert.areEqual (i |> decimal |> round) (decimal i) + + [] + let ``Round of floats``() = + // Round down + Assert.areEqual (round 1.1) 1.0 + Assert.areEqual (round 1.2) 1.0 + Assert.areEqual (round 1.3) 1.0 + Assert.areEqual (round 1.4) 1.0 + Assert.areEqual (round 1.1f) 1.0f + Assert.areEqual (round 1.2f) 1.0f + Assert.areEqual (round 1.3f) 1.0f + Assert.areEqual (round 1.4f) 1.0f + Assert.areEqual (round 1.1m) 1.0m + Assert.areEqual (round 1.2m) 1.0m + Assert.areEqual (round 1.3m) 1.0m + Assert.areEqual (round 1.4m) 1.0m + + // Round down + Assert.areEqual (round 1.6) 2.0 + Assert.areEqual (round 1.7) 2.0 + Assert.areEqual (round 1.8) 2.0 + Assert.areEqual (round 1.9) 2.0 + Assert.areEqual (round 1.6f) 2.0f + Assert.areEqual (round 1.7f) 2.0f + Assert.areEqual (round 1.8f) 2.0f + Assert.areEqual (round 1.9f) 2.0f + Assert.areEqual (round 1.6m) 2.0m + Assert.areEqual (round 1.7m) 2.0m + Assert.areEqual (round 1.8m) 2.0m + Assert.areEqual (round 1.9m) 2.0m + + // Midpoint rounding. If between two numbers, round to the 'even' one. + Assert.areEqual (round 1.5 ) 2.0 + Assert.areEqual (round 1.5f) 2.0f + Assert.areEqual (round 1.5m) 2.0m + Assert.areEqual (round 2.5 ) 2.0 + Assert.areEqual (round 2.5f) 2.0f + Assert.areEqual (round 2.5m) 2.0m + + // If not midpoint, round to nearest as usual + Assert.areEqual (round 2.500001 ) 3.0 + Assert.areEqual (round 2.500001f) 3.0f + Assert.areEqual (round 2.500001m) 3.0m \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index d7b804b6b4b..8010fe6b0ef 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -72,6 +72,7 @@ + diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index c166978edae..b4b1e5468fe 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -1,4 +1,3 @@ - SOURCE=round01.fs # round01.fs SOURCE=string01.fs # string01.fs diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs deleted file mode 100644 index a9287100a85..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs +++ /dev/null @@ -1,60 +0,0 @@ -// #Libraries #Operators -#light - -// Test the round function - -// Identity -for i in [1 .. 10000] do - if i |> float |> round <> float i then exit 1 - if i |> float32 |> round <> float32 i then exit 1 - if i |> decimal |> round <> decimal i then exit 1 - -// Round down -if round 1.1 <> 1.0 then exit 1 -if round 1.2 <> 1.0 then exit 1 -if round 1.3 <> 1.0 then exit 1 -if round 1.4 <> 1.0 then exit 1 - -if round 1.1f <> 1.0f then exit 1 -if round 1.2f <> 1.0f then exit 1 -if round 1.3f <> 1.0f then exit 1 -if round 1.4f <> 1.0f then exit 1 - -if round 1.1m <> 1.0m then exit 1 -if round 1.2m <> 1.0m then exit 1 -if round 1.3m <> 1.0m then exit 1 -if round 1.4m <> 1.0m then exit 1 - -// Round down -if round 1.6 <> 2.0 then exit 1 -if round 1.7 <> 2.0 then exit 1 -if round 1.8 <> 2.0 then exit 1 -if round 1.9 <> 2.0 then exit 1 - -if round 1.6f <> 2.0f then exit 1 -if round 1.7f <> 2.0f then exit 1 -if round 1.8f <> 2.0f then exit 1 -if round 1.9f <> 2.0f then exit 1 - -if round 1.6m <> 2.0m then exit 1 -if round 1.7m <> 2.0m then exit 1 -if round 1.8m <> 2.0m then exit 1 -if round 1.9m <> 2.0m then exit 1 - -// Midpoint rounding. If between two numbers, round to the 'even' one. - -if round 1.5 <> 2.0 then exit 1 -if round 1.5f <> 2.0f then exit 1 -if round 1.5m <> 2.0m then exit 1 - -if round 2.5 <> 2.0 then exit 1 -if round 2.5f <> 2.0f then exit 1 -if round 2.5m <> 2.0m then exit 1 - -// If not midpoint, round to nearest as usual - -if round 2.500001 <> 3.0 then exit 1 -if round 2.500001f <> 3.0f then exit 1 -if round 2.500001m <> 3.0m then exit 1 - -exit 0 From 668d23308f080143e102bde480e5bf03e56c581c Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 21:35:12 +0200 Subject: [PATCH 11/12] Migrated StringOnEnum01.fs test case --- .../Libraries/Core/Operators/StringTests.fs | 86 +++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + .../Core/Operators/StringOnEnum01.fs | 68 --------------- .../Source/Libraries/Core/Operators/env.lst | 2 - 4 files changed, 87 insertions(+), 70 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs new file mode 100644 index 00000000000..55587861388 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``String Tests`` = + + // int32 + type Foo = + | A = 1 + | B = 2 + + [] + let ``String of int32 based enum``() = + let a = Foo.A + let r = a :> System.IFormattable + + Assert.areEqual (string a) (string r) + + // uint32 + type Foo2 = + | A = 3u + | B = 4u + + [] + let ``String of uint32 based enum``() = + let a = Foo2.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // char + type Foo3 = + | A = 'a' + | B = 'b' + + [] + let ``String of char based enum``() = + let a = Foo3.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // int16 + type Foo4 = + | A = 1s + | B = 2s + + [] + let ``String of int16 based enum``() = + let a = Foo4.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // uint16 + type Foo5 = + | A = 1us + | B = 2us + + [] + let ``String of uint16 based enum``() = + let a = Foo5.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // sbyte + type Foo6 = + | A = 1y + | B = 2y + + [] + let ``String of sbyte based enum``() = + let a = Foo6.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) + + // byte + type Foo7 = + | A = 1uy + | B = 2uy + + [] + let ``String of byte based enum``() = + let a = Foo7.A + let r = a :> System.IFormattable + Assert.areEqual (string a) (string r) \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 8010fe6b0ef..b06425e88dc 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -74,6 +74,7 @@ + diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs deleted file mode 100644 index 7fd2ceccddb..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs +++ /dev/null @@ -1,68 +0,0 @@ -// #Regression #Libraries #Operators -// Regression for FSHARP1.0:5995 -// Calling "string" on an enum results in the integer value rather than the ToString name (possibly other static optimization issues?) - -module M - -// int32 -type Foo = - | A = 1 - | B = 2 - -let a = Foo.A -let r = a :> System.IFormattable -if (string a) <> (string r) then exit 1 - -// uint32 -type Foo2 = - | A = 3u - | B = 4u - -let a2 = Foo2.A -let r2 = a :> System.IFormattable -if (string a2) <> (string r2) then exit 1 - -// char : see FSHARP1.0:6228 -//type Foo3 = -// | A = 'a' -// | B = 'b' - -//let a3 = Foo3.A -//let r3 = a :> System.IFormattable -//if (string a3) <> (string r3) then exit 1 - -// int16 -type Foo4 = - | A = 1s - | B = 2s - -let a4 = Foo4.A -let r4 = a :> System.IFormattable -if (string a4) <> (string r4) then exit 1 - -// uint16 -type Foo5 = - | A = 1us - | B = 2us - -let a5 = Foo5.A -let r5 = a :> System.IFormattable -if (string a5) <> (string r5) then exit 1 - -// sbyte -type Foo6 = - | A = 1y - | B = 2y - -let a6 = Foo6.A -let r6 = a :> System.IFormattable -if (string a6) <> (string r6) then exit 1 - -// byte -type Foo7 = - | A = 1uy - | B = 2uy - -let a7 = Foo7.A -let r7 = a :> System.IFormattable -if (string a7) <> (string r7) then exit 1 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst index b4b1e5468fe..7034184550f 100644 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst @@ -1,4 +1,2 @@ SOURCE=string01.fs # string01.fs - - SOURCE=StringOnEnum01.fs # StringOnEnum01.fs \ No newline at end of file From 32cceb4ba47954562467867616b3f605a3948751 Mon Sep 17 00:00:00 2001 From: "Thorsten (Gerbrunn)" Date: Thu, 25 Jun 2020 21:44:57 +0200 Subject: [PATCH 12/12] Migrated string01.fs test case --- .../Libraries/Core/Operators/StringTests.fs | 29 ++++++++++++ .../Source/Libraries/Core/Operators/env.lst | 2 - .../Libraries/Core/Operators/string01.fs | 44 ------------------- 3 files changed, 29 insertions(+), 46 deletions(-) delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/env.lst delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/string01.fs diff --git a/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs index 55587861388..dbb691fb35b 100644 --- a/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs @@ -3,10 +3,39 @@ namespace FSharp.Compiler.UnitTests open NUnit.Framework +open System [] module ``String Tests`` = + type CalcSum(x : int, y: int) = + let mutable x = x + let mutable y = y + + member __.Sum () = x + y + + interface IFormattable with + member x.ToString (format: string, _ : IFormatProvider) = + match format with + | null | "" + | "g" | "G" -> String.Format("X + Y = {0}", x.Sum()) + | "s" | "S" -> x.Sum().ToString() // Short form + | _ -> invalidArg format "Format is wrong!" + + override x.ToString() = (x :> IFormattable).ToString(null, null) + + [] + let ``String of custom type``() = + let calc = CalcSum(10, 20) + Assert.areEqual (string calc) "X + Y = 30" + + let testDelegate = TestDelegate (fun () -> + printfn "%s" (calc.ToString()) + Console.WriteLine("{0:S}", calc) + Console.Write("{0} {1} {2:D}", 10, 20, calc)) + let e = Assert.Throws testDelegate + Assert.areEqual e.ParamName "D" + // int32 type Foo = | A = 1 diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst b/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst deleted file mode 100644 index 7034184550f..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ /dev/null @@ -1,2 +0,0 @@ - SOURCE=string01.fs # string01.fs - diff --git a/tests/fsharpqa/Source/Libraries/Core/Operators/string01.fs b/tests/fsharpqa/Source/Libraries/Core/Operators/string01.fs deleted file mode 100644 index 881cd5c28a2..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/string01.fs +++ /dev/null @@ -1,44 +0,0 @@ -// #Regression #Libraries #Operators -open System - -// Regression test for FSHARP1.0:3977 - Make "string" function work for decimal and user-defined IFormattable types. - -type CalcSum(x : int, y: int) = - let mutable x = x - let mutable y = y - - member this.Sum () = x + y - - interface IFormattable with - member x.ToString (format: string, provider : IFormatProvider) = - match format with - | null | "" - | "g" | "G" -> - String.Format("X + Y = {0}", x.Sum()) - | "s" | "S" -> - // Short form - x.Sum().ToString() - | _ -> - invalidArg format "Format is wrong!" - - override x.ToString() = (x :> IFormattable).ToString(null, null) - -let calc = CalcSum(10, 20) - -// test string function -match string calc with -| "X + Y = 30" -> () -| _ -> exit 1 - -// test with Console.WriteLine -try - printfn "%s" (calc.ToString()) - Console.WriteLine("{0:S}", calc) - Console.Write("{0} {1} {2:D}", 10, 20, calc) -with - | :? ArgumentException as e -> - match e.ParamName with - | "D" -> exit 0 - | _ -> exit 2 - -exit 1