add comment
[mcs.git] / tests / dtest-006.cs
blob5f06ca05f6ff54542b48ed1f3b0495e518de3b96
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Linq.Expressions;
5 using System.Reflection;
7 // Dynamic binary and unary operators tests
9 public struct InverseLogicalOperator
11 bool value;
12 public InverseLogicalOperator (bool value)
14 this.value = value;
17 public static bool operator true (InverseLogicalOperator u)
19 return u.value;
22 public static bool operator false (InverseLogicalOperator u)
24 return u.value;
28 /* TODO: Add tests for every numeric expression where a type has only 1 implicit
29 numeric conversion
30 public struct MyType<T>
32 T value;
34 public MyType (T value)
36 this.value = value;
39 public static implicit operator T (MyType<T> o)
41 return o.value;
47 // TODO: Create a clone which uses +(MyType, int) pattern and an implicit conversion
48 // is required to do the user-conversion
50 public struct MyType
52 int value;
54 public MyType (int value) : this ()
56 this.value = value;
59 public short ShortProp { get; set; }
61 public override int GetHashCode ()
63 throw new NotImplementedException ();
66 public static implicit operator int (MyType o)
68 return o.value;
71 public static bool operator true (MyType a)
73 return a.value == a;
76 public static bool operator false (MyType a)
78 return a.value != a;
81 public static MyType operator + (MyType a, MyType b)
83 return new MyType (a.value + b.value);
86 public static MyType operator - (MyType a, MyType b)
88 return new MyType (a.value - b.value);
91 public static MyType operator / (MyType a, MyType b)
93 return new MyType (a.value / b.value);
96 public static MyType operator * (MyType a, MyType b)
98 return new MyType (a.value * b.value);
101 public static MyType operator % (MyType a, MyType b)
103 return new MyType (a.value % b.value);
106 public static MyType operator &(MyType a, MyType b)
108 return new MyType (a.value & b.value);
111 public static MyType operator | (MyType a, MyType b)
113 return new MyType (a.value | b.value);
116 public static MyType operator ^ (MyType a, MyType b)
118 return new MyType (a.value ^ b.value);
121 public static bool operator == (MyType a, MyType b)
123 return a.value == b.value;
126 public static bool operator != (MyType a, MyType b)
128 return a.value != b.value;
131 public static bool operator > (MyType a, MyType b)
133 return a.value > b.value;
136 public static bool operator < (MyType a, MyType b)
138 return a.value < b.value;
141 public static bool operator >= (MyType a, MyType b)
143 return a.value >= b.value;
146 public static bool operator <= (MyType a, MyType b)
148 return a.value <= b.value;
151 public static bool operator ! (MyType a)
153 return a.value > 0;
156 public static int operator >> (MyType a, int b)
158 return a.value >> b;
161 public static int operator << (MyType a, int b)
163 return a.value << b;
166 public static MyType operator - (MyType a)
168 return new MyType (-a.value);
171 public static MyType operator + (MyType a)
173 return new MyType (+a.value);
176 public override string ToString ()
178 return value.ToString ();
183 class MyTypeExplicit
185 int value;
187 public MyTypeExplicit (int value)
189 this.value = value;
192 public static explicit operator int (MyTypeExplicit m)
194 return m.value;
198 struct MyTypeImplicitOnly
200 short b;
202 public MyTypeImplicitOnly (short b)
204 this.b = b;
207 public static implicit operator short (MyTypeImplicitOnly m)
209 return m.b;
213 class MemberAccessData
215 public bool BoolValue;
216 public static decimal DecimalValue = decimal.MinValue;
217 public volatile uint VolatileValue;
218 public string [] StringValues;
219 public List<string> ListValues;
221 event Func<bool> EventField;
222 public Expression<Func<Func<bool>>> GetEvent ()
224 return () => EventField;
227 MyType mt;
228 public MyType MyTypeProperty {
229 set {
230 mt = value;
232 get {
233 return mt;
237 public static string StaticProperty {
238 get {
239 return "alo";
244 enum MyEnum : byte
246 Value_1 = 1,
247 Value_2 = 2
250 enum MyEnumUlong : ulong
252 Value_1 = 1,
253 Value_2 = 2
257 class NewTest<T>
259 T [] t;
260 public NewTest (T i)
262 t = new T [] { i };
265 public NewTest (params T [] t)
267 this.t = t;
270 public override int GetHashCode ()
272 return base.GetHashCode ();
275 public override bool Equals (object obj)
277 NewTest<T> obj_t = obj as NewTest<T>;
278 if (obj_t == null)
279 return false;
281 for (int i = 0; i < t.Length; ++i) {
282 if (!t [i].Equals (obj_t.t [i]))
283 return false;
286 return true;
290 class Indexer
292 public int this [int i] { get { return i; } set { } }
293 public string this [params string[] i] { get { return string.Concat (i); } }
297 class Tester
299 static void Assert<T> (T expected, T value, string name)
301 if (!EqualityComparer<T>.Default.Equals (expected, value)) {
302 name += ": ";
303 throw new ApplicationException (name + expected + " != " + value);
307 static void AssertChecked<T> (Func<T> expected, T value, string name)
309 try {
310 Assert (expected (), value, name);
311 throw new ApplicationException (name + ": OverflowException expected");
312 } catch (OverflowException) {
313 // passed
317 static void AssertChecked (Action expected, string name)
319 try {
320 expected ();
321 throw new ApplicationException (name + ": OverflowException expected");
322 } catch (OverflowException) {
323 // passed
328 static void Assert<T> (T [] expected, T [] value)
330 if (expected == null) {
331 if (value != null)
332 throw new ApplicationException ("Both arrays expected to be null");
333 return;
336 if (expected.Length != value.Length)
337 throw new ApplicationException ("Array length does not match " + expected.Length + " != " + value.Length);
339 for (int i = 0; i < expected.Length; ++i) {
340 if (!EqualityComparer<T>.Default.Equals (expected [i], value [i]))
341 throw new ApplicationException ("Index " + i + ": " + expected [i] + " != " + value [i]);
346 #pragma warning disable 169
348 void AddTest ()
350 dynamic d = 5;
352 int v = 2;
353 Assert (d + v, 7, "#1");
354 double v2 = 0.5;
355 Assert (d + v2, 5.5, "#1a");
357 MyType v3 = new MyType (30);
358 Assert (d + v3, new MyType (35), "#3");
359 dynamic d3 = new MyType (-7);
360 Assert<MyType> (d3 + new MyType (6), new MyType (-1), "#3a");
361 Assert (d3 + 11, 4, "#3b");
363 decimal v4 = 4m;
364 Assert (d + v4, 9m, "#4");
367 void AddNullableTest ()
369 dynamic d = 5;
371 int? v2 = null;
372 Assert<int?> (d + v2, null, "#1");
373 Assert<int?> (d + null, null, "#1a");
374 Assert<int?> (null + d, null, "#1b");
376 v2 = -2;
377 Assert (d + v2, 3, "#2");
378 dynamic d2 = (int?) -2;
379 Assert (d2 + 1, -1, "#2a");
381 MyType? v3 = new MyType (30);
382 Assert (d + v3, new MyType (35), "#3");
383 dynamic d3 = new MyType? (new MyType (-7));
384 Assert (d3 + new MyType (6), new MyType (-1), "#3a");
385 Assert<MyType?> (d3 + null, null, "#3b");
387 decimal? v4 = 4m;
388 Assert (d + v4, 9m, "#4");
389 v4 = null;
390 Assert<decimal?> (d + v4, null, "#4a");
393 void AddEnumTest ()
395 dynamic d = MyEnum.Value_1;
397 // CSC: Invalid System.InvalidOperationException
398 Assert (d + null, null, "#1");
400 Assert (d + 1, MyEnum.Value_2, "#2");
402 dynamic d2 = (MyEnumUlong?) MyEnumUlong.Value_1;
403 Assert (d2 + (byte) 1, MyEnumUlong.Value_2, "#3");
404 Assert<MyEnumUlong?> (d2 + (object) null, null, "#3a");
407 void AddCheckedTest ()
409 checked {
410 dynamic d = 5;
412 int v = int.MaxValue;
413 AssertChecked (() => d + v, 7, "#1");
415 int? v2 = v;
416 AssertChecked (() => d + v2, null, "#2");
418 MyType v3 = new MyType (int.MaxValue);
419 AssertChecked (() => d + v3, new MyType (35), "#3");
423 void AddStringTest ()
425 dynamic d = "foo";
426 string v = "->";
427 Assert (d + v, "foo->", "#1");
428 Assert (d + 1, "foo1", "#1a");
429 Assert (d + null, "foo", "#1b");
430 Assert (d + 1 + v, "foo1->", "#1a");
432 uint? v2 = 4;
433 Assert (d + v2, "foo4", "#2");
436 void AddAssignTest ()
438 dynamic d = 5;
440 int v = 2;
441 d += v;
442 Assert (d, 7, "#1");
444 d = 5.0;
445 double v2 = 0.5;
446 d += v2;
447 Assert (d, 5.5, "#1a");
448 d += v;
449 Assert (d, 7.5, "#1b");
451 dynamic d3 = new MyType (-7);
452 d3 += new MyType (6);
453 Assert<MyType> (d3, new MyType (-1), "#3");
455 d = 5m;
456 decimal v4 = 4m;
457 d += v4;
458 Assert (d, 9m, "#4");
461 void AddAssignNullableTest ()
463 dynamic d = (int?) 5;
465 // For now it's impossible to use nullable compound assignment
466 // due to the way how DLR works. GetType () on nullable object returns
467 // underlying type and not nullable type, that means that
468 // C# binder is initialized with wrong operand type and any operation
469 // fails to resolve
471 long? v2 = null;
472 d += v2;
473 Assert<int?> (d, null, "#1");
474 d += null;
475 Assert<int?> (d, null, "#1a");
477 long? l = (long?) 3;
478 d = l;
479 v2 = -2;
480 d += v2;
481 Assert (d, 3, "#2");
482 d = (int?) -2;
483 d += 1;
484 Assert (d, -1, "#2a");
486 MyType? v3 = new MyType (30);
487 d += v3;
488 Assert (d, new MyType (35), "#3");
489 dynamic d3 = new MyType? (new MyType (-7));
490 Assert (d3 + new MyType (6), new MyType (-1), "#3a");
491 Assert<MyType?> (d3 + null, null, "#3b");
493 decimal? v4 = 4m;
494 d = 2m;
495 d += v4;
496 Assert (d, 9m, "#4");
497 d += null;
498 Assert<decimal?> (d, null, "#4a");
502 void AddAssignEnumTest ()
504 dynamic d = MyEnum.Value_1;
506 d = MyEnum.Value_1;
507 d += 1;
508 Assert (d, MyEnum.Value_2, "#2");
510 dynamic d2 = (MyEnumUlong?) MyEnumUlong.Value_1;
511 d2 += (byte) 1;
512 Assert (d2, MyEnumUlong.Value_2, "#3");
515 void AddAssignCheckedTest ()
517 checked {
518 dynamic d = 5;
520 int v = int.MaxValue;
521 AssertChecked (() => { d += v; Assert (d, 0, "#1-"); }, "#1");
523 // d = (int?) 3;
524 // int? v2 = v;
525 // AssertChecked (() => { d += v2; Assert (d, 0, "#2-"); }, "#2");
527 MyType v3 = new MyType (int.MaxValue);
528 AssertChecked (() => { d += v3; Assert (d, 0, "#3-"); }, "#3");
532 void AddAssignStringTest ()
534 dynamic d = "foo";
535 string v = "->";
536 d += v;
537 Assert (d, "foo->", "#1");
539 d = "foo";
540 d += 1;
541 Assert (d, "foo1", "#1a");
543 d += null;
544 Assert (d, "foo1", "#1b");
546 uint? v2 = 4;
547 d = "foo";
548 d += v2;
549 Assert (d, "foo4", "#2");
553 void AndTest ()
555 Expression<Func<bool, bool, bool>> e = (bool a, bool b) => a & b;
557 AssertNodeType (e, ExpressionType.And);
558 Func<bool, bool, bool> c = e.Compile ();
560 Assert (true, c (true, true));
561 Assert (false, c (true, false));
562 Assert (false, c (false, true));
563 Assert (false, c (false, false));
566 void AndTest_2 ()
568 Expression<Func<MyType, MyType, MyType>> e2 = (MyType a, MyType b) => a & b;
570 AssertNodeType (e2, ExpressionType.And);
571 var c2 = e2.Compile ();
573 Assert (new MyType (0), c2 (new MyType (0), new MyType (1)));
574 Assert (new MyType (1), c2 (new MyType (0xFF), new MyType (0x01)));
577 void AndTest_3 ()
579 Expression<Func<MyEnum, MyEnum, MyEnum>> e3 = (a, b) => a & b;
580 AssertNodeType (e3, ExpressionType.Convert);
581 Assert<MyEnum> (0, e3.Compile ().Invoke (MyEnum.Value_1, MyEnum.Value_2));
582 Assert (MyEnum.Value_2, e3.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
585 void AndTest_4 ()
587 Expression<Func<int, int>> e = (a) => a & 0;
588 AssertNodeType (e, ExpressionType.And);
589 var c = e.Compile ();
591 Assert (0, c (1));
594 void AndNullableTest ()
596 Expression<Func<bool?, bool?, bool?>> e = (bool? a, bool? b) => a & b;
598 AssertNodeType (e, ExpressionType.And);
599 Func<bool?, bool?, bool?> c = e.Compile ();
601 Assert (true, c (true, true));
602 Assert (false, c (true, false));
603 Assert (false, c (false, true));
604 Assert (false, c (false, false));
606 Assert (null, c (true, null));
607 Assert (false, c (false, null));
608 Assert (false, c (null, false));
609 Assert (null, c (true, null));
610 Assert (null, c (null, null));
613 void AndNullableTest_2 ()
615 Expression<Func<MyType?, MyType?, MyType?>> e2 = (MyType? a, MyType? b) => a & b;
617 AssertNodeType (e2, ExpressionType.And);
618 var c2 = e2.Compile ();
620 Assert (new MyType (0), c2 (new MyType (0), new MyType (1)));
621 Assert (new MyType (1), c2 (new MyType (0xFF), new MyType (0x01)));
622 Assert (null, c2 (new MyType (0xFF), null));
625 void AndNullableTest_3 ()
627 Expression<Func<MyEnum?, MyEnum?, MyEnum?>> e3 = (a, b) => a & b;
628 AssertNodeType (e3, ExpressionType.Convert);
629 Assert (null, e3.Compile ().Invoke (null, MyEnum.Value_2));
630 Assert (MyEnum.Value_2, e3.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
633 void AndAlsoTest ()
635 Expression<Func<bool, bool, bool>> e = (bool a, bool b) => a && b;
636 AssertNodeType (e, ExpressionType.AndAlso);
637 Assert (false, e.Compile ().Invoke (true, false));
640 void AndAlsoTest_2 ()
642 Expression<Func<MyType, MyType, MyType>> e2 = (MyType a, MyType b) => a && b;
643 AssertNodeType (e2, ExpressionType.AndAlso);
644 Assert (new MyType (64), e2.Compile ().Invoke (new MyType (64), new MyType (64)));
645 Assert (new MyType (0), e2.Compile ().Invoke (new MyType (32), new MyType (64)));
648 void AndAlsoTest_3 ()
650 Expression<Func<bool, bool>> e3 = (bool a) => a && true;
651 AssertNodeType (e3, ExpressionType.AndAlso);
652 Assert (false, e3.Compile ().Invoke (false));
653 Assert (true, e3.Compile ().Invoke (true));
656 void ArrayIndexTest ()
658 Expression<Func<string [], long, string>> e = (string [] a, long i) => a [i];
659 AssertNodeType (e, ExpressionType.ArrayIndex);
660 Assert ("b", e.Compile ().Invoke (new string [] { "a", "b", "c" }, 1));
663 void ArrayIndexTest_2 ()
665 Expression<Func<string [], string>> e2 = (string [] a) => a [0];
666 AssertNodeType (e2, ExpressionType.ArrayIndex);
667 Assert ("a", e2.Compile ().Invoke (new string [] { "a", "b" }));
670 void ArrayIndexTest_3 ()
672 Expression<Func<object [,], int, int, object>> e3 = (object [,] a, int i, int j) => a [i, j];
673 AssertNodeType (e3, ExpressionType.Call);
675 Assert ("z", e3.Compile ().Invoke (
676 new object [,] { { 1, 2 }, { "x", "z" } }, 1, 1));
679 void ArrayIndexTest_4 ()
681 Expression<Func<decimal [] [], byte, decimal>> e4 = (decimal [] [] a, byte b) => a [b] [1];
682 AssertNodeType (e4, ExpressionType.ArrayIndex);
684 decimal [] [] array = { new decimal [] { 1, 9 }, new decimal [] { 10, 90 } };
685 Assert (90, e4.Compile ().Invoke (array, 1));
688 void ArrayIndexTest_5 ()
690 Expression<Func<int>> e5 = () => (new int [1]) [0];
691 AssertNodeType (e5, ExpressionType.ArrayIndex);
692 Assert (0, e5.Compile ().Invoke ());
695 void ArrayLengthTest ()
697 Expression<Func<double [], int>> e = (double [] a) => a.Length;
698 AssertNodeType (e, ExpressionType.ArrayLength);
699 Assert (0, e.Compile ().Invoke (new double [0]));
700 Assert (9, e.Compile ().Invoke (new double [9]));
703 void ArrayLengthTest_2 ()
705 Expression<Func<string [,], int>> e2 = (string [,] a) => a.Length;
706 AssertNodeType (e2, ExpressionType.MemberAccess);
707 Assert (0, e2.Compile ().Invoke (new string [0, 0]));
710 void CallTest ()
712 Expression<Func<int, int>> e = (int a) => Math.Max (a, 5);
713 AssertNodeType (e, ExpressionType.Call);
714 Assert (5, e.Compile ().Invoke (2));
715 Assert (9, e.Compile ().Invoke (9));
718 void CallTest_2 ()
720 Expression<Func<string, string>> e2 = (string a) => InstanceMethod (a);
721 AssertNodeType (e2, ExpressionType.Call);
722 Assert ("abc", e2.Compile ().Invoke ("abc"));
725 void CallTest_3 ()
727 Expression<Func<int, string, int, object>> e3 = (int index, string a, int b) => InstanceParamsMethod (index, a, b);
728 AssertNodeType (e3, ExpressionType.Call);
729 Assert<object> (4, e3.Compile ().Invoke (1, "a", 4));
732 void CallTest_4 ()
734 Expression<Func<object>> e4 = () => InstanceParamsMethod (0);
735 AssertNodeType (e4, ExpressionType.Call);
736 Assert<object> ("<empty>", e4.Compile ().Invoke ());
739 void CallTest_5 ()
741 Expression<Func<int, int>> e5 = (int a) => GenericMethod (a);
742 AssertNodeType (e5, ExpressionType.Call);
743 Assert (5, e5.Compile ().Invoke (5));
746 void CallTest_6 ()
748 Expression<Action> e6 = () => Console.WriteLine ("call test");
749 AssertNodeType (e6, ExpressionType.Call);
752 void CallTest_7 ()
754 Expression<Func<Indexer, int, int>> e7 = (a, b) => a [b];
755 AssertNodeType (e7, ExpressionType.Call);
756 Assert (3, e7.Compile ().Invoke (new Indexer (), 3));
759 void CallTest_8 ()
761 Expression<Func<Indexer, string, string, string, string>> e8 = (a, b, c , d) => a [b, c, d];
762 AssertNodeType (e8, ExpressionType.Call);
763 Assert ("zyb", e8.Compile ().Invoke (new Indexer (), "z", "y", "b"));
766 void CallTest_9 ()
768 Expression<Action<int>> e9 = (a) => RefMethod (ref a);
769 AssertNodeType (e9, ExpressionType.Call);
770 e9.Compile ().Invoke (1);
773 void CoalesceTest ()
775 Expression<Func<uint?, uint>> e = (uint? a) => a ?? 99;
776 AssertNodeType (e, ExpressionType.Coalesce);
777 var r = e.Compile ();
778 Assert ((uint) 5, r.Invoke (5));
779 Assert ((uint) 99, r.Invoke (null));
782 void CoalesceTest_2 ()
784 Expression<Func<MyType?, int>> e2 = (MyType? a) => a ?? -3;
785 AssertNodeType (e2, ExpressionType.Coalesce);
786 var r2 = e2.Compile ();
787 Assert (2, r2.Invoke (new MyType (2)));
788 Assert (-3, r2.Invoke (null));
791 void ConditionTest ()
793 Expression<Func<bool, byte, int, int>> e = (bool a, byte b, int c) => (a ? b : c);
794 AssertNodeType (e, ExpressionType.Conditional);
795 var r = e.Compile ();
796 Assert (3, r.Invoke (true, 3, 999999));
797 Assert (999999, r.Invoke (false, 3, 999999));
800 void ConditionTest_2 ()
802 Expression<Func<int, decimal, decimal?>> e2 = (int a, decimal d) => (a > 0 ? d : a < 0 ? -d : (decimal?) null);
803 AssertNodeType (e2, ExpressionType.Conditional);
804 var r2 = e2.Compile ();
805 Assert (null, r2.Invoke (0, 10));
806 Assert (50, r2.Invoke (1, 50));
807 Assert (30, r2.Invoke (-7, -30));
810 void ConditionTest_3 ()
812 Expression<Func<bool?, int?>> e3 = (bool? a) => ((bool) a ? 3 : -2);
813 AssertNodeType (e3, ExpressionType.Convert);
814 var r3 = e3.Compile ();
815 Assert (3, r3.Invoke (true));
816 Assert (-2, r3.Invoke (false));
819 void ConditionTest_4 ()
821 Expression<Func<InverseLogicalOperator, byte, byte, byte>> e4 = (InverseLogicalOperator a, byte b, byte c) => (a ? b : c);
822 AssertNodeType (e4, ExpressionType.Conditional);
823 var r4 = e4.Compile ();
824 Assert (3, r4.Invoke (new InverseLogicalOperator (true), 3, 4));
825 Assert (4, r4.Invoke (new InverseLogicalOperator (false), 3, 4));
828 void ConditionTest_5 ()
830 // CSC bug ?
831 Expression<Func<int>> e = () => false ? 1 : 4;
832 AssertNodeType (e, ExpressionType.Conditional);
833 var r = e.Compile ();
834 Assert (4, r.Invoke ());
837 void ConstantTest ()
839 Expression<Func<int>> e1 = () => default (int);
840 AssertNodeType (e1, ExpressionType.Constant);
841 Assert (0, e1.Compile ().Invoke ());
844 void ConstantTest_2 ()
846 Expression<Func<int?>> e2 = () => default (int?);
847 AssertNodeType (e2, ExpressionType.Constant);
848 Assert (null, e2.Compile ().Invoke ());
851 void ConstantTest_3 ()
853 Expression<Func<Tester>> e3 = () => default (Tester);
854 AssertNodeType (e3, ExpressionType.Constant);
855 Assert (null, e3.Compile ().Invoke ());
858 void ConstantTest_4 ()
860 Expression<Func<object>> e4 = () => null;
861 AssertNodeType (e4, ExpressionType.Constant);
862 Assert (null, e4.Compile ().Invoke ());
865 void ConstantTest_5 ()
867 Expression<Func<int>> e5 = () => 8 / 4;
868 AssertNodeType (e5, ExpressionType.Constant);
869 Assert (2, e5.Compile ().Invoke ());
872 void ConstantTest_6 ()
874 Expression<Func<int>> e6 = () => 0xFFFFFF >> 0x40;
875 AssertNodeType (e6, ExpressionType.Constant);
876 Assert (0xFFFFFF, e6.Compile ().Invoke ());
879 void ConstantTest_7 ()
881 Expression<Func<object>> e7 = () => "Alleluia";
882 AssertNodeType (e7, ExpressionType.Constant);
883 Assert ("Alleluia", e7.Compile ().Invoke ());
886 void ConstantTest_8 ()
888 Expression<Func<Type>> e8 = () => typeof (int);
889 AssertNodeType (e8, ExpressionType.Constant);
890 Assert (typeof (int), e8.Compile ().Invoke ());
893 void ConstantTest_9 ()
895 Expression<Func<Type>> e9 = () => typeof (void);
896 AssertNodeType (e9, ExpressionType.Constant);
897 Assert (typeof (void), e9.Compile ().Invoke ());
900 void ConstantTest_10 ()
902 Expression<Func<Type>> e10 = () => typeof (Func<,>);
903 AssertNodeType (e10, ExpressionType.Constant);
904 Assert (typeof (Func<,>), e10.Compile ().Invoke ());
907 void ConstantTest_11 ()
909 Expression<Func<MyEnum>> e11 = () => MyEnum.Value_2;
910 AssertNodeType (e11, ExpressionType.Constant);
911 Assert (MyEnum.Value_2, e11.Compile ().Invoke ());
914 void ConstantTest_13 ()
916 Expression<Func<int>> e13 = () => sizeof (byte);
917 AssertNodeType (e13, ExpressionType.Constant);
918 Assert (1, e13.Compile ().Invoke ());
922 //unsafe void ConstantTest_14 ()
924 // Expression<Func<Type>> e14 = () => typeof (bool*);
925 // AssertNodeType (e14, ExpressionType.Constant);
926 // Assert (typeof (bool*), e14.Compile ().Invoke ());
929 void ConstantTest_15 ()
931 Expression<Func<int?>> e15 = () => null;
932 AssertNodeType (e15, ExpressionType.Constant);
933 Assert (null, e15.Compile ().Invoke ());
936 void ConvertTest ()
938 Expression<Func<int, byte>> e = (int a) => ((byte) a);
939 AssertNodeType (e, ExpressionType.Convert);
940 Assert (100, e.Compile ().Invoke (100));
943 void ConvertTest_2 ()
945 Expression<Func<long, ushort>> e2 = (long a) => ((ushort) a);
946 AssertNodeType (e2, ExpressionType.Convert);
947 Assert (100, e2.Compile ().Invoke (100));
950 void ConvertTest_3 ()
952 Expression<Func<float?, float>> e3 = (float? a) => ((float) a);
953 AssertNodeType (e3, ExpressionType.Convert);
954 Assert (-0.456f, e3.Compile ().Invoke (-0.456f));
957 void ConvertTest_4 ()
959 Expression<Func<MyType, int>> e4 = (MyType a) => (a);
960 AssertNodeType (e4, ExpressionType.Convert);
961 Assert (-9, e4.Compile ().Invoke (new MyType (-9)));
964 void ConvertTest_5 ()
966 Expression<Func<MyType, MyType, bool?>> e5 = (MyType a, MyType b) => a == b;
967 AssertNodeType (e5, ExpressionType.Convert);
970 void ConvertTest_6 ()
972 Expression<Func<MyType?, MyType?, bool?>> e6 = (MyType? a, MyType? b) => a == b;
973 AssertNodeType (e6, ExpressionType.Convert);
974 Assert (false, e6.Compile ().Invoke (null, new MyType (-20)));
975 Assert (true, e6.Compile ().Invoke (null, null));
976 Assert (true, e6.Compile ().Invoke (new MyType (120), new MyType (120)));
979 void ConvertTest_7 ()
981 Expression<Func<MyTypeExplicit, int?>> e7 = x => (int?)x;
982 AssertNodeType (e7, ExpressionType.Convert);
983 Assert (33, e7.Compile ().Invoke (new MyTypeExplicit (33)));
986 void ConvertTest_8 ()
988 Expression<Func<int?, object>> e8 = x => (object)x;
989 AssertNodeType (e8, ExpressionType.Convert);
990 Assert (null, e8.Compile ().Invoke (null));
991 Assert (-100, e8.Compile ().Invoke (-100));
994 //unsafe void ConvertTest_9 ()
996 // int*[] p = new int* [1];
997 // Expression<Func<object>> e9 = () => (object)p;
998 // AssertNodeType (e9, ExpressionType.Convert);
999 // Assert (p, e9.Compile ().Invoke ());
1002 void ConvertTest_10 ()
1004 Expression<Func<Func<int>, Delegate>> e10 = (a) => a + a;
1005 AssertNodeType (e10, ExpressionType.Convert);
1006 Assert (null, e10.Compile ().Invoke (null));
1007 Assert (new Func<int> (TestInt) + new Func<int> (TestInt), e10.Compile ().Invoke (TestInt));
1010 void ConvertTest_11 ()
1012 Expression<Func<Func<int>, Delegate>> e11 = (a) => a - a;
1013 AssertNodeType (e11, ExpressionType.Convert);
1014 Assert (null, e11.Compile ().Invoke (null));
1017 void ConvertTest_12 ()
1019 Expression<Func<Func<int>>> e12 = () => TestInt;
1020 AssertNodeType (e12, ExpressionType.Convert);
1021 Assert (29, e12.Compile ().Invoke () ());
1024 void ConvertTest_13 ()
1026 Expression<Func<decimal, sbyte>> e13 = a => (sbyte)a;
1027 AssertNodeType (e13, ExpressionType.Convert);
1028 Assert (6, e13.Compile ().Invoke (6));
1031 void ConvertTest_14 ()
1033 Expression<Func<long, decimal>> e14 = a => a;
1034 AssertNodeType (e14, ExpressionType.Convert);
1035 Assert (-66, e14.Compile ().Invoke (-66));
1038 void ConvertTest_15 ()
1040 Expression<Func<ulong?, decimal?>> e15 = a => a;
1041 AssertNodeType (e15, ExpressionType.Convert);
1042 Assert (null, e15.Compile ().Invoke (null));
1043 Assert (9, e15.Compile ().Invoke (9));
1046 void ConvertCheckedTest ()
1048 Expression<Func<int, byte>> e = (int a) => checked((byte) a);
1049 AssertNodeType (e, ExpressionType.ConvertChecked);
1050 Assert (100, e.Compile ().Invoke (100));
1053 void ConvertCheckedTest_2 ()
1055 checked {
1056 Expression<Func<long, ushort>> e2 = (long a) => unchecked((ushort) a);
1057 AssertNodeType (e2, ExpressionType.Convert);
1058 Assert (100, e2.Compile ().Invoke (100));
1062 void ConvertCheckedTest_3 ()
1064 checked {
1065 Expression<Func<float?, float>> e3 = (float? a) => ((float) a);
1066 AssertNodeType (e3, ExpressionType.ConvertChecked);
1067 Assert (-0.456f, e3.Compile ().Invoke (-0.456f));
1071 void ConvertCheckedTest_4 ()
1073 checked {
1074 Expression<Func<MyType, int>> e4 = (MyType a) => (a);
1075 AssertNodeType (e4, ExpressionType.Convert);
1076 Assert (-9, e4.Compile ().Invoke (new MyType (-9)));
1080 void DivideTest ()
1082 Expression<Func<int, int, int>> e = (int a, int b) => a / b;
1083 AssertNodeType (e, ExpressionType.Divide);
1084 Assert (2, e.Compile ().Invoke (60, 30));
1087 void DivideTest_2 ()
1089 Expression<Func<double?, double?, double?>> e2 = (a, b) => a / b;
1090 AssertNodeType (e2, ExpressionType.Divide);
1091 Assert (null, e2.Compile ().Invoke (null, 3));
1092 Assert (1.5, e2.Compile ().Invoke (3, 2));
1095 void DivideTest_3 ()
1097 Expression<Func<MyType, MyType, MyType>> e3 = (MyType a, MyType b) => a / b;
1098 AssertNodeType (e3, ExpressionType.Divide);
1099 Assert (1, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1102 void DivideTest_4 ()
1104 Expression<Func<MyType?, MyType?, MyType?>> e4 = (MyType? a, MyType? b) => a / b;
1105 AssertNodeType (e4, ExpressionType.Divide);
1106 Assert (null, e4.Compile ().Invoke (null, new MyType (-20)));
1107 Assert (new MyType (-6), e4.Compile ().Invoke (new MyType (120), new MyType (-20)));
1110 void DivideTest_5 ()
1112 Expression<Func<int, MyType, int>> e5 = (int a, MyType b) => a / b;
1113 AssertNodeType (e5, ExpressionType.Divide);
1114 Assert (50, e5.Compile ().Invoke (100, new MyType (2)));
1117 void DivideTest_6 ()
1119 Expression<Func<int, MyType?, int?>> e6 = (int a, MyType? b) => a / b;
1120 AssertNodeType (e6, ExpressionType.Divide);
1121 Assert (50, e6.Compile ().Invoke (100, new MyType (2)));
1122 Assert (null, e6.Compile ().Invoke (20, null));
1125 void EqualTest ()
1127 Expression<Func<int, int, bool>> e = (int a, int b) => a == b;
1128 AssertNodeType (e, ExpressionType.Equal);
1129 Assert (false, e.Compile ().Invoke (60, 30));
1130 Assert (true, e.Compile ().Invoke (-1, -1));
1133 void EqualTest_2 ()
1135 Expression<Func<double?, double?, bool>> e2 = (a, b) => a == b;
1136 AssertNodeType (e2, ExpressionType.Equal);
1137 Assert (true, e2.Compile ().Invoke (3, 3));
1138 Assert (false, e2.Compile ().Invoke (3, 2));
1141 void EqualTest_3 ()
1143 Expression<Func<MyType, MyType, bool>> e3 = (MyType a, MyType b) => a == b;
1144 AssertNodeType (e3, ExpressionType.Equal);
1145 Assert (true, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1148 void EqualTest_4 ()
1150 Expression<Func<MyType?, MyType?, bool>> e4 = (MyType? a, MyType? b) => a == b;
1151 AssertNodeType (e4, ExpressionType.Equal);
1152 Assert (false, e4.Compile ().Invoke (null, new MyType (-20)));
1153 Assert (true, e4.Compile ().Invoke (null, null));
1154 Assert (true, e4.Compile ().Invoke (new MyType (120), new MyType (120)));
1157 void EqualTest_5 ()
1159 Expression<Func<bool?, bool?, bool>> e5 = (bool? a, bool? b) => a == b;
1160 AssertNodeType (e5, ExpressionType.Equal);
1161 Assert (false, e5.Compile ().Invoke (true, null));
1162 Assert (true, e5.Compile ().Invoke (null, null));
1163 Assert (true, e5.Compile ().Invoke (false, false));
1166 void EqualTest_6 ()
1168 Expression<Func<bool, bool>> e6 = (bool a) => a == null;
1169 AssertNodeType (e6, ExpressionType.Equal);
1170 Assert (false, e6.Compile ().Invoke (true));
1171 Assert (false, e6.Compile ().Invoke (false));
1174 void EqualTest_7 ()
1176 Expression<Func<string, string, bool>> e7 = (string a, string b) => a == b;
1177 AssertNodeType (e7, ExpressionType.Equal);
1178 Assert (true, e7.Compile ().Invoke (null, null));
1179 Assert (false, e7.Compile ().Invoke ("a", "A"));
1180 Assert (true, e7.Compile ().Invoke ("a", "a"));
1183 void EqualTest_8 ()
1185 Expression<Func<object, bool>> e8 = (object a) => null == a;
1186 AssertNodeType (e8, ExpressionType.Equal);
1187 Assert (true, e8.Compile ().Invoke (null));
1188 Assert (false, e8.Compile ().Invoke ("a"));
1189 Assert (false, e8.Compile ().Invoke (this));
1192 void EqualTest_9 ()
1194 Expression<Func<MyEnum, MyEnum, bool>> e9 = (a, b) => a == b;
1195 AssertNodeType (e9, ExpressionType.Equal);
1196 Assert (false, e9.Compile ().Invoke (MyEnum.Value_1, MyEnum.Value_2));
1197 Assert (true, e9.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1200 void EqualTest_10 ()
1202 Expression<Func<MyEnum?, MyEnum?, bool>> e10 = (a, b) => a == b;
1203 AssertNodeType (e10, ExpressionType.Equal);
1204 Assert (false, e10.Compile ().Invoke (MyEnum.Value_1, null));
1205 Assert (true, e10.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1208 void EqualTest_11 ()
1210 Expression<Func<MyEnum?, bool>> e11 = (a) => a == null;
1211 AssertNodeType (e11, ExpressionType.Equal);
1212 Assert (false, e11.Compile ().Invoke (MyEnum.Value_1));
1213 Assert (true, e11.Compile ().Invoke (null));
1216 void EqualTest_12 ()
1218 Expression<Func<MyEnumUlong, bool>> e12 = (a) => a == 0;
1219 AssertNodeType (e12, ExpressionType.Equal);
1220 Assert (false, e12.Compile ().Invoke (MyEnumUlong.Value_1));
1221 Assert (true, e12.Compile ().Invoke (0));
1224 void EqualTest_13 ()
1226 Expression<Func<MyEnum, bool>> e13 = (a) => a == MyEnum.Value_2;
1227 AssertNodeType (e13, ExpressionType.Equal);
1228 Assert (true, e13.Compile ().Invoke (MyEnum.Value_2));
1229 Assert (false, e13.Compile ().Invoke (0));
1232 void EqualTest_14 ()
1234 Expression<Func<MyEnum, bool>> e = (a) => a == null;
1235 AssertNodeType (e, ExpressionType.Equal);
1236 Assert (false, e.Compile ().Invoke (MyEnum.Value_1));
1239 void EqualTest_15 ()
1241 Expression<Func<int?, uint, bool>> e = (a, b) => a == b;
1242 AssertNodeType (e, ExpressionType.Equal);
1243 Assert (false, e.Compile ().Invoke (null, 0));
1244 Assert (true, e.Compile ().Invoke (4, 4));
1247 void EqualTestDelegate ()
1249 Expression<Func<Delegate, Delegate, bool>> e1 = (a, b) => a == b;
1250 AssertNodeType (e1, ExpressionType.Equal);
1251 Assert (true, e1.Compile ().Invoke (null, null));
1254 void EqualTestDelegate_2 ()
1256 EmptyDelegate ed = delegate () {};
1258 Expression<Func<EmptyDelegate, EmptyDelegate, bool>> e2 = (a, b) => a == b;
1259 AssertNodeType (e2, ExpressionType.Equal);
1260 Assert (false, e2.Compile ().Invoke (delegate () {}, null));
1261 Assert (false, e2.Compile ().Invoke (delegate () {}, delegate {}));
1262 Assert (false, e2.Compile ().Invoke (ed, delegate {}));
1263 Assert (true, e2.Compile ().Invoke (ed, ed));
1266 void ExclusiveOrTest ()
1268 Expression<Func<int, short, int>> e = (int a, short b) => a ^ b;
1269 AssertNodeType (e, ExpressionType.ExclusiveOr);
1270 Assert (34, e.Compile ().Invoke (60, 30));
1273 void ExclusiveOrTest_2 ()
1275 Expression<Func<byte?, byte?, int?>> e2 = (a, b) => a ^ b;
1276 AssertNodeType (e2, ExpressionType.ExclusiveOr);
1277 Assert (null, e2.Compile ().Invoke (null, 3));
1278 Assert (1, e2.Compile ().Invoke (3, 2));
1281 void ExclusiveOrTest_3 ()
1283 Expression<Func<MyType, MyType, MyType>> e3 = (MyType a, MyType b) => a ^ b;
1284 AssertNodeType (e3, ExpressionType.ExclusiveOr);
1285 Assert (0, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1288 void ExclusiveOrTest_4 ()
1290 Expression<Func<MyType?, MyType?, MyType?>> e4 = (MyType? a, MyType? b) => a ^ b;
1291 AssertNodeType (e4, ExpressionType.ExclusiveOr);
1292 Assert (null, e4.Compile ().Invoke (null, new MyType (-20)));
1293 Assert (new MyType (-108), e4.Compile ().Invoke (new MyType (120), new MyType (-20)));
1296 void ExclusiveOrTest_5 ()
1298 Expression<Func<MyType?, byte, int?>> e5 = (MyType? a, byte b) => a ^ b;
1299 AssertNodeType (e5, ExpressionType.ExclusiveOr);
1300 Assert (null, e5.Compile ().Invoke (null, 64));
1301 Assert (96, e5.Compile ().Invoke (new MyType (64), 32));
1304 void ExclusiveOrTest_6 ()
1306 Expression<Func<MyEnum, MyEnum, MyEnum>> e6 = (a, b) => a ^ b;
1307 AssertNodeType (e6, ExpressionType.Convert);
1308 Assert ((MyEnum)3, e6.Compile ().Invoke (MyEnum.Value_1, MyEnum.Value_2));
1309 Assert<MyEnum> (0, e6.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1312 void ExclusiveOrTest_7 ()
1314 Expression<Func<MyEnum?, MyEnum?, MyEnum?>> e7 = (a, b) => a ^ b;
1315 AssertNodeType (e7, ExpressionType.Convert);
1316 Assert (null, e7.Compile ().Invoke (MyEnum.Value_1, null));
1317 Assert<MyEnum?> (0, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1320 void ExclusiveOrTest_8 ()
1322 Expression<Func<MyEnum?, MyEnum?>> e8 = (a) => a ^ null;
1323 AssertNodeType (e8, ExpressionType.Convert);
1324 Assert (null, e8.Compile ().Invoke (MyEnum.Value_1));
1325 Assert (null, e8.Compile ().Invoke (null));
1328 void GreaterThanTest ()
1330 Expression<Func<int, int, bool>> e = (int a, int b) => a > b;
1331 AssertNodeType (e, ExpressionType.GreaterThan);
1332 Assert (true, e.Compile ().Invoke (60, 30));
1335 void GreaterThanTest_2 ()
1337 Expression<Func<uint?, byte?, bool>> e2 = (a, b) => a > b;
1338 AssertNodeType (e2, ExpressionType.GreaterThan);
1339 Assert (false, e2.Compile ().Invoke (null, 3));
1340 Assert (false, e2.Compile ().Invoke (2, 2));
1343 void GreaterThanTest_3 ()
1345 Expression<Func<MyType, MyType, bool>> e3 = (MyType a, MyType b) => a > b;
1346 AssertNodeType (e3, ExpressionType.GreaterThan);
1347 Assert (false, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1350 void GreaterThanTest_4 ()
1352 Expression<Func<MyType?, MyType?, bool>> e4 = (MyType? a, MyType? b) => a > b;
1353 AssertNodeType (e4, ExpressionType.GreaterThan);
1354 Assert (false, e4.Compile ().Invoke (null, new MyType (-20)));
1355 Assert (false, e4.Compile ().Invoke (null, null));
1356 Assert (true, e4.Compile ().Invoke (new MyType (120), new MyType (-20)));
1359 void GreaterThanTest_5 ()
1361 Expression<Func<MyType?, sbyte, bool>> e5 = (MyType? a, sbyte b) => a > b;
1362 AssertNodeType (e5, ExpressionType.GreaterThan);
1363 Assert (false, e5.Compile ().Invoke (null, 33));
1364 Assert (false, e5.Compile ().Invoke (null, 0));
1365 Assert (true, e5.Compile ().Invoke (new MyType (120), 3));
1368 void GreaterThanTest_6 ()
1370 Expression<Func<ushort, bool>> e6 = (ushort a) => a > null;
1371 AssertNodeType (e6, ExpressionType.GreaterThan);
1372 Assert (false, e6.Compile ().Invoke (60));
1375 void GreaterThanTest_7 ()
1377 Expression<Func<MyEnum, MyEnum, bool>> e7 = (a, b) => a > b;
1378 AssertNodeType (e7, ExpressionType.GreaterThan);
1379 Assert (true, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_1));
1380 Assert (false, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1383 void GreaterThanTest_8 ()
1385 Expression<Func<MyEnum?, MyEnum?, bool>> e8 = (a, b) => a > b;
1386 AssertNodeType (e8, ExpressionType.GreaterThan);
1387 Assert (false, e8.Compile ().Invoke (MyEnum.Value_1, null));
1388 Assert (false, e8.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1391 void GreaterThanOrEqualTest ()
1393 Expression<Func<int, int, bool>> e = (int a, int b) => a >= b;
1394 AssertNodeType (e, ExpressionType.GreaterThanOrEqual);
1395 Assert (true, e.Compile ().Invoke (60, 30));
1398 void GreaterThanOrEqualTest_2 ()
1400 Expression<Func<byte?, byte?, bool>> e2 = (a, b) => a >= b;
1401 AssertNodeType (e2, ExpressionType.GreaterThanOrEqual);
1402 Assert (false, e2.Compile ().Invoke (null, 3));
1403 Assert (true, e2.Compile ().Invoke (2, 2));
1406 void GreaterThanOrEqualTest_3 ()
1408 Expression<Func<MyType, MyType, bool>> e3 = (MyType a, MyType b) => a >= b;
1409 AssertNodeType (e3, ExpressionType.GreaterThanOrEqual);
1410 Assert (true, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)), "D1");
1413 void GreaterThanOrEqualTest_4 ()
1415 Expression<Func<MyType?, MyType?, bool>> e4 = (MyType? a, MyType? b) => a >= b;
1416 AssertNodeType (e4, ExpressionType.GreaterThanOrEqual);
1417 Assert (false, e4.Compile ().Invoke (null, new MyType (-20)));
1418 Assert (false, e4.Compile ().Invoke (null, null));
1419 Assert (true, e4.Compile ().Invoke (new MyType (120), new MyType (-20)));
1422 void GreaterThanOrEqualTest_5 ()
1424 Expression<Func<MyType?, sbyte, bool>> e5 = (MyType? a, sbyte b) => a >= b;
1425 AssertNodeType (e5, ExpressionType.GreaterThanOrEqual);
1426 Assert (false, e5.Compile ().Invoke (null, 33));
1427 Assert (false, e5.Compile ().Invoke (null, 0));
1428 Assert (true, e5.Compile ().Invoke (new MyType (120), 3));
1431 void GreaterThanOrEqualTest_6 ()
1433 Expression<Func<ushort, bool>> e6 = (ushort a) => a >= null;
1434 AssertNodeType (e6, ExpressionType.GreaterThanOrEqual);
1435 Assert (false, e6.Compile ().Invoke (60));
1438 void GreaterThanOrEqualTest_7 ()
1440 Expression<Func<MyEnum, MyEnum, bool>> e7 = (a, b) => a >= b;
1441 AssertNodeType (e7, ExpressionType.GreaterThanOrEqual);
1442 Assert (true, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_1));
1443 Assert (true, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1446 void GreaterThanOrEqualTest_8 ()
1448 Expression<Func<MyEnum?, MyEnum?, bool>> e8 = (a, b) => a >= b;
1449 AssertNodeType (e8, ExpressionType.GreaterThanOrEqual);
1450 Assert (false, e8.Compile ().Invoke (MyEnum.Value_1, null));
1451 Assert (true, e8.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1454 void InvokeTest ()
1456 var del = new IntDelegate (TestInt);
1457 Expression<Func<IntDelegate, int>> e = (a) => a ();
1458 AssertNodeType (e, ExpressionType.Invoke);
1459 Assert (29, e.Compile ().Invoke (del));
1462 void InvokeTest_2 ()
1464 Expression<Func<Func<int, string>, int, string>> e2 = (a, b) => a (b);
1465 AssertNodeType (e2, ExpressionType.Invoke);
1466 Assert ("4", e2.Compile ().Invoke ((a) => (a+1).ToString (), 3));
1469 void LambdaTest ()
1471 Expression<Func<string, Func<string>>> e = (string s) => () => s;
1472 AssertNodeType (e, ExpressionType.Lambda);
1473 Assert ("xx", e.Compile ().Invoke ("xx") ());
1476 void LeftShiftTest ()
1478 Expression<Func<ulong, short, ulong>> e = (ulong a, short b) => a << b;
1479 AssertNodeType (e, ExpressionType.LeftShift);
1480 Assert ((ulong) 0x7F000, e.Compile ().Invoke (0xFE, 11));
1481 Assert ((ulong) 0x1FFFFFFFE, e.Compile ().Invoke (0xFFFFFFFF, 0xA01));
1483 // .net produces a strange result
1484 // see https://bugzilla.novell.com/show_bug.cgi?id=398358
1485 // Assert ((ulong) 0xFFFFFFFE00000000, e.Compile ().Invoke (0xFFFFFFFF, 0xA01));
1488 void LeftShiftTest_2 ()
1490 Expression<Func<MyType, MyType, int>> e2 = (MyType a, MyType b) => a << b;
1491 AssertNodeType (e2, ExpressionType.LeftShift);
1492 var c2 = e2.Compile ();
1493 Assert (1024, c2 (new MyType (256), new MyType (2)));
1496 void LeftShiftTest_3 ()
1498 Expression<Func<long?, sbyte, long?>> e3 = (long? a, sbyte b) => a << b;
1499 AssertNodeType (e3, ExpressionType.LeftShift);
1500 Assert (null, e3.Compile ().Invoke (null, 11));
1501 Assert (2048, e3.Compile ().Invoke (1024, 1));
1504 void LeftShiftTest_4 ()
1506 Expression<Func<MyType?, MyType?, int?>> e4 = (MyType? a, MyType? b) => a << b;
1507 AssertNodeType (e4, ExpressionType.LeftShift);
1508 var c4 = e4.Compile ();
1509 Assert (null, c4 (new MyType (8), null));
1510 Assert (null, c4 (null, new MyType (8)));
1511 Assert (1024, c4 (new MyType (256), new MyType (2)));
1514 void LeftShiftTest_5 ()
1516 Expression<Func<ushort, int?>> e5 = (ushort a) => a << null;
1517 AssertNodeType (e5, ExpressionType.LeftShift);
1518 Assert (null, e5.Compile ().Invoke (30));
1521 void LessThanTest ()
1523 Expression<Func<int, int, bool>> e = (int a, int b) => a < b;
1524 AssertNodeType (e, ExpressionType.LessThan);
1525 Assert (false, e.Compile ().Invoke (60, 30));
1528 void LessThanTest_2 ()
1530 Expression<Func<uint?, byte?, bool>> e2 = (a, b) => a < b;
1531 AssertNodeType (e2, ExpressionType.LessThan);
1532 Assert (false, e2.Compile ().Invoke (null, 3));
1533 Assert (false, e2.Compile ().Invoke (2, 2));
1536 void LessThanTest_3 ()
1538 Expression<Func<MyType, MyType, bool>> e3 = (MyType a, MyType b) => a < b;
1539 AssertNodeType (e3, ExpressionType.LessThan);
1540 Assert (false, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1543 void LessThanTest_4 ()
1545 Expression<Func<MyType?, MyType?, bool>> e4 = (MyType? a, MyType? b) => a < b;
1546 AssertNodeType (e4, ExpressionType.LessThan);
1547 Assert (false, e4.Compile ().Invoke (null, new MyType (-20)));
1548 Assert (false, e4.Compile ().Invoke (null, null));
1549 Assert (false, e4.Compile ().Invoke (new MyType (120), new MyType (-20)));
1552 void LessThanTest_5 ()
1554 Expression<Func<MyType?, sbyte, bool>> e5 = (MyType? a, sbyte b) => a < b;
1555 AssertNodeType (e5, ExpressionType.LessThan);
1556 Assert (false, e5.Compile ().Invoke (null, 33));
1557 Assert (false, e5.Compile ().Invoke (null, 0));
1558 Assert (false, e5.Compile ().Invoke (new MyType (120), 3));
1561 void LessThanTest_6 ()
1563 Expression<Func<ushort, bool>> e6 = (ushort a) => a < null;
1564 AssertNodeType (e6, ExpressionType.LessThan);
1565 Assert (false, e6.Compile ().Invoke (60));
1568 void LessThanTest_7 ()
1570 Expression<Func<MyEnum, MyEnum, bool>> e7 = (a, b) => a < b;
1571 AssertNodeType (e7, ExpressionType.LessThan);
1572 Assert (false, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_1));
1573 Assert (false, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1576 void LessThanTest_8 ()
1578 Expression<Func<MyEnum?, MyEnum?, bool>> e8 = (a, b) => a < b;
1579 AssertNodeType (e8, ExpressionType.LessThan);
1580 Assert (false, e8.Compile ().Invoke (MyEnum.Value_1, null));
1581 Assert (false, e8.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1584 void LessThanOrEqualTest ()
1586 Expression<Func<int, int, bool>> e = (int a, int b) => a <= b;
1587 AssertNodeType (e, ExpressionType.LessThanOrEqual);
1588 Assert (false, e.Compile ().Invoke (60, 30));
1591 void LessThanOrEqualTest_2 ()
1593 Expression<Func<byte?, byte?, bool>> e2 = (a, b) => a <= b;
1594 AssertNodeType (e2, ExpressionType.LessThanOrEqual);
1595 Assert (false, e2.Compile ().Invoke (null, 3));
1596 Assert (true, e2.Compile ().Invoke (2, 2));
1599 void LessThanOrEqualTest_3 ()
1601 Expression<Func<MyType, MyType, bool>> e3 = (MyType a, MyType b) => a <= b;
1602 AssertNodeType (e3, ExpressionType.LessThanOrEqual);
1603 Assert (true, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1606 void LessThanOrEqualTest_4 ()
1608 Expression<Func<MyType?, MyType?, bool>> e4 = (MyType? a, MyType? b) => a <= b;
1609 AssertNodeType (e4, ExpressionType.LessThanOrEqual);
1610 Assert (false, e4.Compile ().Invoke (null, new MyType (-20)));
1611 Assert (false, e4.Compile ().Invoke (null, null));
1612 Assert (false, e4.Compile ().Invoke (new MyType (120), new MyType (-20)));
1615 void LessThanOrEqualTest_5 ()
1617 Expression<Func<MyType?, sbyte, bool>> e5 = (MyType? a, sbyte b) => a <= b;
1618 AssertNodeType (e5, ExpressionType.LessThanOrEqual);
1619 Assert (false, e5.Compile ().Invoke (null, 33));
1620 Assert (false, e5.Compile ().Invoke (null, 0));
1621 Assert (false, e5.Compile ().Invoke (new MyType (120), 3));
1624 void LessThanOrEqualTest_6 ()
1626 Expression<Func<ushort, bool>> e6 = (ushort a) => a <= null;
1627 AssertNodeType (e6, ExpressionType.LessThanOrEqual);
1628 Assert (false, e6.Compile ().Invoke (60));
1631 void LessThanOrEqualTest_7 ()
1633 Expression<Func<MyEnum, MyEnum, bool>> e7 = (a, b) => a <= b;
1634 AssertNodeType (e7, ExpressionType.LessThanOrEqual);
1635 Assert (false, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_1));
1636 Assert (true, e7.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1639 void LessThanOrEqualTest_8 ()
1641 Expression<Func<MyEnum?, MyEnum?, bool>> e8 = (a, b) => a <= b;
1642 AssertNodeType (e8, ExpressionType.LessThanOrEqual);
1643 Assert (false, e8.Compile ().Invoke (MyEnum.Value_1, null));
1644 Assert (true, e8.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
1647 void ListInitTest ()
1649 Expression<Func<List<object>>> e1 = () => new List<object> { "Hello", "", null, "World", 5 };
1650 AssertNodeType (e1, ExpressionType.ListInit);
1651 var re1 = e1.Compile ().Invoke ();
1652 Assert (null, re1 [2]);
1653 Assert ("World", re1 [3]);
1654 Assert (5, re1 [4]);
1657 void ListInitTest_2 ()
1659 Expression<Func<int, Dictionary<string, int>>> e2 = (int value) => new Dictionary<string, int> (3) { { "A", value }, { "B", 2 } };
1660 AssertNodeType (e2, ExpressionType.ListInit);
1661 var re2 = e2.Compile ().Invoke (3456);
1662 Assert (3456, re2 ["A"]);
1665 void MemberAccessTest ()
1667 MemberAccessData d = new MemberAccessData ();
1668 d.BoolValue = true;
1669 Expression<Func<bool>> e = () => d.BoolValue;
1670 AssertNodeType (e, ExpressionType.MemberAccess);
1671 Assert (true, e.Compile ().Invoke ());
1672 d.BoolValue = false;
1673 Assert (false, e.Compile ().Invoke ());
1676 void MemberAccessTest_2 ()
1678 Expression<Func<decimal>> e2 = () => MemberAccessData.DecimalValue;
1679 AssertNodeType (e2, ExpressionType.MemberAccess);
1680 Assert (decimal.MinValue, e2.Compile ().Invoke ());
1683 void MemberAccessTest_3 ()
1685 MemberAccessData d = new MemberAccessData ();
1686 d.VolatileValue = 492;
1687 Expression<Func<uint>> e3 = () => d.VolatileValue;
1688 AssertNodeType (e3, ExpressionType.MemberAccess);
1689 Assert<uint> (492, e3.Compile ().Invoke ());
1692 void MemberAccessTest_4 ()
1694 MemberAccessData d = new MemberAccessData ();
1695 Expression<Func<string[]>> e4 = () => d.StringValues;
1696 AssertNodeType (e4, ExpressionType.MemberAccess);
1697 Assert (null, e4.Compile ().Invoke ());
1700 void MemberAccessTest_5 ()
1702 MemberAccessData d = new MemberAccessData ();
1703 var e5 = d.GetEvent ();
1704 AssertNodeType (e5, ExpressionType.MemberAccess);
1705 Assert (null, e5.Compile ().Invoke ());
1708 void MemberAccessTest_6 ()
1710 MemberAccessData d = new MemberAccessData ();
1711 Expression<Func<MyType>> e6 = () => d.MyTypeProperty;
1712 AssertNodeType (e6, ExpressionType.MemberAccess);
1713 Assert (new MyType (), e6.Compile ().Invoke ());
1716 void MemberAccessTest_7 ()
1718 MemberAccessData d = new MemberAccessData ();
1719 Expression<Func<MyType, short>> e7 = a => a.ShortProp;
1720 AssertNodeType (e7, ExpressionType.MemberAccess);
1721 MyType mt = new MyType ();
1722 mt.ShortProp = 124;
1723 Assert (124, e7.Compile ().Invoke (mt));
1726 void MemberAccessTest_8 ()
1728 Expression<Func<string>> e8 = () => MemberAccessData.StaticProperty;
1729 AssertNodeType (e8, ExpressionType.MemberAccess);
1730 Assert ("alo", e8.Compile ().Invoke ());
1733 void MemberAccessTest_9 ()
1735 string s = "localvar";
1736 Expression<Func<string>> e9 = () => s;
1737 AssertNodeType (e9, ExpressionType.MemberAccess);
1738 Assert ("localvar", e9.Compile ().Invoke ());
1741 void MemberInitTest ()
1743 Expression<Func<MemberAccessData>> e = () => new MemberAccessData {
1744 VolatileValue = 2, StringValues = new string [] { "sv" }, MyTypeProperty = new MyType (692)
1746 AssertNodeType (e, ExpressionType.MemberInit);
1747 var r1 = e.Compile ().Invoke ();
1748 Assert<uint> (2, r1.VolatileValue);
1749 Assert (new string[] { "sv" }, r1.StringValues);
1750 Assert (new MyType (692), r1.MyTypeProperty);
1753 void MemberInitTest_2 ()
1755 Expression<Func<MemberAccessData>> e2 = () => new MemberAccessData {
1756 ListValues = new List<string> { "a", null }
1759 AssertNodeType (e2, ExpressionType.MemberInit);
1760 var r2 = e2.Compile ().Invoke ();
1761 Assert ("a", r2.ListValues [0]);
1764 void MemberInitTest_3 ()
1766 Expression<Func<short, MyType>> e3 = a => new MyType { ShortProp = a };
1767 AssertNodeType (e3, ExpressionType.MemberInit);
1768 var r3 = e3.Compile ().Invoke (33);
1769 Assert (33, r3.ShortProp);
1772 void MemberInitTest_4 ()
1774 Expression<Func<int>> e = () => new int { };
1776 AssertNodeType (e, ExpressionType.MemberInit);
1777 var r = e.Compile ().Invoke ();
1778 Assert (0, r);
1781 void ModuloTest ()
1783 Expression<Func<int, int, int>> e = (int a, int b) => a % b;
1784 AssertNodeType (e, ExpressionType.Modulo);
1785 Assert (29, e.Compile ().Invoke (60, 31));
1788 void ModuloTest_2 ()
1790 Expression<Func<double?, double?, double?>> e2 = (a, b) => a % b;
1791 AssertNodeType (e2, ExpressionType.Modulo);
1792 Assert (null, e2.Compile ().Invoke (null, 3));
1793 Assert (1.1, e2.Compile ().Invoke (3.1, 2));
1796 void ModuloTest_3 ()
1798 Expression<Func<MyType, MyType, MyType>> e3 = (MyType a, MyType b) => a % b;
1799 AssertNodeType (e3, ExpressionType.Modulo);
1800 Assert (0, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1803 void ModuloTest_4 ()
1805 Expression<Func<MyType?, MyType?, MyType?>> e4 = (MyType? a, MyType? b) => a % b;
1806 AssertNodeType (e4, ExpressionType.Modulo);
1807 Assert (null, e4.Compile ().Invoke (null, new MyType (-20)));
1808 Assert (new MyType (12), e4.Compile ().Invoke (new MyType (12), new MyType (-20)));
1811 void ModuloTest_5 ()
1813 Expression<Func<int, MyType, int>> e5 = (int a, MyType b) => a % b;
1814 AssertNodeType (e5, ExpressionType.Modulo);
1815 Assert (1, e5.Compile ().Invoke (99, new MyType (2)));
1818 void ModuloTest_6 ()
1820 Expression<Func<int, MyType?, int?>> e6 = (int a, MyType? b) => a % b;
1821 AssertNodeType (e6, ExpressionType.Modulo);
1822 Assert (100, e6.Compile ().Invoke (100, new MyType (200)));
1823 Assert (null, e6.Compile ().Invoke (20, null));
1826 void ModuloTest_7 ()
1828 Expression<Func<ushort, int?>> e7 = (ushort a) => a % null;
1829 AssertNodeType (e7, ExpressionType.Modulo);
1830 Assert (null, e7.Compile ().Invoke (60));
1833 void MultiplyTest ()
1835 Expression<Func<int, int, int>> e = (int a, int b) => a * b;
1836 AssertNodeType (e, ExpressionType.Multiply);
1837 Assert (1860, e.Compile ().Invoke (60, 31));
1838 Assert (2147483617, e.Compile ().Invoke (int.MaxValue, 31));
1841 void MultiplyTest_2 ()
1843 Expression<Func<double?, double?, double?>> e2 = (a, b) => a * b;
1844 AssertNodeType (e2, ExpressionType.Multiply);
1845 Assert (null, e2.Compile ().Invoke (null, 3));
1846 Assert (6.2, e2.Compile ().Invoke (3.1, 2));
1849 void MultiplyTest_3 ()
1851 Expression<Func<MyType, MyType, MyType>> e3 = (MyType a, MyType b) => a * b;
1852 AssertNodeType (e3, ExpressionType.Multiply);
1853 Assert (400, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
1856 void MultiplyTest_4 ()
1858 Expression<Func<MyType?, MyType?, MyType?>> e4 = (MyType? a, MyType? b) => a * b;
1859 AssertNodeType (e4, ExpressionType.Multiply);
1860 Assert (null, e4.Compile ().Invoke (null, new MyType (-20)));
1861 Assert (new MyType (-240), e4.Compile ().Invoke (new MyType (12), new MyType (-20)));
1864 void MultiplyTest_5 ()
1866 Expression<Func<int, MyType, int>> e5 = (int a, MyType b) => a * b;
1867 AssertNodeType (e5, ExpressionType.Multiply);
1868 Assert (198, e5.Compile ().Invoke (99, new MyType (2)));
1871 void MultiplyTest_6 ()
1873 Expression<Func<int, MyType?, int?>> e6 = (int a, MyType? b) => a * b;
1874 AssertNodeType (e6, ExpressionType.Multiply);
1875 Assert (0, e6.Compile ().Invoke (int.MinValue, new MyType (200)));
1876 Assert (null, e6.Compile ().Invoke (20, null));
1879 void MultiplyTest_7 ()
1881 Expression<Func<ushort, int?>> e7 = (ushort a) => a * null;
1882 AssertNodeType (e7, ExpressionType.Multiply);
1883 Assert (null, e7.Compile ().Invoke (60));
1886 void MultiplyCheckedTest ()
1888 checked {
1889 Expression<Func<int, int, int>> e = (int a, int b) => a * b;
1890 AssertNodeType (e, ExpressionType.MultiplyChecked);
1891 try {
1892 e.Compile ().Invoke (int.MaxValue, 309);
1893 throw new ApplicationException ("MultiplyCheckedTest #1");
1894 } catch (OverflowException) { }
1898 void MultiplyCheckedTest_2 ()
1900 checked {
1901 Expression<Func<byte?, byte?, int?>> e2 = (a, b) => a * b;
1902 AssertNodeType (e2, ExpressionType.MultiplyChecked);
1903 Assert (null, e2.Compile ().Invoke (null, 3));
1904 Assert (14025, e2.Compile ().Invoke (byte.MaxValue, 55));
1908 void MultiplyCheckedTest_3 ()
1910 checked {
1911 Expression<Func<MyType, MyType, MyType>> e3 = (MyType a, MyType b) => a * b;
1912 AssertNodeType (e3, ExpressionType.Multiply);
1913 Assert (-600, e3.Compile ().Invoke (new MyType (-20), new MyType (30)));
1917 void MultiplyCheckedTest_4 ()
1919 checked {
1920 Expression<Func<double, double, double>> e4 = (a, b) => a * b;
1921 AssertNodeType (e4, ExpressionType.Multiply);
1922 Assert (double.PositiveInfinity, e4.Compile ().Invoke (double.MaxValue, int.MaxValue));
1926 void MultiplyCheckedTest_5 ()
1928 checked {
1929 Expression<Func<float?, float?, float?>> e5 = (a, b) => b * a;
1930 AssertNodeType (e5, ExpressionType.MultiplyChecked);
1931 Assert (float.PositiveInfinity, e5.Compile ().Invoke (float.Epsilon, float.PositiveInfinity));
1935 void NegateTest ()
1937 Expression<Func<int, int>> e = (a) => -a;
1938 AssertNodeType (e, ExpressionType.Negate);
1939 Assert (30, e.Compile ().Invoke (-30));
1942 void NegateTest_2 ()
1944 Expression<Func<sbyte, int>> e2 = (a) => -(-a);
1945 AssertNodeType (e2, ExpressionType.Negate);
1946 Assert (-10, e2.Compile ().Invoke (-10));
1949 void NegateTest_3 ()
1951 Expression<Func<long?, long?>> e3 = (a) => -a;
1952 AssertNodeType (e3, ExpressionType.Negate);
1953 Assert (long.MinValue + 1, e3.Compile ().Invoke (long.MaxValue));
1954 Assert (null, e3.Compile ().Invoke (null));
1957 void NegateTest_4 ()
1959 Expression<Func<MyType, MyType>> e4 = (a) => -a;
1960 AssertNodeType (e4, ExpressionType.Negate);
1961 Assert (new MyType (14), e4.Compile ().Invoke (new MyType (-14)));
1964 void NegateTest_5 ()
1966 Expression<Func<MyType?, MyType?>> e5 = (a) => -a;
1967 AssertNodeType (e5, ExpressionType.Negate);
1968 Assert (new MyType (-33), e5.Compile ().Invoke (new MyType (33)));
1969 Assert (null, e5.Compile ().Invoke (null));
1972 void NegateTest_6 ()
1974 Expression<Func<MyTypeImplicitOnly, int>> e6 = (MyTypeImplicitOnly a) => -a;
1975 AssertNodeType (e6, ExpressionType.Negate);
1976 Assert (-4, e6.Compile ().Invoke (new MyTypeImplicitOnly (4)));
1979 void NegateTest_7 ()
1981 Expression<Func<MyTypeImplicitOnly?, int?>> e7 = (MyTypeImplicitOnly? a) => -a;
1982 AssertNodeType (e7, ExpressionType.Negate);
1983 Assert (-46, e7.Compile ().Invoke (new MyTypeImplicitOnly (46)));
1985 // Another version of MS bug when predefined conversion is required on nullable user operator
1986 // Assert (null, e7.Compile ().Invoke (null));
1989 void NegateTest_8 ()
1991 Expression<Func<sbyte?, int?>> e8 = (a) => -a;
1992 AssertNodeType (e8, ExpressionType.Negate);
1993 Assert (11, e8.Compile ().Invoke (-11));
1996 void NegateTest_9 ()
1998 Expression<Func<uint, long>> e9 = (a) => -a;
1999 AssertNodeType (e9, ExpressionType.Negate);
2000 Assert (-2, e9.Compile ().Invoke (2));
2003 void NegateTestChecked ()
2005 checked {
2006 Expression<Func<int, int>> e = (int a) => -a;
2007 AssertNodeType (e, ExpressionType.NegateChecked);
2008 try {
2009 e.Compile ().Invoke (int.MinValue);
2010 throw new ApplicationException ("NegateTestChecked #1");
2011 } catch (OverflowException) { }
2015 void NegateTestChecked_2 ()
2017 checked {
2018 Expression<Func<byte?, int?>> e2 = (a) => -a;
2019 AssertNodeType (e2, ExpressionType.NegateChecked);
2020 Assert (null, e2.Compile ().Invoke (null));
2021 Assert (-255, e2.Compile ().Invoke (byte.MaxValue));
2025 void NegateTestChecked_3 ()
2027 checked {
2028 Expression<Func<MyType, MyType>> e3 = (MyType a) => -a;
2029 AssertNodeType (e3, ExpressionType.Negate);
2030 Assert (20, e3.Compile ().Invoke (new MyType (-20)));
2034 void NegateTestChecked_4 ()
2036 checked {
2037 Expression<Func<double, double>> e4 = (a) => -a;
2038 AssertNodeType (e4, ExpressionType.Negate);
2039 Assert (double.NegativeInfinity, e4.Compile ().Invoke (double.PositiveInfinity));
2043 void NewArrayInitTest ()
2045 Expression<Func<int []>> e = () => new int [0];
2046 AssertNodeType (e, ExpressionType.NewArrayInit);
2047 Assert (new int [0], e.Compile ().Invoke ());
2050 void NewArrayInitTest_2 ()
2052 Expression<Func<int []>> e1 = () => new int [] { };
2053 AssertNodeType (e1, ExpressionType.NewArrayInit);
2054 Assert (new int [0], e1.Compile ().Invoke ());
2057 void NewArrayInitTest_3 ()
2059 Expression<Func<ushort, ulong? []>> e2 = (ushort a) => new ulong? [] { a };
2060 AssertNodeType (e2, ExpressionType.NewArrayInit);
2061 Assert (new ulong? [1] { ushort.MaxValue }, e2.Compile ().Invoke (ushort.MaxValue));
2064 void NewArrayInitTest_4 ()
2066 Expression<Func<char [] []>> e3 = () => new char [] [] { new char [] { 'a' } };
2067 AssertNodeType (e3, ExpressionType.NewArrayInit);
2068 Assert (new char [] { 'a' }, e3.Compile ().Invoke () [0]);
2071 void NewArrayInitTest_5 ()
2073 Expression<Func<int?[]>> e = () => new int?[] { null, 3, 4 };
2074 AssertNodeType (e, ExpressionType.NewArrayInit);
2075 Assert (3, e.Compile ().Invoke ().Length);
2078 void NewArrayInitTest_6 ()
2080 Expression<Func<string []>> e = () => new [] { null, "a" };
2081 AssertNodeType (e, ExpressionType.NewArrayInit);
2082 Assert (2, e.Compile ().Invoke ().Length);
2085 void NewArrayBoundsTest ()
2087 Expression<Func<int [,]>> e = () => new int [2,3];
2088 AssertNodeType (e, ExpressionType.NewArrayBounds);
2089 Assert (new int [2,3].Length, e.Compile ().Invoke ().Length);
2092 void NewArrayBoundsTest_2 ()
2094 Expression<Func<int[,]>> e2 = () => new int [0,0];
2095 AssertNodeType (e2, ExpressionType.NewArrayBounds);
2096 Assert (new int [0, 0].Length, e2.Compile ().Invoke ().Length);
2099 void NewTest ()
2101 Expression<Func<MyType>> e = () => new MyType (2);
2102 AssertNodeType (e, ExpressionType.New);
2103 Assert (new MyType (2), e.Compile ().Invoke ());
2106 void NewTest_2 ()
2108 Expression<Func<MyType>> e2 = () => new MyType ();
2109 AssertNodeType (e2, ExpressionType.New);
2110 Assert (new MyType (), e2.Compile ().Invoke ());
2113 void NewTest_3 ()
2115 Expression<Func<NewTest<bool>>> e3 = () => new NewTest<bool> (true);
2116 AssertNodeType (e3, ExpressionType.New);
2117 Assert (new NewTest<bool> (true), e3.Compile ().Invoke ());
2120 void NewTest_4 ()
2122 Expression<Func<decimal, NewTest<decimal>>> e4 = (decimal d) => new NewTest<decimal> (1, 5, d);
2123 AssertNodeType (e4, ExpressionType.New);
2124 Assert (new NewTest<decimal> (1, 5, -9), e4.Compile ().Invoke (-9));
2127 void NewTest_5 ()
2129 Expression<Func<object>> e5 = () => new { A = 9, Value = "a" };
2130 AssertNodeType (e5, ExpressionType.New);
2131 Assert (new { A = 9, Value = "a" }, e5.Compile ().Invoke ());
2134 // CSC bug: emits new MyEnum as a constant
2135 void NewTest_6 ()
2137 Expression<Func<MyEnum>> e = () => new MyEnum ();
2138 AssertNodeType (e, ExpressionType.New);
2139 Assert<MyEnum> (0, e.Compile ().Invoke ());
2142 void NotTest ()
2144 Expression<Func<bool, bool>> e = (bool a) => !a;
2145 AssertNodeType (e, ExpressionType.Not);
2146 Assert (false, e.Compile ().Invoke (true));
2149 void NotTest_2 ()
2151 Expression<Func<MyType, bool>> e2 = (MyType a) => !a;
2152 AssertNodeType (e2, ExpressionType.Not);
2153 Assert (true, e2.Compile ().Invoke (new MyType (1)));
2154 Assert (false, e2.Compile ().Invoke (new MyType (-1)));
2157 void NotTest_3 ()
2159 Expression<Func<int, int>> e3 = (int a) => ~a;
2160 AssertNodeType (e3, ExpressionType.Not);
2161 Assert (-8, e3.Compile ().Invoke (7));
2164 void NotTest_4 ()
2166 Expression<Func<MyType, int>> e4 = (MyType a) => ~a;
2167 AssertNodeType (e4, ExpressionType.Not);
2168 Assert (0, e4.Compile ().Invoke (new MyType (-1)));
2171 void NotTest_5 ()
2173 Expression<Func<ulong, ulong>> e5 = (ulong a) => ~a;
2174 AssertNodeType (e5, ExpressionType.Not);
2175 Assert<ulong> (18446744073709551608, e5.Compile ().Invoke (7));
2178 void NotTest_6 ()
2180 Expression<Func<MyEnum, MyEnum>> e6 = (MyEnum a) => ~a;
2181 AssertNodeType (e6, ExpressionType.Convert);
2182 Assert ((MyEnum)254, e6.Compile ().Invoke (MyEnum.Value_1));
2185 void NotNullableTest ()
2187 Expression<Func<bool?, bool?>> e = (bool? a) => !a;
2188 AssertNodeType (e, ExpressionType.Not);
2189 Assert (false, e.Compile ().Invoke (true));
2190 Assert (null, e.Compile ().Invoke (null));
2193 void NotNullableTest_2 ()
2195 Expression<Func<MyType?, bool?>> e2 = (MyType? a) => !a;
2196 AssertNodeType (e2, ExpressionType.Not);
2197 Assert (true, e2.Compile ().Invoke (new MyType (1)));
2198 Assert (null, e2.Compile ().Invoke (null));
2201 void NotNullableTest_3 ()
2203 Expression<Func<sbyte?, int?>> e3 = (sbyte? a) => ~a;
2204 AssertNodeType (e3, ExpressionType.Not);
2205 Assert (-5, e3.Compile ().Invoke (4));
2206 Assert (null, e3.Compile ().Invoke (null));
2209 void NotNullableTest_4 ()
2211 Expression<Func<MyType?, int?>> e4 = (MyType? a) => ~a;
2212 AssertNodeType (e4, ExpressionType.Not);
2213 Assert (0, e4.Compile ().Invoke (new MyType (-1)));
2214 Assert (null, e4.Compile ().Invoke (null));
2217 void NotNullableTest_5 ()
2219 Expression<Func<MyEnum?, MyEnum?>> e5 = (MyEnum? a) => ~a;
2220 AssertNodeType (e5, ExpressionType.Convert);
2221 Assert ((MyEnum) 254, e5.Compile ().Invoke (MyEnum.Value_1));
2222 Assert (null, e5.Compile ().Invoke (null));
2225 void NotEqualTest ()
2227 Expression<Func<int, int, bool>> e = (int a, int b) => a != b;
2228 AssertNodeType (e, ExpressionType.NotEqual);
2229 Assert (true, e.Compile ().Invoke (60, 30));
2230 Assert (false, e.Compile ().Invoke (-1, -1));
2233 void NotEqualTest_2 ()
2235 Expression<Func<sbyte?, sbyte?, bool>> e2 = (a, b) => a != b;
2236 AssertNodeType (e2, ExpressionType.NotEqual);
2237 Assert (false, e2.Compile ().Invoke (3, 3));
2238 Assert (true, e2.Compile ().Invoke (3, 2));
2241 void NotEqualTest_3 ()
2243 Expression<Func<MyType, MyType, bool>> e3 = (MyType a, MyType b) => a != b;
2244 AssertNodeType (e3, ExpressionType.NotEqual);
2245 Assert (false, e3.Compile ().Invoke (new MyType (-20), new MyType (-20)));
2248 void NotEqualTest_4 ()
2250 Expression<Func<MyType?, MyType?, bool>> e4 = (MyType? a, MyType? b) => a != b;
2251 AssertNodeType (e4, ExpressionType.NotEqual);
2252 Assert (true, e4.Compile ().Invoke (null, new MyType (-20)));
2253 Assert (false, e4.Compile ().Invoke (null, null));
2254 Assert (false, e4.Compile ().Invoke (new MyType (120), new MyType (120)));
2257 void NotEqualTest_5 ()
2259 Expression<Func<bool?, bool?, bool>> e5 = (bool? a, bool? b) => a != b;
2260 AssertNodeType (e5, ExpressionType.NotEqual);
2261 Assert (true, e5.Compile ().Invoke (true, null));
2262 Assert (false, e5.Compile ().Invoke (null, null));
2263 Assert (false, e5.Compile ().Invoke (false, false));
2266 void NotEqualTest_6 ()
2268 Expression<Func<bool, bool>> e6 = (bool a) => a != null;
2269 AssertNodeType (e6, ExpressionType.NotEqual);
2270 Assert (true, e6.Compile ().Invoke (true));
2271 Assert (true, e6.Compile ().Invoke (false));
2274 void NotEqualTest_7 ()
2276 Expression<Func<string, string, bool>> e7 = (string a, string b) => a != b;
2277 AssertNodeType (e7, ExpressionType.NotEqual);
2278 Assert (false, e7.Compile ().Invoke (null, null));
2279 Assert (true, e7.Compile ().Invoke ("a", "A"));
2280 Assert (false, e7.Compile ().Invoke ("a", "a"));
2283 void NotEqualTest_8 ()
2285 Expression<Func<object, bool>> e8 = (object a) => null != a;
2286 AssertNodeType (e8, ExpressionType.NotEqual);
2287 Assert (false, e8.Compile ().Invoke (null));
2288 Assert (true, e8.Compile ().Invoke ("a"));
2289 Assert (true, e8.Compile ().Invoke (this));
2292 void NotEqualTest_9 ()
2294 Expression<Func<MyEnum, MyEnum, bool>> e9 = (a, b) => a != b;
2295 AssertNodeType (e9, ExpressionType.NotEqual);
2296 Assert (true, e9.Compile ().Invoke (MyEnum.Value_1, MyEnum.Value_2));
2297 Assert (false, e9.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
2300 void NotEqualTest_10 ()
2302 Expression<Func<MyEnum?, MyEnum?, bool>> e10 = (a, b) => a != b;
2303 AssertNodeType (e10, ExpressionType.NotEqual);
2304 Assert (true, e10.Compile ().Invoke (MyEnum.Value_1, null));
2305 Assert (false, e10.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
2308 void NotEqualTest_11 ()
2310 Expression<Func<MyEnum?, bool>> e11 = (a) => a != null;
2311 AssertNodeType (e11, ExpressionType.NotEqual);
2312 Assert (true, e11.Compile ().Invoke (MyEnum.Value_1));
2313 Assert (false, e11.Compile ().Invoke (null));
2316 void OrTest ()
2318 Expression<Func<bool, bool, bool>> e = (bool a, bool b) => a | b;
2320 AssertNodeType (e, ExpressionType.Or);
2321 Func<bool, bool, bool> c = e.Compile ();
2323 Assert (true, c (true, true));
2324 Assert (true, c (true, false));
2325 Assert (true, c (false, true));
2326 Assert (false, c (false, false));
2329 void OrTest_2 ()
2331 Expression<Func<MyType, MyType, MyType>> e2 = (MyType a, MyType b) => a | b;
2332 AssertNodeType (e2, ExpressionType.Or);
2333 var c2 = e2.Compile ();
2334 Assert (new MyType (3), c2 (new MyType (1), new MyType (2)));
2337 void OrTest_3 ()
2339 Expression<Func<MyEnum, MyEnum, MyEnum>> e3 = (a, b) => a | b;
2340 AssertNodeType (e3, ExpressionType.Convert);
2341 Assert ((MyEnum)3, e3.Compile ().Invoke (MyEnum.Value_1, MyEnum.Value_2));
2342 Assert (MyEnum.Value_2, e3.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_2));
2345 void OrNullableTest ()
2347 Expression<Func<bool?, bool?, bool?>> e = (bool? a, bool? b) => a | b;
2349 AssertNodeType (e, ExpressionType.Or);
2350 Func<bool?, bool?, bool?> c = e.Compile ();
2352 Assert (true, c (true, true));
2353 Assert (true, c (true, false));
2354 Assert (true, c (false, true));
2355 Assert (false, c (false, false));
2357 Assert (true, c (true, null));
2358 Assert (null, c (false, null));
2359 Assert (null, c (null, false));
2360 Assert (true, c (true, null));
2361 Assert (null, c (null, null));
2364 void OrNullableTest_2 ()
2366 Expression<Func<MyType?, MyType?, MyType?>> e2 = (MyType? a, MyType? b) => a | b;
2367 AssertNodeType (e2, ExpressionType.Or);
2368 var c2 = e2.Compile ();
2369 Assert (new MyType (3), c2 (new MyType (1), new MyType (2)));
2370 Assert (null, c2 (new MyType (1), null));
2373 // CSC BUG: Fixed?
2374 void OrNullableTest_3 ()
2376 Expression<Func<MyType?, uint, long?>> e3 = (MyType? a, uint b) => a | b;
2377 AssertNodeType (e3, ExpressionType.Or);
2378 var c3 = e3.Compile ();
2379 Assert (9, c3 (new MyType (1), 8));
2382 void OrNullableTest_4 ()
2384 Expression<Func<MyEnum?, MyEnum?, MyEnum?>> e4 = (a, b) => a | b;
2385 AssertNodeType (e4, ExpressionType.Convert);
2386 Assert (null, e4.Compile ().Invoke (null, MyEnum.Value_2));
2387 Assert ((MyEnum)3, e4.Compile ().Invoke (MyEnum.Value_1, MyEnum.Value_2));
2390 void OrElseTest ()
2392 Expression<Func<bool, bool, bool>> e = (bool a, bool b) => a || b;
2393 AssertNodeType (e, ExpressionType.OrElse);
2394 Assert (true, e.Compile ().Invoke (true, false));
2397 void OrElseTest_2 ()
2399 Expression<Func<MyType, MyType, MyType>> e2 = (MyType a, MyType b) => a || b;
2400 AssertNodeType (e2, ExpressionType.OrElse);
2401 Assert (new MyType (64), e2.Compile ().Invoke (new MyType (64), new MyType (64)));
2402 Assert (new MyType (32), e2.Compile ().Invoke (new MyType (32), new MyType (64)));
2405 void ParameterTest ()
2407 Expression<Func<string, string>> e = (string a) => a;
2408 AssertNodeType (e, ExpressionType.Parameter);
2409 Assert ("t", e.Compile ().Invoke ("t"));
2412 void ParameterTest_2 ()
2414 Expression<Func<object[], object[]>> e2 = (object[] a) => a;
2415 AssertNodeType (e2, ExpressionType.Parameter);
2416 Assert (new object [0], e2.Compile ().Invoke (new object [0]));
2419 void ParameterTest_3 ()
2421 Expression<Func<IntPtr, IntPtr>> e3 = a => a;
2422 AssertNodeType (e3, ExpressionType.Parameter);
2423 Assert (IntPtr.Zero, e3.Compile ().Invoke (IntPtr.Zero));
2426 //unsafe void ParameterTest_4 ()
2428 // Expression<Func<int*[], int* []>> e4 = (a) => a;
2429 // AssertNodeType (e4, ExpressionType.Parameter);
2430 // Assert<int*[]> (null, e4.Compile ().Invoke (null));
2431 // int* e4_el = stackalloc int [5];
2432 // int*[] ptr = new int*[] { e4_el };
2433 // Assert<int*[]> (ptr, e4.Compile ().Invoke (ptr));
2436 void QuoteTest ()
2438 Expression<Func<Expression<Func<int>>>> e = () => () => 2;
2439 AssertNodeType (e, ExpressionType.Quote);
2440 Assert (2, e.Compile ().Invoke ().Compile ().Invoke ());
2443 void RightShiftTest ()
2445 Expression<Func<ulong, short, ulong>> e = (ulong a, short b) => a >> b;
2446 AssertNodeType (e, ExpressionType.RightShift);
2447 Assert ((ulong) 0x1FD940L, e.Compile ().Invoke (0xFECA0000, 11));
2448 Assert ((ulong) 0x7FFFFFFF, e.Compile ().Invoke (0xFFFFFFFF, 0xA01));
2450 // .net produces a strange result
2451 // see https://bugzilla.novell.com/show_bug.cgi?id=398358
2452 // Assert ((ulong)0, e.Compile ().Invoke (0xFFFFFFFF, 0xA01));
2455 void RightShiftTest_2 ()
2457 Expression<Func<MyType, MyType, int>> e2 = (MyType a, MyType b) => a >> b;
2458 AssertNodeType (e2, ExpressionType.RightShift);
2459 var c2 = e2.Compile ();
2460 Assert (64, c2 (new MyType (256), new MyType (2)));
2463 void RightShiftTest_3 ()
2465 Expression<Func<long?, sbyte, long?>> e3 = (long? a, sbyte b) => a >> b;
2466 AssertNodeType (e3, ExpressionType.RightShift);
2467 Assert (null, e3.Compile ().Invoke (null, 11));
2468 Assert (512, e3.Compile ().Invoke (1024, 1));
2471 void RightShiftTest_4 ()
2473 Expression<Func<MyType?, MyType?, int?>> e4 = (MyType? a, MyType? b) => a >> b;
2474 AssertNodeType (e4, ExpressionType.RightShift);
2475 var c4 = e4.Compile ();
2476 Assert (null, c4 (new MyType (8), null));
2477 Assert (null, c4 (null, new MyType (8)));
2478 Assert (64, c4 (new MyType (256), new MyType (2)));
2481 void SubtractTest ()
2483 Expression<Func<int, int, int>> e = (int a, int b) => a - b;
2484 AssertNodeType (e, ExpressionType.Subtract);
2485 Assert (-10, e.Compile ().Invoke (20, 30));
2488 void SubtractTest_2 ()
2490 Expression<Func<int?, int?, int?>> e2 = (a, b) => a - b;
2491 AssertNodeType (e2, ExpressionType.Subtract);
2492 Assert (null, e2.Compile ().Invoke (null, 3));
2495 void SubtractTest_3 ()
2497 Expression<Func<MyType, MyType, MyType>> e3 = (MyType a, MyType b) => a - b;
2498 AssertNodeType (e3, ExpressionType.Subtract);
2499 Assert (-50, e3.Compile ().Invoke (new MyType (-20), new MyType (30)));
2502 void SubtractTest_4 ()
2504 Expression<Func<MyType?, MyType?, MyType?>> e4 = (MyType? a, MyType? b) => a - b;
2505 AssertNodeType (e4, ExpressionType.Subtract);
2506 Assert (new MyType (-50), e4.Compile ().Invoke (new MyType (-20), new MyType (30)));
2507 Assert (null, e4.Compile ().Invoke (null, new MyType (30)));
2510 void SubtractTest_5 ()
2512 Expression<Func<int, MyType, int>> e5 = (int a, MyType b) => a - b;
2513 AssertNodeType (e5, ExpressionType.Subtract);
2514 Assert (-29, e5.Compile ().Invoke (1, new MyType (30)));
2517 void SubtractTest_6 ()
2519 Expression<Func<int, MyType?, int?>> e6 = (int a, MyType? b) => a - b;
2520 AssertNodeType (e6, ExpressionType.Subtract);
2521 Assert (-61, e6.Compile ().Invoke (-31, new MyType (30)));
2524 void SubtractTest_7 ()
2526 Expression<Func<ushort, int?>> e7 = (ushort a) => null - a;
2527 AssertNodeType (e7, ExpressionType.Subtract);
2528 Assert (null, e7.Compile ().Invoke (690));
2531 void SubtractTest_8 ()
2533 Expression<Func<MyEnum, byte, MyEnum>> e8 = (a, b) => a - b;
2534 AssertNodeType (e8, ExpressionType.Convert);
2535 Assert ((MyEnum)255, e8.Compile ().Invoke (MyEnum.Value_1, 2));
2538 void SubtractTest_9 ()
2540 Expression<Func<MyEnum, MyEnum, byte>> e9 = (a, b) => a - b;
2541 AssertNodeType (e9, ExpressionType.Convert);
2542 Assert (1, e9.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_1));
2545 // CSC bug
2546 void SubtractTest_10 ()
2548 Expression<Func<MyEnum?, byte?, MyEnum?>> e10 = (a, b) => a - b;
2549 AssertNodeType (e10, ExpressionType.Convert);
2550 Assert ((MyEnum) 255, e10.Compile ().Invoke (MyEnum.Value_1, 2));
2553 // CSC bug
2554 void SubtractTest_11 ()
2556 Expression<Func<MyEnum?, MyEnum?, byte?>> e11 = (a, b) => a - b;
2557 AssertNodeType (e11, ExpressionType.Convert);
2558 Assert<byte?> (1, e11.Compile ().Invoke (MyEnum.Value_2, MyEnum.Value_1));
2561 void SubtractCheckedTest ()
2563 checked {
2564 Expression<Func<long, long, long>> e = (long a, long b) => a - b;
2565 AssertNodeType (e, ExpressionType.SubtractChecked);
2566 try {
2567 e.Compile ().Invoke (long.MinValue, 309);
2568 throw new ApplicationException ("SubtractCheckedTest #1");
2569 } catch (OverflowException) { }
2573 void SubtractCheckedTest_2 ()
2575 checked {
2576 Expression<Func<byte?, byte?, int?>> e2 = (a, b) => a - b;
2577 AssertNodeType (e2, ExpressionType.SubtractChecked);
2578 Assert (null, e2.Compile ().Invoke (null, 3));
2579 Assert (-55, e2.Compile ().Invoke (byte.MinValue, 55));
2583 void SubtractCheckedTest_3 ()
2585 checked {
2586 Expression<Func<MyType, MyType, MyType>> e3 = (MyType a, MyType b) => a - b;
2587 AssertNodeType (e3, ExpressionType.Subtract);
2588 Assert (-50, e3.Compile ().Invoke (new MyType (-20), new MyType (30)));
2592 void SubtractCheckedTest_4 ()
2594 checked {
2595 Expression<Func<double, double, double>> e4 = (a, b) => a - b;
2596 AssertNodeType (e4, ExpressionType.Subtract);
2597 Assert (double.PositiveInfinity, e4.Compile ().Invoke (double.MinValue, double.NegativeInfinity));
2601 void TypeAsTest ()
2603 Expression<Func<object, Tester>> e = (object a) => a as Tester;
2604 AssertNodeType (e, ExpressionType.TypeAs);
2605 Assert (this, e.Compile ().Invoke (this));
2608 void TypeAsTest_2 ()
2610 Expression<Func<object, int?>> e2 = (object a) => a as int?;
2611 AssertNodeType (e2, ExpressionType.TypeAs);
2612 Assert (null, e2.Compile ().Invoke (null));
2613 Assert (null, e2.Compile ().Invoke (this));
2614 Assert (44, e2.Compile ().Invoke (44));
2617 void TypeAsTest_3 ()
2619 Expression<Func<object, object>> e3 = (object a) => null as object;
2620 AssertNodeType (e3, ExpressionType.TypeAs);
2621 Assert (null, e3.Compile ().Invoke (null));
2624 void TypeIsTest ()
2626 Expression<Func<object, bool>> e = (object a) => a is Tester;
2627 AssertNodeType (e, ExpressionType.TypeIs);
2628 Assert (true, e.Compile ().Invoke (this));
2629 Assert (false, e.Compile ().Invoke (1));
2632 void TypeIsTest_2 ()
2634 Expression<Func<object, bool>> e2 = (object a) => a is int?;
2635 AssertNodeType (e2, ExpressionType.TypeIs);
2636 Assert (false, e2.Compile ().Invoke (null));
2637 Assert (true, e2.Compile ().Invoke (1));
2640 void TypeIsTest_3 ()
2642 Expression<Func<object, bool>> e3 = (object a) => null is object;
2643 AssertNodeType (e3, ExpressionType.TypeIs);
2644 Assert (false, e3.Compile ().Invoke (null));
2647 void TypeIsTest_5 ()
2649 Expression<Func<bool>> e5 = () => 1 is int;
2650 AssertNodeType (e5, ExpressionType.TypeIs);
2651 Assert (true, e5.Compile ().Invoke ());
2654 void TypeIsTest_6 ()
2656 Expression<Func<int?, bool>> e6 = (a) => a is int;
2657 AssertNodeType (e6, ExpressionType.TypeIs);
2658 Assert (true, e6.Compile ().Invoke (1));
2659 Assert (false, e6.Compile ().Invoke (null));
2662 void UnaryPlusTest ()
2664 Expression<Func<int, int>> e = (a) => +a;
2665 AssertNodeType (e, ExpressionType.Parameter);
2666 Assert (-30, e.Compile ().Invoke (-30));
2669 void UnaryPlusTest_2 ()
2671 Expression<Func<long?, long?>> e2 = (a) => +a;
2672 AssertNodeType (e2, ExpressionType.Parameter);
2675 void UnaryPlusTest_3 ()
2677 Expression<Func<MyType, MyType>> e4 = (a) => +a;
2678 AssertNodeType (e4, ExpressionType.UnaryPlus);
2679 Assert (new MyType (-14), e4.Compile ().Invoke (new MyType (-14)));
2682 void UnaryPlusTest_4 ()
2684 Expression<Func<MyType?, MyType?>> e5 = (a) => +a;
2685 AssertNodeType (e5, ExpressionType.UnaryPlus);
2686 Assert (new MyType (33), e5.Compile ().Invoke (new MyType (33)));
2687 Assert (null, e5.Compile ().Invoke (null));
2690 void UnaryPlusTest_5 ()
2692 Expression<Func<sbyte?, long?>> e6 = (a) => +a;
2693 AssertNodeType (e6, ExpressionType.Convert);
2694 Assert (3, e6.Compile ().Invoke (3));
2695 Assert (null, e6.Compile ().Invoke (null));
2698 #pragma warning restore 169
2701 // Test helpers
2703 string InstanceMethod (string arg)
2705 return arg;
2708 object InstanceParamsMethod (int index, params object [] args)
2710 if (args == null)
2711 return "<null>";
2712 if (args.Length == 0)
2713 return "<empty>";
2714 return args [index];
2717 static int TestInt ()
2719 return 29;
2722 T GenericMethod<T> (T t)
2724 return t;
2727 static void RefMethod (ref int i)
2729 i = 867;
2732 static bool RunTest (MethodInfo test)
2734 Console.Write ("Running test {0, -25}", test.Name);
2735 try {
2736 test.Invoke (new Tester (), null);
2737 Console.WriteLine ("OK");
2738 return true;
2739 } catch (Exception e) {
2740 Console.WriteLine ("FAILED");
2741 Console.WriteLine (e.ToString ());
2742 return false;
2746 public static int Main ()
2748 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
2749 where test.GetParameters ().Length == 0
2750 orderby test.Name
2751 select RunTest (test);
2753 int failures = tests.Count (a => !a);
2754 Console.WriteLine (failures + " tests failed");
2755 return failures;