diff --git a/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/CastToUnitsTests.fs b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/CastToUnitsTests.fs new file mode 100644 index 00000000000..d53f23d6ab0 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/CastToUnitsTests.fs @@ -0,0 +1,29 @@ +// 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.TestHelpers + +[] +module ``Cast to Units Tests`` = + + [] + let ``Casting to Measures should compile``() = + CompilerAssert.Pass + """ +module M + +open Microsoft.FSharp.Core.LanguagePrimitives + +[] +type M + +let r1 = SByteWithMeasure 1y + 2y +let r2 = Int16WithMeasure 2s - 2s +let r3 = Int32WithMeasure 3 * 3 +let r4 = Int64WithMeasure 5L / 5L +let r5 = FloatWithMeasure 11.11 + 1.1 +let r6 = Float32WithMeasure 22.22f - 11.11f +let r7 = DecimalWithMeasure 33.33M * 44.44M + """ \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/ComparisonTests.fs b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/ComparisonTests.fs new file mode 100644 index 00000000000..c4547842f40 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/ComparisonTests.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 + +[] +module ``Comparison Tests`` = + + type 'a www = W of 'a + + [] + let ``Comparisons with wrapped NaN``() = + // Regression test for FSHARP1.0:5640 + // This is a sanity test: more coverage in FSHARP suite... + + Assert.IsFalse (W System.Double.NaN = W System.Double.NaN) + Assert.IsTrue ((W System.Double.NaN).Equals(W System.Double.NaN)) + Assert.areEqual (compare (W System.Double.NaN) (W System.Double.NaN)) 0 \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/StringFormatTests.fs b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/StringFormatTests.fs new file mode 100644 index 00000000000..c2ad00ab3fb --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/StringFormatTests.fs @@ -0,0 +1,139 @@ +// 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 Format Tests`` = + + [] + let ``sprintf with %d format specifier``() = + // Regression test for FSHARP1.0:4120 + // format specifier %d does not work correctly with UInt64 values + + Assert.areEqual (sprintf "%d" System.UInt64.MaxValue) "18446744073709551615" + Assert.areEqual (sprintf "%d" System.UInt64.MinValue) "0" + Assert.areEqual (sprintf "%d" System.UInt32.MaxValue) "4294967295" + Assert.areEqual (sprintf "%d" System.UInt32.MinValue) "0" + Assert.areEqual (sprintf "%d" System.UInt16.MaxValue) "65535" + Assert.areEqual (sprintf "%d" System.UInt16.MinValue) "0" + Assert.areEqual (sprintf "%d" System.Byte.MaxValue) "255" + Assert.areEqual (sprintf "%d" System.Byte.MinValue) "0" + Assert.areEqual (sprintf "%d" System.Int64.MaxValue) "9223372036854775807" + Assert.areEqual (sprintf "%d" System.Int64.MinValue) "-9223372036854775808" + Assert.areEqual (sprintf "%d" System.Int32.MaxValue) "2147483647" + Assert.areEqual (sprintf "%d" System.Int32.MinValue) "-2147483648" + Assert.areEqual (sprintf "%d" System.Int16.MaxValue) "32767" + Assert.areEqual (sprintf "%d" System.Int16.MinValue) "-32768" + Assert.areEqual (sprintf "%d" System.SByte.MaxValue) "127" + Assert.areEqual (sprintf "%d" System.SByte.MinValue) "-128" + Assert.areEqual (sprintf "%d" 1un) "1" + Assert.areEqual (sprintf "%d" -1n) "-1" + + [] + let ``sprintf with %i format specifier``() = + // Regression test for FSHARP1.0:4120 + // format specifier %i does not work correctly with UInt64 values + + Assert.areEqual (sprintf "%i" System.UInt64.MaxValue) "18446744073709551615" + Assert.areEqual (sprintf "%i" System.UInt64.MinValue) "0" + Assert.areEqual (sprintf "%i" System.UInt32.MaxValue) "4294967295" + Assert.areEqual (sprintf "%i" System.UInt32.MinValue) "0" + Assert.areEqual (sprintf "%i" System.UInt16.MaxValue) "65535" + Assert.areEqual (sprintf "%i" System.UInt16.MinValue) "0" + Assert.areEqual (sprintf "%i" System.Byte.MaxValue) "255" + Assert.areEqual (sprintf "%i" System.Byte.MinValue) "0" + Assert.areEqual (sprintf "%i" System.Int64.MaxValue) "9223372036854775807" + Assert.areEqual (sprintf "%i" System.Int64.MinValue) "-9223372036854775808" + Assert.areEqual (sprintf "%i" System.Int32.MaxValue) "2147483647" + Assert.areEqual (sprintf "%i" System.Int32.MinValue) "-2147483648" + Assert.areEqual (sprintf "%i" System.Int16.MaxValue) "32767" + Assert.areEqual (sprintf "%i" System.Int16.MinValue) "-32768" + Assert.areEqual (sprintf "%i" System.SByte.MaxValue) "127" + Assert.areEqual (sprintf "%i" System.SByte.MinValue) "-128" + Assert.areEqual (sprintf "%i" 1un) "1" + Assert.areEqual (sprintf "%i" -1n) "-1" + + [] + let ``sprintf with %u format specifier``() = + // Regression test for FSHARP1.0:4120 + // format specifier %u does not work correctly with UInt64 values + + Assert.areEqual (sprintf "%u" System.UInt64.MaxValue) "18446744073709551615" + Assert.areEqual (sprintf "%u" System.UInt64.MinValue) "0" + Assert.areEqual (sprintf "%u" System.UInt32.MaxValue) "4294967295" + Assert.areEqual (sprintf "%u" System.UInt32.MinValue) "0" + Assert.areEqual (sprintf "%u" System.UInt16.MaxValue) "65535" + Assert.areEqual (sprintf "%u" System.UInt16.MinValue) "0" + Assert.areEqual (sprintf "%u" System.Byte.MaxValue) "255" + Assert.areEqual (sprintf "%u" System.Byte.MinValue) "0" + Assert.areEqual (sprintf "%u" System.Int64.MaxValue) "9223372036854775807" + Assert.areEqual (sprintf "%u" System.Int64.MinValue) "9223372036854775808" + Assert.areEqual (sprintf "%u" System.Int32.MaxValue) "2147483647" + Assert.areEqual (sprintf "%u" System.Int32.MinValue) "2147483648" + Assert.areEqual (sprintf "%u" System.Int16.MaxValue) "32767" + Assert.areEqual (sprintf "%u" System.Int16.MinValue) "32768" + Assert.areEqual (sprintf "%u" System.SByte.MaxValue) "127" + Assert.areEqual (sprintf "%u" System.SByte.MinValue) "128" + Assert.areEqual (sprintf "%u" 1un) "1" + Assert.areEqual (sprintf "%u" -1n) (if System.IntPtr.Size = 4 then "4294967295" else "18446744073709551615") + + [] + let ``string constructor``() = + // Regression test for FSHARP1.0:5894 + + Assert.areEqual (string 1.0f) "1" + Assert.areEqual (string 1.00001f) "1.00001" + Assert.areEqual (string -1.00001f) "-1.00001" + Assert.areEqual (string 1.0) "1" + Assert.areEqual (string 1.00001) "1.00001" + Assert.areEqual (string -1.00001) "-1.00001" + Assert.areEqual (string System.SByte.MaxValue) "127" + Assert.areEqual (string System.SByte.MinValue) "-128" + Assert.areEqual (string 0y) "0" + Assert.areEqual (string -1y) "-1" + Assert.areEqual (string 1y) "1" + Assert.areEqual (string System.Byte.MaxValue) "255" + Assert.areEqual (string System.Byte.MinValue) "0" + Assert.areEqual (string 0uy) "0" + Assert.areEqual (string 1uy) "1" + Assert.areEqual (string System.Int16.MaxValue) "32767" + Assert.areEqual (string System.Int16.MinValue) "-32768" + Assert.areEqual (string 0s) "0" + Assert.areEqual (string -10s) "-10" + Assert.areEqual (string 10s) "10" + Assert.areEqual (string System.UInt16.MaxValue) "65535" + Assert.areEqual (string System.UInt16.MinValue) "0" + Assert.areEqual (string 0us) "0" + Assert.areEqual (string 110us) "110" + Assert.areEqual (string System.Int32.MaxValue) "2147483647" + Assert.areEqual (string System.Int32.MinValue) "-2147483648" + Assert.areEqual (string 0) "0" + Assert.areEqual (string -10) "-10" + Assert.areEqual (string 10) "10" + Assert.areEqual (string System.UInt32.MaxValue) "4294967295" + Assert.areEqual (string System.UInt32.MinValue) "0" + Assert.areEqual (string 0u) "0" + Assert.areEqual (string 10u) "10" + Assert.areEqual (string System.Int64.MaxValue) "9223372036854775807" + Assert.areEqual (string System.Int64.MinValue) "-9223372036854775808" + Assert.areEqual (string 0L) "0" + Assert.areEqual (string -10L) "-10" + Assert.areEqual (string 10L) "10" + Assert.areEqual (string System.UInt64.MaxValue) "18446744073709551615" + Assert.areEqual (string System.UInt64.MinValue) "0" + Assert.areEqual (string 0UL) "0" + Assert.areEqual (string 10UL) "10" + Assert.areEqual (string System.Decimal.MaxValue) "79228162514264337593543950335" + Assert.areEqual (string System.Decimal.MinValue) "-79228162514264337593543950335" + Assert.areEqual (string System.Decimal.Zero) "0" + Assert.areEqual (string 12345678M) "12345678" + Assert.areEqual (string -12345678M) "-12345678" + Assert.areEqual (string -infinity) "-Infinity" + Assert.areEqual (string infinity) "Infinity" + Assert.areEqual (string nan) "NaN" + Assert.areEqual (string -infinityf) "-Infinity" + Assert.areEqual (string infinityf) "Infinity" + Assert.areEqual (string nanf) "NaN" + Assert.areEqual (string (new System.Guid("210f4d6b-cb42-4b09-baa1-f1aa8e59d4b0"))) "210f4d6b-cb42-4b09-baa1-f1aa8e59d4b0" diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 0c84007859f..46cab3c2a27 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -75,6 +75,9 @@ + + + diff --git a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/CastToUnits01.fs b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/CastToUnits01.fs deleted file mode 100644 index 571c788c397..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/CastToUnits01.fs +++ /dev/null @@ -1,20 +0,0 @@ -// #Regression #Libraries #LanguagePrimitives -// Regression for FSHARP1.0:5794 -// New functions to cast dimensionless value to unitful value - -module M - -open Microsoft.FSharp.Core.LanguagePrimitives - -[] -type M - -let r1 = SByteWithMeasure 1y + 2y -let r2 = Int16WithMeasure 2s - 2s -let r3 = Int32WithMeasure 3 * 3 -let r4 = Int64WithMeasure 5L / 5L -let r5 = FloatWithMeasure 11.11 + 1.1 -let r6 = Float32WithMeasure 22.22f - 11.11f -let r7 = DecimalWithMeasure 33.33M * 44.44M - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_d_01.fs b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_d_01.fs deleted file mode 100644 index 17ae0d72847..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_d_01.fs +++ /dev/null @@ -1,32 +0,0 @@ -// #Regression #Libraries #LanguagePrimitives -// Regression test for FSHARP1.0:4120 -// format specifier %d does not work correctly with UInt64 values - -// -// This test covers the usage of %d -// All kinds of valid input are provided -// - -let test = [ ((sprintf "%d" System.UInt64.MaxValue), "18446744073709551615"); - ((sprintf "%d" System.UInt64.MinValue), "0"); - ((sprintf "%d" System.UInt32.MaxValue), "4294967295"); - ((sprintf "%d" System.UInt32.MinValue), "0"); - ((sprintf "%d" System.UInt16.MaxValue), "65535"); - ((sprintf "%d" System.UInt16.MinValue), "0"); - ((sprintf "%d" System.Byte.MaxValue), "255"); - ((sprintf "%d" System.Byte.MinValue), "0"); - ((sprintf "%d" System.Int64.MaxValue), "9223372036854775807"); - ((sprintf "%d" System.Int64.MinValue), "-9223372036854775808"); - ((sprintf "%d" System.Int32.MaxValue), "2147483647"); - ((sprintf "%d" System.Int32.MinValue), "-2147483648"); - ((sprintf "%d" System.Int16.MaxValue), "32767"); - ((sprintf "%d" System.Int16.MinValue), "-32768"); - ((sprintf "%d" System.SByte.MaxValue), "127"); - ((sprintf "%d" System.SByte.MinValue), "-128"); - ((sprintf "%d" 1un), "1"); - ((sprintf "%d" -1n), "-1"); - ] - -let res = List.forall (fun x -> (fst x) = (snd x)) test - -(if res then 0 else 1) |> exit diff --git a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_i_01.fs b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_i_01.fs deleted file mode 100644 index e5fa47c4143..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_i_01.fs +++ /dev/null @@ -1,32 +0,0 @@ -// #Regression #Libraries #LanguagePrimitives -// Regression test for FSHARP1.0:4120 -// format specifier %i does not work correctly with UInt64 values - -// -// This test covers the usage of %i -// All kinds of valid input are provided -// - -let test = [ ((sprintf "%i" System.UInt64.MaxValue), "18446744073709551615"); - ((sprintf "%i" System.UInt64.MinValue), "0"); - ((sprintf "%i" System.UInt32.MaxValue), "4294967295"); - ((sprintf "%i" System.UInt32.MinValue), "0"); - ((sprintf "%i" System.UInt16.MaxValue), "65535"); - ((sprintf "%i" System.UInt16.MinValue), "0"); - ((sprintf "%i" System.Byte.MaxValue), "255"); - ((sprintf "%i" System.Byte.MinValue), "0"); - ((sprintf "%i" System.Int64.MaxValue), "9223372036854775807"); - ((sprintf "%i" System.Int64.MinValue), "-9223372036854775808"); - ((sprintf "%i" System.Int32.MaxValue), "2147483647"); - ((sprintf "%i" System.Int32.MinValue), "-2147483648"); - ((sprintf "%i" System.Int16.MaxValue), "32767"); - ((sprintf "%i" System.Int16.MinValue), "-32768"); - ((sprintf "%i" System.SByte.MaxValue), "127"); - ((sprintf "%i" System.SByte.MinValue), "-128"); - ((sprintf "%i" 1un), "1"); - ((sprintf "%i" -1n), "-1"); - ] - -let res = List.forall (fun x -> (fst x) = (snd x)) test - -(if res then 0 else 1) |> exit diff --git a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_u_01.fs b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_u_01.fs deleted file mode 100644 index 240b9ef9a08..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/FormatSpec_u_01.fs +++ /dev/null @@ -1,32 +0,0 @@ -// #Regression #Libraries #LanguagePrimitives -// Regression test for FSHARP1.0:4120 -// format specifier %u does not work correctly with UInt64 values - -// -// This test covers the usage of %u -// All kinds of valid input are provided -// - -let test = [ ((sprintf "%u" System.UInt64.MaxValue), "18446744073709551615"); - ((sprintf "%u" System.UInt64.MinValue), "0"); - ((sprintf "%u" System.UInt32.MaxValue), "4294967295"); - ((sprintf "%u" System.UInt32.MinValue), "0"); - ((sprintf "%u" System.UInt16.MaxValue), "65535"); - ((sprintf "%u" System.UInt16.MinValue), "0"); - ((sprintf "%u" System.Byte.MaxValue), "255"); - ((sprintf "%u" System.Byte.MinValue), "0"); - ((sprintf "%u" System.Int64.MaxValue), "9223372036854775807"); - ((sprintf "%u" System.Int64.MinValue), "9223372036854775808"); - ((sprintf "%u" System.Int32.MaxValue), "2147483647"); - ((sprintf "%u" System.Int32.MinValue), "2147483648"); - ((sprintf "%u" System.Int16.MaxValue), "32767"); - ((sprintf "%u" System.Int16.MinValue), "32768"); - ((sprintf "%u" System.SByte.MaxValue), "127"); - ((sprintf "%u" System.SByte.MinValue), "128"); - ((sprintf "%u" 1un), "1"); - ((sprintf "%u" -1n), if System.IntPtr.Size = 4 then "4294967295" else "18446744073709551615"); - ] - -let res = List.forall (fun x -> (fst x) = (snd x)) test - -(if res then 0 else 1) |> exit diff --git a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/anytostring01.fs b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/anytostring01.fs deleted file mode 100644 index 59ff2ee3409..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/anytostring01.fs +++ /dev/null @@ -1,87 +0,0 @@ -// #Regression #Libraries #LanguagePrimitives #ReqNOMT -// Regression test for FSHARP1.0:5894 -// - -let v = [ - (string 1.0f); - (string 1.00001f); - (string -1.00001f); - - (string 1.0); - (string 1.00001); - (string -1.00001); - - (string System.SByte.MaxValue); - (string System.SByte.MinValue); - (string 0y); - (string -1y); - (string 1y); - - (string System.Byte.MaxValue); - (string System.Byte.MinValue); - (string 0uy); - (string 1uy); - - (string System.Int16.MaxValue); - (string System.Int16.MinValue); - (string 0s); - (string -10s); - (string 10s); - - (string System.UInt16.MaxValue); - (string System.UInt16.MinValue); - (string 0us); - (string 110us); - - (string System.Int32.MaxValue); - (string System.Int32.MinValue); - (string 0); - (string -10); - (string 10); - - (string System.UInt32.MaxValue); - (string System.UInt32.MinValue); - (string 0u); - (string 10u); - - (string System.Int64.MaxValue); - (string System.Int64.MinValue); - (string 0L); - (string -10L); - (string 10L); - - (string System.UInt64.MaxValue); - (string System.UInt64.MinValue); - (string 0UL); - (string 10UL); - - (string System.Decimal.MaxValue); - (string System.Decimal.MinValue); - (string System.Decimal.Zero); - (string 12345678M); - (string -12345678M); - - (string -infinity); - (string infinity); - (string nan); - - (string -infinityf); - (string infinityf); - (string nanf); - - (string (new System.Guid("210f4d6b-cb42-4b09-baa1-f1aa8e59d4b0"))) - - ] - -let expected = ["1"; "1.00001"; "-1.00001"; "1"; "1.00001"; "-1.00001"; "127"; "-128"; "0"; - "-1"; "1"; "255"; "0"; "0"; "1"; "32767"; "-32768"; "0"; "-10"; "10"; - "65535"; "0"; "0"; "110"; "2147483647"; "-2147483648"; "0"; "-10"; "10"; - "4294967295"; "0"; "0"; "10"; "9223372036854775807"; "-9223372036854775808"; - "0"; "-10"; "10"; "18446744073709551615"; "0"; "0"; "10"; - "79228162514264337593543950335"; "-79228162514264337593543950335"; "0"; - "12345678"; "-12345678"; "-Infinity"; "Infinity"; "NaN"; "-Infinity"; - "Infinity"; "NaN"; - "210f4d6b-cb42-4b09-baa1-f1aa8e59d4b0"] - -exit <| if v = expected then 0 else 1 - diff --git a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/compare01.fs b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/compare01.fs deleted file mode 100644 index 4ff6d56b57c..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/compare01.fs +++ /dev/null @@ -1,11 +0,0 @@ -// #Regression #Libraries #LanguagePrimitives #ReqNOMT -// Regression test for FSHARP1.0:5640 -// This is a sanity test: more coverage in FSHARP suite... -// - -type 'a www = W of 'a -let p = W System.Double.NaN = W System.Double.NaN // false (PER semantic) -let q = (W System.Double.NaN).Equals(W System.Double.NaN) // true (ER semantic) -let z = compare (W System.Double.NaN) (W System.Double.NaN) // 0 - -(if (not p) && q && (z=0) then 0 else 1) |> exit diff --git a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/env.lst b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/env.lst index 16d6bcc4799..7e5badf8903 100644 --- a/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/env.lst +++ b/tests/fsharpqa/Source/Libraries/Core/LanguagePrimitives/env.lst @@ -1,9 +1,2 @@ - SOURCE=anytostring01.fs # anytostring01.fs NoMT SOURCE=anytostring01.fsx FSIMODE=PIPE COMPILE_ONLY=1 # anytostring01.fsx - - SOURCE=compare01.fs # compare01.fs NoMT SOURCE=compare01.fsx FSIMODE=PIPE COMPILE_ONLY=1 # compare01.fsx - - SOURCE=FormatSpec_d_01.fs # FormatSpec_d_01.fs - SOURCE=FormatSpec_i_01.fs # FormatSpec_i_01.fs - SOURCE=FormatSpec_u_01.fs # FormatSpec_u_01.fs