Skip to content

Commit

Permalink
Moved fsharpqa/Libraries/Core/Unchecked test cases to NUnit (#9576) (#…
Browse files Browse the repository at this point in the history
…9598)

Co-authored-by: Thorsten Reichert <ThorstenReichert@users.noreply.github.com>
  • Loading branch information
dotnet-bot and ThorstenReichert authored Jun 30, 2020
1 parent d890c64 commit c2a10fd
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 70 deletions.
63 changes: 63 additions & 0 deletions tests/fsharp/Compiler/Libraries/Core/Unchecked/DefaultOfTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 ``DefaultOf Tests`` =

type DUType =
| A
| B of int
| C of DUType * DUType

type RecordType = { A : int; B : string; C : DUType }

type ClassType = string

type InterfaceType =
abstract DoStuff : unit -> unit

type EnumType =
| A = 1
| B = 2
| C = 4

type StructType = struct
val m_ivalue : int
val m_svalue : string
member this.IValue = this.m_ivalue
member this.SValue = this.m_svalue
end

[<Test>]
let `` Unchecked defaultof reference types``() =
Assert.areEqual Unchecked.defaultof<ClassType> null
Assert.areEqual (box Unchecked.defaultof<DUType>) null
Assert.areEqual (box Unchecked.defaultof<RecordType>) null
Assert.areEqual (box Unchecked.defaultof<InterfaceType>) null

[<Test>]
let ``Unchecked defaultof stack types``() =
Assert.areEqual Unchecked.defaultof<int> 0
Assert.areEqual Unchecked.defaultof<float> 0.0
Assert.areEqual Unchecked.defaultof<EnumType> (enum 0)
Assert.areEqual Unchecked.defaultof<StructType>.IValue 0
Assert.areEqual Unchecked.defaultof<StructType>.SValue null

type R = { x : int; y : string }
type U = | A of int | B of string
type S = struct val mutable x : int end
type C() = class end

[<Test>]
let ``Unchecked defaultof and equality``() =
// FSharp1.0:5417 - Unchecked.defaultof<_> on records/unions can cause structural equality check to throw
// Check that Unchecked.defaultof<_> works correctly on various types, mostly structs/unions/records

Assert.areEqual Unchecked.defaultof<R> Unchecked.defaultof<R>
Assert.areEqual Unchecked.defaultof<U> Unchecked.defaultof<U>
Assert.areEqual Unchecked.defaultof<S> Unchecked.defaultof<S>
Assert.areEqual Unchecked.defaultof<C> Unchecked.defaultof<C>
Assert.areEqual Unchecked.defaultof<int> Unchecked.defaultof<int>
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="Compiler\Libraries\Core\Operators\RoundTests.fs" />
<Compile Include="Compiler\Libraries\Core\Operators\SignTests.fs" />
<Compile Include="Compiler\Libraries\Core\Operators\StringTests.fs" />
<Compile Include="Compiler\Libraries\Core\Unchecked\DefaultOfTests.fs" />
<None Include="app.config" />
<None Include="update.base.line.with.actuals.fsx" />

Expand Down
51 changes: 0 additions & 51 deletions tests/fsharpqa/Source/Libraries/Core/Unchecked/DefaultOf01.fs

This file was deleted.

17 changes: 0 additions & 17 deletions tests/fsharpqa/Source/Libraries/Core/Unchecked/DefaultOf02.fs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/fsharpqa/Source/Libraries/Core/Unchecked/env.lst

This file was deleted.

0 comments on commit c2a10fd

Please sign in to comment.