diff options
author | Marek Safar <marek.safar@gmail.com> | 2008-05-31 22:49:27 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2008-05-31 22:49:27 +0400 |
commit | 10dc4560c7321a1e315708ce5fa3afa84553c58c (patch) | |
tree | 407650f8610c11780130a505397abf3d6bd52911 /mcs/tests/gtest-397.cs | |
parent | 03f6e7fdd6ba00253b5e6b0f2ba0caf3f776a59b (diff) |
New test.
svn path=/trunk/mcs/; revision=104604
Diffstat (limited to 'mcs/tests/gtest-397.cs')
-rwxr-xr-x | mcs/tests/gtest-397.cs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/mcs/tests/gtest-397.cs b/mcs/tests/gtest-397.cs new file mode 100755 index 00000000000..a899a717c1b --- /dev/null +++ b/mcs/tests/gtest-397.cs @@ -0,0 +1,79 @@ +using System;
+
+struct Foo
+{
+ public int Value;
+
+ public Foo (int value)
+ {
+ this.Value = value;
+ }
+
+ public static Foo operator - (Foo? f)
+ {
+ if (f.HasValue)
+ return new Foo (-f.Value.Value);
+
+ return new Foo (42);
+ }
+}
+
+struct Bar
+{
+ public int Value;
+
+ public Bar (int value)
+ {
+ this.Value = value;
+ }
+
+ public static Bar? operator - (Bar? b)
+ {
+ if (b.HasValue)
+ return new Bar (-b.Value.Value);
+
+ return b;
+ }
+}
+
+class Test
+{
+
+ static Foo NegateFoo (Foo f)
+ {
+ return -f;
+ }
+
+ static Foo NegateFooNullable (Foo? f)
+ {
+ return -f;
+ }
+
+ static Bar? NegateBarNullable (Bar? b)
+ {
+ return -b;
+ }
+
+ static Bar? NegateBar (Bar b)
+ {
+ return -b;
+ }
+
+ static int Main ()
+ {
+ if (NegateFooNullable (null).Value != 42)
+ return 1;
+
+ if (NegateFoo (new Foo (2)).Value != -2)
+ return 2;
+
+ if (NegateBarNullable (null) != null)
+ return 3;
+
+ if (NegateBar (new Bar (2)).Value.Value != -2)
+ return 4;
+
+ Console.WriteLine ("OK");
+ return 0;
+ }
+}
|