Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gtest-269.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8da9a5b893961212831f54ee8c1a527ac7a6dbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;

[Flags]
enum IrishBeer {
	Stout		= 0x1000,
	Ale		= 0x2000,
	Lager		= 0x3000,

	Guinness	= 1 | Stout,
	Smithwicks	= 2 | Ale
}

struct IrishPub
{
	public readonly IrishBeer Beer;

	public IrishPub (IrishBeer beer)
	{
		this.Beer = beer;
	}

	public static implicit operator long (IrishPub? pub)
	{
		return pub.HasValue ? (long) pub.Value.Beer : 0;
	}

	public static implicit operator IrishPub? (long value)
	{
		return new IrishPub ((IrishBeer) value);
	}
}

class X
{
	static int Beer (IrishPub? pub)
	{
		switch (pub) {
		case 0x1001:
			return 1;

		case 0x2002:
			return 2;

		default:
			return 3;
		}
	}

	static long PubToLong (IrishPub pub)
	{
		return pub;
	}

	static int Test (int? a)
	{
		switch (a) {
		case 0:
			return 0;

		case 3:
			return 1;

		default:
			return 2;
		}
	}

	static int TestWithNull (int? a)
	{
		switch (a) {
		case 0:
			return 0;

		case 3:
			return 1;

		case null:
			return 2;

		default:
			return 3;
		}
	}

	static long? Foo (bool flag)
	{
		if (flag)
			return 4;
		else
			return null;
	}

	static int Test (bool flag)
	{
		switch (Foo (flag)) {
		case 0:
			return 0;

		case 4:
			return 1;

		default:
			return 2;
		}
	}

	static int Main ()
	{
		IrishPub pub = new IrishPub (IrishBeer.Guinness);
		if (PubToLong (pub) != 0x1001)
			return 1;

		if (Beer (null) != 3)
			return 2;
		if (Beer (new IrishPub (IrishBeer.Guinness)) != 1)
			return 3;

		if (Test (null) != 2)
			return 4;
		if (Test (3) != 1)
			return 5;
		if (Test (true) != 1)
			return 6;
		if (Test (false) != 2)
			return 7;

		if (TestWithNull (null) != 2)
			return 8;
		if (TestWithNull (3) != 1)
			return 9;

		return 0;
	}
}