From 70f3758eee33fe34bc69874ff9d569bb95a9b13c Mon Sep 17 00:00:00 2001 From: Thorsten Reichert Date: Fri, 26 Jun 2020 15:55:51 +0200 Subject: [PATCH] Moved fsharpqa/Libraries/Core/Operators test cases to NUnit (#9570) --- .../Libraries/Core/Operators/AbsTests.fs | 94 ++++++++++++++ .../Libraries/Core/Operators/CastTests.fs | 19 +++ .../Libraries/Core/Operators/HashTests.fs | 40 ++++++ .../Libraries/Core/Operators/PowTests.fs | 25 ++++ .../Libraries/Core/Operators/RoundTests.fs | 58 +++++++++ .../Libraries/Core/Operators/SignTests.fs | 81 ++++++++++++ .../Libraries/Core/Operators/StringTests.fs | 115 ++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 7 ++ .../Core/Operators/AbsOnIntegers01.fs | 15 --- .../Libraries/Core/Operators/CastOperator.fs | 11 -- .../Core/Operators/E_EqualityAndHash01.fs | 8 -- .../Libraries/Core/Operators/E_sign02.fs | 12 -- .../Operators/EqualityAndUncheckedHash01.fs | 10 -- .../Core/Operators/Pow_Constrains.fs | 16 --- .../Core/Operators/StringOnEnum01.fs | 68 ----------- .../Core/Operators/e_AbsOnIntegers02.fs | 17 --- .../Source/Libraries/Core/Operators/env.lst | 13 -- .../Libraries/Core/Operators/round01.fs | 60 --------- .../Source/Libraries/Core/Operators/sign01.fs | 34 ------ .../Libraries/Core/Operators/string01.fs | 44 ------- 20 files changed, 439 insertions(+), 308 deletions(-) create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/CastTests.fs create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/PowTests.fs create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/RoundTests.fs create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs create mode 100644 tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/AbsOnIntegers01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/CastOperator.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/E_EqualityAndHash01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/E_sign02.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/EqualityAndUncheckedHash01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/Pow_Constrains.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/StringOnEnum01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/e_AbsOnIntegers02.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/env.lst delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/round01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/sign01.fs delete mode 100644 tests/fsharpqa/Source/Libraries/Core/Operators/string01.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..806c93b7dba --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/AbsTests.fs @@ -0,0 +1,94 @@ +// 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 ``Abs Tests`` = + + [] + 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 + 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 + + [] + 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/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/Compiler/Libraries/Core/Operators/HashTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs new file mode 100644 index 00000000000..8958cd5b8e9 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/HashTests.fs @@ -0,0 +1,40 @@ +// 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" + + [] + 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/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/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/Compiler/Libraries/Core/Operators/SignTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs new file mode 100644 index 00000000000..751e535d531 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/SignTests.fs @@ -0,0 +1,81 @@ +// 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`` = + + [] + 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. + + [] + 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/Compiler/Libraries/Core/Operators/StringTests.fs b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs new file mode 100644 index 00000000000..dbb691fb35b --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Operators/StringTests.fs @@ -0,0 +1,115 @@ +// 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 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 + | 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 374a27b68cb..b06425e88dc 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -68,6 +68,13 @@ + + + + + + + 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/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/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/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/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/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/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/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 deleted file mode 100644 index 3b893973508..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Operators/env.lst +++ /dev/null @@ -1,13 +0,0 @@ - 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 - 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 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 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 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