-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
d890c64
commit c2a10fd
Showing
5 changed files
with
64 additions
and
70 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
tests/fsharp/Compiler/Libraries/Core/Unchecked/DefaultOfTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
tests/fsharpqa/Source/Libraries/Core/Unchecked/DefaultOf01.fs
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
tests/fsharpqa/Source/Libraries/Core/Unchecked/DefaultOf02.fs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.