ExpressionTest_MakeBinary.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. //
  19. // Authors:
  20. // Miguel de Icaza <[email protected]>
  21. //
  22. using System;
  23. using System.Reflection;
  24. using System.Linq;
  25. using System.Linq.Expressions;
  26. using NUnit.Framework;
  27. namespace MonoTests.System.Linq.Expressions
  28. {
  29. [TestFixture]
  30. public class ExpressionTest_MakeBinary {
  31. static void PassInt (ExpressionType nt)
  32. {
  33. Expression left = Expression.Constant (1);
  34. Expression right = Expression.Constant (1);
  35. Expression.MakeBinary (nt, left, right);
  36. }
  37. static void FailInt (ExpressionType nt)
  38. {
  39. Expression left = Expression.Constant (1);
  40. Expression right = Expression.Constant (1);
  41. try {
  42. Expression.MakeBinary (nt, left, right);
  43. } catch (ArgumentException){
  44. return;
  45. }
  46. // If we get here, there was an error
  47. Assert.Fail ("FailInt failed while creating an {0}", nt);
  48. }
  49. //
  50. // Checks that we complain on the proper ExpressionTypes
  51. //
  52. [Test]
  53. public void TestBinaryCtor ()
  54. {
  55. PassInt (ExpressionType.Add);
  56. PassInt (ExpressionType.AddChecked);
  57. PassInt (ExpressionType.And);
  58. PassInt (ExpressionType.Divide);
  59. PassInt (ExpressionType.Equal);
  60. PassInt (ExpressionType.ExclusiveOr);
  61. PassInt (ExpressionType.GreaterThan);
  62. PassInt (ExpressionType.GreaterThanOrEqual);
  63. PassInt (ExpressionType.LeftShift);
  64. PassInt (ExpressionType.LessThan);
  65. PassInt (ExpressionType.LessThanOrEqual);
  66. PassInt (ExpressionType.Multiply);
  67. PassInt (ExpressionType.MultiplyChecked);
  68. PassInt (ExpressionType.NotEqual);
  69. PassInt (ExpressionType.Or);
  70. PassInt (ExpressionType.Modulo);
  71. PassInt (ExpressionType.RightShift);
  72. PassInt (ExpressionType.Subtract);
  73. PassInt (ExpressionType.SubtractChecked);
  74. // Remove comment when the code is implemented:
  75. //FailInt (ExpressionType.AndAlso);
  76. //FailInt (ExpressionType.OrElse);
  77. //This should test for types, not operation: FailInt (ExpressionType.Power);
  78. #if false
  79. // These currently fail, because it now goes directly to the nodes, instead of doing
  80. // a first-pass check; REmove when its all done.
  81. FailInt (ExpressionType.ArrayLength);
  82. FailInt (ExpressionType.ArrayIndex);
  83. FailInt (ExpressionType.Call);
  84. FailInt (ExpressionType.Coalesce);
  85. FailInt (ExpressionType.Conditional);
  86. FailInt (ExpressionType.Constant);
  87. FailInt (ExpressionType.Convert);
  88. FailInt (ExpressionType.ConvertChecked);
  89. FailInt (ExpressionType.Invoke);
  90. FailInt (ExpressionType.Lambda);
  91. FailInt (ExpressionType.ListInit);
  92. FailInt (ExpressionType.MemberAccess);
  93. FailInt (ExpressionType.MemberInit);
  94. FailInt (ExpressionType.Negate);
  95. FailInt (ExpressionType.UnaryPlus);
  96. FailInt (ExpressionType.NegateChecked);
  97. FailInt (ExpressionType.New);
  98. FailInt (ExpressionType.NewArrayInit);
  99. FailInt (ExpressionType.NewArrayBounds);
  100. FailInt (ExpressionType.Not);
  101. FailInt (ExpressionType.Parameter);
  102. FailInt (ExpressionType.Quote);
  103. FailInt (ExpressionType.TypeAs);
  104. FailInt (ExpressionType.TypeIs);
  105. #endif
  106. }
  107. }
  108. }