From 903f7674c598bb3d05c3636f87a0b08b6c62b87e Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 27 Mar 2008 12:33:21 +0000 Subject: [PATCH] New tests. svn path=/trunk/mcs/; revision=99117 --- mcs/tests/gtest-376.cs | 18 ++++++++++++++++++ mcs/tests/gtest-etree-01.cs | 29 +++++++++++++++++++++++++++-- mcs/tests/gtest-etree-03.cs | 27 +++++++++++++++++++++++++++ mcs/tests/known-issues-gmcs | 2 ++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 mcs/tests/gtest-376.cs create mode 100644 mcs/tests/gtest-etree-03.cs diff --git a/mcs/tests/gtest-376.cs b/mcs/tests/gtest-376.cs new file mode 100644 index 00000000000..fd78b6c1ba5 --- /dev/null +++ b/mcs/tests/gtest-376.cs @@ -0,0 +1,18 @@ +using System; + +struct S where T : struct +{ + static object Box (T? o) + { + if (o == null) + return null; + return (T) o; + } +} + +class C +{ + public static void Main () + { + } +} diff --git a/mcs/tests/gtest-etree-01.cs b/mcs/tests/gtest-etree-01.cs index ce465958084..2a26d944eec 100644 --- a/mcs/tests/gtest-etree-01.cs +++ b/mcs/tests/gtest-etree-01.cs @@ -197,6 +197,7 @@ class Tester void AddTest () { + /* Expression> e = (int a, int b) => a + b; AssertNodeType (e, ExpressionType.Add); Assert (50, e.Compile ().Invoke (20, 30)); @@ -217,11 +218,11 @@ class Tester Expression> e5 = (int a, MyType b) => a + b; AssertNodeType (e5, ExpressionType.Add); Assert (31, e5.Compile ().Invoke (1, new MyType (30))); -/* +*/ + Expression> e6 = (int a, MyType? b) => a + b; AssertNodeType (e6, ExpressionType.Add); Assert (-1, e6.Compile ().Invoke (-31, new MyType (30))); -*/ } void AddCheckedTest () @@ -406,6 +407,25 @@ class Tester Assert (3, r4.Invoke (new InverseLogicalOperator (true), 3, 4)); Assert (4, r4.Invoke (new InverseLogicalOperator (false), 3, 4)); } + + void ConstantTest () + { + Expression> e1 = () => default (int); + AssertNodeType (e1, ExpressionType.Constant); + Assert (0, e1.Compile ().Invoke ()); + + Expression> e2 = () => default (int?); + AssertNodeType (e2, ExpressionType.Constant); + Assert (null, e2.Compile ().Invoke ()); + + Expression> e3 = () => default (Tester); + AssertNodeType (e3, ExpressionType.Constant); + Assert (null, e3.Compile ().Invoke ()); + + Expression> e4 = () => null; + AssertNodeType (e4, ExpressionType.Constant); + Assert (null, e4.Compile ().Invoke ()); + } void ConvertTest () { @@ -430,6 +450,10 @@ class Tester // TODO: redundant return conversion // Expression> e6 = x => (int?)x; + + // TODO: redundant convert + // TODO: pass null value + // Expression> ex = x => (object)x; } void ConvertCheckedTest () @@ -790,6 +814,7 @@ class Tester e.CallTest (); e.CoalesceTest (); e.ConditionTest (); + e.ConstantTest (); e.ConvertTest (); e.ConvertCheckedTest (); e.DivideTest (); diff --git a/mcs/tests/gtest-etree-03.cs b/mcs/tests/gtest-etree-03.cs new file mode 100644 index 00000000000..e6562cc1f35 --- /dev/null +++ b/mcs/tests/gtest-etree-03.cs @@ -0,0 +1,27 @@ +using System; +using System.Linq.Expressions; + +struct S where T : struct +{ + public static int Test () + { + Expression> e = (T? o) => o == null; + if (!e.Compile ().Invoke (null)) + return 1; + + if (e.Compile ().Invoke (default (T))) + return 2; + + Console.WriteLine ("OK"); + return 0; + } +} + +class C +{ + static int Main() + { + return S.Test (); + } +} + diff --git a/mcs/tests/known-issues-gmcs b/mcs/tests/known-issues-gmcs index a7612f14efd..063b04d7aa4 100644 --- a/mcs/tests/known-issues-gmcs +++ b/mcs/tests/known-issues-gmcs @@ -13,5 +13,7 @@ gtest-367.cs ltest-11.cs gtest-etree-01.cs +gtest-etree-03.cs + gtest-334.cs # Will have to really investigate why is it allowed gtest-358.cs # Required user-operators rewrite -- 2.25.1