Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move fsharpqa/Libraries/Core/Collections test cases to NUnit #9292

Merged
merged 6 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
module ``Array2D Tests`` =

[<Test>]
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

[<Test>]
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
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
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

[<Test>]
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
59 changes: 59 additions & 0 deletions tests/fsharp/Compiler/Libraries/Core/Collections/ListTests.fs
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
module ``List Tests`` =

[<Test>]
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."



[<Test>]
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."

[<Test>]
let ``List head of empty list``() =
let testDelegate = TestDelegate (fun _ -> (List.head [] |> ignore))

Assert.Throws<System.ArgumentException> testDelegate |> ignore

[<Test>]
let ``List tail of empty list``() =
let testDelegate = TestDelegate (fun _ -> (List.tail [] |> ignore))

Assert.Throws<System.ArgumentException> testDelegate |> ignore

[<Test>]
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'])
17 changes: 17 additions & 0 deletions tests/fsharp/Compiler/Libraries/Core/Collections/MapTests.fs
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
module ``Map Tests`` =

[<Test>]
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
4 changes: 4 additions & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
<Compile Include="Compiler\Stress\LargeExprTests.fs" />
<Compile Include="Compiler\Regressions\IndexerRegressionTests.fs" />
<Compile Include="Compiler\Regressions\ForInDoMutableRegressionTest.fs" />
<Compile Include="Compiler\Libraries\Core\Collections\IEnumerableTests.fs" />
<Compile Include="Compiler\Libraries\Core\Collections\MapTests.fs" />
<Compile Include="Compiler\Libraries\Core\Collections\CollectionTests.fs" />
<Compile Include="Compiler\Libraries\Core\Collections\ListTests.fs" />
<None Include="app.config" />
<None Include="update.base.line.with.actuals.fsx" />

Expand Down
10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter01.fs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/Libraries/Core/Collections/Array2DIter02.fs

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions tests/fsharpqa/Source/Libraries/Core/Collections/env.lst

This file was deleted.

This file was deleted.