Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52fa967

Browse files
forkiVFSharpTeam
authored and
VFSharpTeam
committed
Starting to add tests for discrimanted unions.
1 parent542ef81 commit52fa967

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core.Unittests.fsproj‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.-->
33
<ProjectToolsVersion="4.0"DefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
44
<PropertyGroup>
@@ -75,6 +75,7 @@
7575
<CompileInclude="FSharp.Core\Microsoft.FSharp.Collections\SeqModule2.fs" />
7676
<CompileInclude="FSharp.Core\Microsoft.FSharp.Collections\StringModule.fs" />
7777
<CompileInclude="FSharp.Core\PrimTypes.fs" />
78+
<CompileInclude="FSharp.Core\DiscrimantedUnionType.fs" />
7879
<CompileInclude="FSharp.Core\Microsoft.FSharp.Core\BigIntType.fs" />
7980
<CompileInclude="FSharp.Core\Microsoft.FSharp.Core\IntConversions.fs" />
8081
<CompileInclude="FSharp.Core\Microsoft.FSharp.Core\IntConversionsGenerated.fs" />
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
namespaceFSharp.Core.Unittests.FSharp_Core.Microsoft_FSharp_Core
4+
5+
openSystem
6+
openSystem.Numerics
7+
openFSharp.Core.Unittests.LibraryTestFx
8+
openNUnit.Framework
9+
10+
typeEnumUnion=
11+
| A
12+
| B
13+
14+
[<TestFixture>]
15+
typeUseUnionsAsEnums()=
16+
[<Test>]
17+
memberthis.CanCompare()=
18+
Assert.AreEqual(EnumUnion.B, EnumUnion.B)
19+
Assert.AreNotEqual(EnumUnion.A, EnumUnion.B)
20+
21+
[<Flags>]
22+
typeFlagsUnion=
23+
| One=1
24+
| Two=2
25+
| Four=4
26+
27+
[<TestFixture>]
28+
typeUseUnionsAsFlags()=
29+
[<Test>]
30+
memberthis.CanCompareWithInts()=
31+
Assert.AreEqual(int FlagsUnion.One,1)
32+
Assert.AreEqual(int FlagsUnion.Two,2)
33+
Assert.AreEqual(int FlagsUnion.Four,4)
34+
35+
[<Test>]
36+
memberthis.CanUseBinaryOr()=
37+
Assert.AreEqual(int(FlagsUnion.One||| FlagsUnion.Two),3)
38+
39+
[<Test>]
40+
memberthis.CanCompareWithFlags()=
41+
Assert.AreEqual(FlagsUnion.Two, FlagsUnion.Two)
42+
Assert.AreNotEqual(FlagsUnion.Two, FlagsUnion.One)
43+
44+
typeUnionsWithData=
45+
| Alphaofint
46+
| Betaofstring*float
47+
48+
[<TestFixture>]
49+
typeUseUnionsWithData()=
50+
leta1= Alpha1
51+
leta2= Alpha2
52+
letb1= Beta("win",8.1)
53+
54+
[<Test>]
55+
memberthis.CanAccessTheData()=
56+
match a1with
57+
| Alpha1->()
58+
|_-> Assert.Fail()
59+
60+
match a2with
61+
| Alpha2->()
62+
|_-> Assert.Fail()
63+
64+
match a2with
65+
| Alpha x-> Assert.AreEqual(x,2)
66+
|_-> Assert.Fail()
67+
68+
match b1with
69+
| Beta("win",8.1)->()
70+
|_-> Assert.Fail()
71+
72+
match b1with
73+
| Beta(x,y)->
74+
Assert.AreEqual(x,"win")
75+
Assert.AreEqual(y,8.1)
76+
|_-> Assert.Fail()
77+
78+
[<Test>]
79+
memberthis.CanAccessTheDataInGuards()=
80+
match a1with
81+
| Alpha xwhen x=1->()
82+
|_-> Assert.Fail()
83+
84+
match a2with
85+
| Alpha xwhen x=2->()
86+
|_-> Assert.Fail()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp