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

Commit9b36cec

Browse files
forkiVFSharpTeam
authored and
VFSharpTeam
committed
More tests for discrimanted unions.
1 parent52fa967 commit9b36cec

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed
Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,98 @@
11
// 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-
32
namespaceFSharp.Core.Unittests.FSharp_Core.Microsoft_FSharp_Core
43

54
openSystem
6-
openSystem.Numerics
5+
openSystem.Numerics
76
openFSharp.Core.Unittests.LibraryTestFx
87
openNUnit.Framework
98

109
typeEnumUnion=
11-
| A
12-
| B
10+
| A
11+
| B
1312

1413
[<TestFixture>]
15-
typeUseUnionsAsEnums()=
14+
typeUseUnionsAsEnums()=
1615
[<Test>]
17-
memberthis.CanCompare()=
16+
memberthis.CanCompare()=
1817
Assert.AreEqual(EnumUnion.B, EnumUnion.B)
1918
Assert.AreNotEqual(EnumUnion.A, EnumUnion.B)
2019

2120
[<Flags>]
2221
typeFlagsUnion=
23-
| One=1
24-
| Two=2
25-
| Four=4
22+
| One=1
23+
| Two=2
24+
| Four=4
2625

2726
[<TestFixture>]
28-
typeUseUnionsAsFlags()=
27+
typeUseUnionsAsFlags()=
28+
2929
[<Test>]
30-
memberthis.CanCompareWithInts()=
30+
memberthis.CanCompareWithInts()=
3131
Assert.AreEqual(int FlagsUnion.One,1)
3232
Assert.AreEqual(int FlagsUnion.Two,2)
3333
Assert.AreEqual(int FlagsUnion.Four,4)
34-
34+
35+
[<Test>]
36+
memberthis.CanCastFromInts()=
37+
letfour:FlagsUnion=enum4
38+
Assert.AreEqual(four, FlagsUnion.Four)
39+
3540
[<Test>]
36-
memberthis.CanUseBinaryOr()=
41+
memberthis.CanCreateValuesWithoutName()=
42+
letunknown:FlagsUnion=enum99// strange, but valid
43+
Assert.AreEqual(int unknown,99)
44+
45+
[<Test>]
46+
memberthis.CanParseViaBCL()=
47+
letvalues= System.Enum.GetValues(typeof<FlagsUnion>)
48+
letfourFromString= System.Enum.Parse(typeof<FlagsUnion>,"Four"):?> FlagsUnion// downcast needed
49+
Assert.AreEqual(fourFromString, FlagsUnion.Four)
50+
51+
[<Test>]
52+
memberthis.CanUseBinaryOr()=
3753
Assert.AreEqual(int(FlagsUnion.One||| FlagsUnion.Two),3)
38-
54+
Assert.AreEqual(int(FlagsUnion.One||| FlagsUnion.One),1)
55+
3956
[<Test>]
40-
memberthis.CanCompareWithFlags()=
57+
memberthis.CanCompareWithFlags()=
4158
Assert.AreEqual(FlagsUnion.Two, FlagsUnion.Two)
4259
Assert.AreNotEqual(FlagsUnion.Two, FlagsUnion.One)
4360

4461
typeUnionsWithData=
45-
| Alphaofint
46-
| Betaofstring*float
62+
| Alphaofint
63+
| Betaofstring*float
4764

4865
[<TestFixture>]
49-
typeUseUnionsWithData()=
66+
typeUseUnionsWithData()=
5067
leta1= Alpha1
5168
leta2= Alpha2
52-
letb1= Beta("win",8.1)
53-
69+
letb1= Beta("win",8.1)
70+
5471
[<Test>]
55-
memberthis.CanAccessTheData()=
72+
memberthis.CanAccessTheData()=
5673
match a1with
5774
| Alpha1->()
5875
|_-> Assert.Fail()
59-
6076
match a2with
6177
| Alpha2->()
6278
|_-> Assert.Fail()
63-
6479
match a2with
65-
| Alpha x-> Assert.AreEqual(x,2)
80+
| Alpha x-> Assert.AreEqual(x,2)
6681
|_-> Assert.Fail()
67-
6882
match b1with
69-
| Beta("win",8.1)->()
83+
| Beta("win",8.1)->()
7084
|_-> Assert.Fail()
71-
7285
match b1with
73-
| Beta(x,y)->
74-
Assert.AreEqual(x,"win")
75-
Assert.AreEqual(y,8.1)
86+
| Beta(x,y)->
87+
Assert.AreEqual(x,"win")
88+
Assert.AreEqual(y,8.1)
7689
|_-> Assert.Fail()
77-
90+
7891
[<Test>]
79-
memberthis.CanAccessTheDataInGuards()=
92+
memberthis.CanAccessTheDataInGuards()=
8093
match a1with
8194
| Alpha xwhen x=1->()
8295
|_-> Assert.Fail()
83-
8496
match a2with
85-
| Alphaxwhen x=2->()
97+
| Alpha xwhen x=2->()
8698
|_-> Assert.Fail()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp