2 // ExpressionTest_Lift: this contains tests for the various lifting settings in binary expressions
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // Miguel de Icaza (miguel@novell.com)
27 using System.Reflection;
29 using System.Linq.Expressions;
30 using NUnit.Framework;
32 namespace MonoTests.System.Linq.Expressions
35 public class ExpressionTest_Lifting
38 public void TestLiftOnEqual ()
40 ConstantExpression a = Expression.Constant (1, typeof (int?));
41 ConstantExpression b = Expression.Constant (1, typeof (int?));
43 BinaryExpression cmp = Expression.Equal (a, b);
45 Assert.AreEqual (true, cmp.IsLifted, "IsLifted");
46 Assert.AreEqual (false, cmp.IsLiftedToNull, "IsLiftedToNull");
47 Assert.AreEqual (typeof(bool), cmp.Type, "type");
51 public void TestLiftOnEqual_ForcedLifted ()
53 ConstantExpression a = Expression.Constant (1, typeof (int?));
54 ConstantExpression b = Expression.Constant (1, typeof (int?));
56 // Force the lift on equal
57 BinaryExpression cmp = Expression.Equal (a, b, true, null);
59 Assert.AreEqual (true, cmp.IsLifted, "IsLifted");
60 Assert.AreEqual (true, cmp.IsLiftedToNull, "IsLiftedToNull");
61 Assert.AreEqual (typeof(bool?), cmp.Type);
64 static MethodInfo GM(string n)
66 MethodInfo [] m = typeof(ExpressionTest_Lifting).GetMethods(BindingFlags.Static | BindingFlags.Public);
68 foreach (MethodInfo mm in m)
72 throw new Exception("No method found: " + n);
75 static public int MyCompare (OpStruct a, OpStruct b)
81 public void TestLiftOnEqual_WithMethodInfo ()
83 ConstantExpression a = Expression.Constant (new OpStruct (), typeof (OpStruct?));
84 ConstantExpression b = Expression.Constant (null, typeof (OpStruct?));
86 // Force the lift on equal
87 BinaryExpression cmp = Expression.Equal (a, b, true, GM("MyCompare"));
89 Assert.AreEqual (true, cmp.IsLifted, "IsLifted");
90 Assert.AreEqual (true, cmp.IsLiftedToNull, "IsLiftedToNull");
92 BinaryExpression cmp2 = Expression.Equal (a, b, false, GM("MyCompare"));
95 // When we use a MethodInfo, that has a non-bool return type,
96 // the result is always Nullable<returntype> regardless of the
97 // setting of "liftToNull"
99 Assert.AreEqual (typeof(int?), cmp.Type);
100 Assert.AreEqual (typeof(int?), cmp2.Type);