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

Moved fsharpqa/Libraries/Core/Unchecked test cases to NUnit #9576

Merged
merged 3 commits into from
Jun 29, 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
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.