diff --git a/tests/fsharp/Compiler/Libraries/Core/Collections/CollectionTests.fs b/tests/fsharp/Compiler/Libraries/Core/Collections/CollectionTests.fs new file mode 100644 index 00000000000..934936fd0c3 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Collections/CollectionTests.fs @@ -0,0 +1,28 @@ +// 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 ``Array2D Tests`` = + + [] + let ``Iter should not throw on non-zero based 2D arrays``() = + // Regression for FSHARP1.0: 5919 + // bug in array2D functions would cause iter to blow up + + let a = Array2D.createBased 1 5 10 10 0.0 + let testDelegate = TestDelegate (fun _ -> a |> Array2D.iter (printf "%f")) + + Assert.DoesNotThrow testDelegate + + [] + let ``Iteri should not throw on non-zero based 2D arrays``() = + // Regression for FSHARP1.0: 5919 + // bug in array2D functions would cause iteri to blow up + + let a = Array2D.createBased 1 5 10 10 0.0 + let testDelegate = TestDelegate (fun _ -> a |> Array2D.iteri (fun _ _ x -> printf "%f" x)) + + Assert.DoesNotThrow testDelegate \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Collections/IEnumerableTests.fs b/tests/fsharp/Compiler/Libraries/Core/Collections/IEnumerableTests.fs new file mode 100644 index 00000000000..a2e994bbae1 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Collections/IEnumerableTests.fs @@ -0,0 +1,43 @@ +// 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 ``IEnumerable Tests`` = + + // Regression test for FSHARP1.0:4726 + // Makes sure that the .Dispose() method, if available, in invoked on IEnumerable + + let mutable dispose_called_in_E = 0 // we expect this to be incremented 3 times + let mutable dispose_called_in_C = 0 // we expect this to be incremented once (=this is what the bug was about, i.e. .Dispose() was never invoked) + + type E(_c:int) = class + interface System.IDisposable with + member __.Dispose () = dispose_called_in_E <- dispose_called_in_E + 1 + end + + type C() = class + let mutable i = 0 + interface System.Collections.IEnumerator with + member __.Current with get () = new E(i) :> obj + member __.MoveNext () = + i <- i+1 + i<4 + member __.Reset () = i <- 0 + interface System.Collections.IEnumerable with + member x.GetEnumerator () = x :> System.Collections.IEnumerator + + interface System.IDisposable with + member __.Dispose () = dispose_called_in_C <- dispose_called_in_C + 1 + end + end + + [] + let ``Dispose``() = + let _ = Seq.cast (new C()) |> Seq.map (fun x -> use o = x; + o) |> Seq.length + + Assert.areEqual 3 dispose_called_in_E + Assert.areEqual 1 dispose_called_in_C \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Collections/ListTests.fs b/tests/fsharp/Compiler/Libraries/Core/Collections/ListTests.fs new file mode 100644 index 00000000000..324a0661883 --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Collections/ListTests.fs @@ -0,0 +1,59 @@ +// 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 + +[] +module ``List Tests`` = + + [] + let ``List hd should not exist``() = + // Regression test for FSharp1.0:5641 + // Title: List.hd/tl --> List.head/tail + + CompilerAssert.TypeCheckSingleError + """ +List.hd [1] |> ignore + """ + FSharpErrorSeverity.Error + 39 + (2, 6, 2, 8) + "The value, constructor, namespace or type 'hd' is not defined." + + + + [] + let ``List tl should not exist``() = + // Regression test for FSharp1.0:5641 + // Title: List.hd/tl --> List.head/tail + + CompilerAssert.TypeCheckSingleError + """ +List.tl [1] |> ignore + """ + FSharpErrorSeverity.Error + 39 + (2, 6, 2, 8) + "The value, constructor, namespace or type 'tl' is not defined." + + [] + let ``List head of empty list``() = + let testDelegate = TestDelegate (fun _ -> (List.head [] |> ignore)) + + Assert.Throws testDelegate |> ignore + + [] + let ``List tail of empty list``() = + let testDelegate = TestDelegate (fun _ -> (List.tail [] |> ignore)) + + Assert.Throws testDelegate |> ignore + + [] + let ``List head and tail``() = + Assert.areEqual 1 (List.head [1 .. 10]) + Assert.areEqual "a" (List.head ["a"]) + Assert.areEqual [2 .. 10] (List.tail [1 .. 10]) + Assert.areEqual [] (List.tail [1]) + Assert.areEqual (List.head (List.tail ['a'; 'a'])) (List.head ['a'; 'a']) \ No newline at end of file diff --git a/tests/fsharp/Compiler/Libraries/Core/Collections/MapTests.fs b/tests/fsharp/Compiler/Libraries/Core/Collections/MapTests.fs new file mode 100644 index 00000000000..a0418bb000b --- /dev/null +++ b/tests/fsharp/Compiler/Libraries/Core/Collections/MapTests.fs @@ -0,0 +1,17 @@ +// 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 ``Map Tests`` = + + [] + let ``Equality should be implemented on map``() = + // Dev11:19569 - this used to throw an ArgumentException saying Object didn't implement IComparable + + let m = Map.ofArray [| 1, obj() |] + let testDelegate = TestDelegate (fun _ -> (m = m) |> ignore) + + Assert.DoesNotThrow testDelegate \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 97980a0ad7b..80517837708 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -78,6 +78,10 @@ + + + + diff --git a/tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter01.fs b/tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter01.fs deleted file mode 100644 index d230135a676..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter01.fs +++ /dev/null @@ -1,10 +0,0 @@ -// #Regression #Libraries #Collections -// Regression for FSHARP1.0: 5919 -// bug in array2D functions would cause iter to blow up - -module M - -let a = Array2D.createBased 1 5 10 10 0.0 -a |> Array2D.iter (printf "%f") - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter02.fs b/tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter02.fs deleted file mode 100644 index 95de7ed0009..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter02.fs +++ /dev/null @@ -1,10 +0,0 @@ -// #Regression #Libraries #Collections -// Regression for FSHARP1.0: 5919 -// bug in array2D functions would cause iteri to blow up - -module M - -let a = Array2D.createBased 1 5 10 10 0.0 -a |> Array2D.iteri (fun i j x -> printf "%f" x) - -exit 0 diff --git a/tests/fsharpqa/Source/Libraries/Core/Collections/EqualityOnMap01.fs b/tests/fsharpqa/Source/Libraries/Core/Collections/EqualityOnMap01.fs deleted file mode 100644 index 2b665710186..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Collections/EqualityOnMap01.fs +++ /dev/null @@ -1,5 +0,0 @@ -// #Regression #Libraries #Collections -// Dev11:19569 - this used to throw an ArgumentException saying Object didn't implement IComparable - -let m = Map.ofArray [| 1, obj() |] -exit <| if (m = m) then 0 else 1 diff --git a/tests/fsharpqa/Source/Libraries/Core/Collections/Seq_Cast_Dispose01.fs b/tests/fsharpqa/Source/Libraries/Core/Collections/Seq_Cast_Dispose01.fs deleted file mode 100644 index 9ad88b379ad..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Collections/Seq_Cast_Dispose01.fs +++ /dev/null @@ -1,38 +0,0 @@ -// #Regression #Libraries #Collections -// -// Regression test for FSHARP1.0:4726 -// Makes sure that the .Dispose() method, if available, in invoked on IEnumerable -// -// This test should probably go under the SystematicUnitTests suite, but -// I could not decide how to make it fit... so I'm leaving it here. -// -// - -let mutable dispose_called_in_E = 0 // we expect this to be incremented 3 times -let mutable dispose_called_in_C = 0 // we expect this to be incremented once (=this is what the bug was about, i.e. .Dispose() was never invoked) - -type E(c:int) = class - interface System.IDisposable with - member x.Dispose () = dispose_called_in_E <- dispose_called_in_E + 1 - end - -type C() = class - let mutable i = 0 - interface System.Collections.IEnumerator with - member x.Current with get () = new E(i) :> obj - member x.MoveNext () = i <- i+1 - i<4 - member x.Reset () = i <- 0 - interface System.Collections.IEnumerable with - member x.GetEnumerator () = x :> System.Collections.IEnumerator - - interface System.IDisposable with - member x.Dispose () = dispose_called_in_C <- dispose_called_in_C + 1 - end - - end - -let _ = Seq.cast (new C()) |> Seq.map (fun x -> use o = x; - o) |> Seq.length - -(if (dispose_called_in_E<>3 && dispose_called_in_C<>1) then 1 else 0) |> exit diff --git a/tests/fsharpqa/Source/Libraries/Core/Collections/env.lst b/tests/fsharpqa/Source/Libraries/Core/Collections/env.lst deleted file mode 100644 index 11b81762be6..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Collections/env.lst +++ /dev/null @@ -1,5 +0,0 @@ - SOURCE=seq_cast_dispose01.fs # seq_cast_dispose01.fs - SOURCE=list_head_tail01.fs SCFLAGS="--test:ErrorRanges" # list_head_tail01.fs - SOURCE=Array2DIter01.fs # Array2DIter01.fs - SOURCE=Array2DIter02.fs # Array2DIter02.fs - SOURCE=EqualityOnMap01.fs # EqualityOnMap01.fs \ No newline at end of file diff --git a/tests/fsharpqa/Source/Libraries/Core/Collections/list_head_tail01.fs b/tests/fsharpqa/Source/Libraries/Core/Collections/list_head_tail01.fs deleted file mode 100644 index c8ef0126e5d..00000000000 --- a/tests/fsharpqa/Source/Libraries/Core/Collections/list_head_tail01.fs +++ /dev/null @@ -1,33 +0,0 @@ -// #Regression #Libraries #Collections -// Regression test for FSharp1.0:5641 -// Title: List.hd/tl --> List.head/tail - -//The value, constructor, namespace or type 'hd' is not defined -//The value, constructor, namespace or type 'tl' is not defined - -// Positive tests... -if (List.head [1 .. 10] <> 1) - || (List.head ["a"] <> "a") - || (List.tail [1 .. 10] <> [2 .. 10]) - || (List.tail [1] <> []) - || (List.head ['a'; 'a'] <> List.head (List.tail ['a'; 'a'])) -then exit 1 - -// Negative tests... -try - List.head [] |> ignore - exit 1 -with - | :? System.ArgumentException -> () - -try - List.tail [] |> ignore - exit 1 -with - | :? System.ArgumentException -> () - -// Test deprecation message (now it's an error!) -List.hd [1] |> ignore -List.tl [1] |> ignore - -exit 0