|
|
@@ -139,16 +139,6 @@ namespace MonoTests.System.Linq.Expressions
|
|
|
Assert.AreEqual ("(value(MonoTests.System.Linq.Expressions.OpClass) = value(MonoTests.System.Linq.Expressions.OpClass))", expr.ToString ());
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
- // Checks for the behavior when the return type for Equal is not
|
|
|
- // bool, and its coping with nullable values.
|
|
|
- //
|
|
|
- [Test]
|
|
|
- public void UserDefinedEqual ()
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
[Test]
|
|
|
public void NullableInt32Equal ()
|
|
|
{
|
|
|
@@ -184,5 +174,225 @@ namespace MonoTests.System.Linq.Expressions
|
|
|
Assert.AreEqual ((bool?) null, eq (null, 0));
|
|
|
Assert.AreEqual ((bool?) null, eq (0, null));
|
|
|
}
|
|
|
+
|
|
|
+ struct Slot {
|
|
|
+ public int Value;
|
|
|
+
|
|
|
+ public Slot (int value)
|
|
|
+ {
|
|
|
+ this.Value = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool Equals (object obj)
|
|
|
+ {
|
|
|
+ if (!(obj is Slot))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ var other = (Slot) obj;
|
|
|
+ return other.Value == this.Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override int GetHashCode ()
|
|
|
+ {
|
|
|
+ return Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool operator == (Slot a, Slot b)
|
|
|
+ {
|
|
|
+ return a.Value == b.Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool operator != (Slot a, Slot b)
|
|
|
+ {
|
|
|
+ return a.Value != b.Value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void UserDefinedEqual ()
|
|
|
+ {
|
|
|
+ var l = Expression.Parameter (typeof (Slot), "l");
|
|
|
+ var r = Expression.Parameter (typeof (Slot), "r");
|
|
|
+
|
|
|
+ var node = Expression.Equal (l, r);
|
|
|
+
|
|
|
+ Assert.IsFalse (node.IsLifted);
|
|
|
+ Assert.IsFalse (node.IsLiftedToNull);
|
|
|
+ Assert.AreEqual (typeof (bool), node.Type);
|
|
|
+ Assert.IsNotNull (node.Method);
|
|
|
+
|
|
|
+ var eq = Expression.Lambda<Func<Slot, Slot, bool>> (node, l, r).Compile ();
|
|
|
+
|
|
|
+ Assert.AreEqual (true, eq (new Slot (21), new Slot (21)));
|
|
|
+ Assert.AreEqual (false, eq (new Slot (1), new Slot (-1)));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void UserDefinedEqualLifted ()
|
|
|
+ {
|
|
|
+ var l = Expression.Parameter (typeof (Slot?), "l");
|
|
|
+ var r = Expression.Parameter (typeof (Slot?), "r");
|
|
|
+
|
|
|
+ var node = Expression.Equal (l, r);
|
|
|
+
|
|
|
+ Assert.IsTrue (node.IsLifted);
|
|
|
+ Assert.IsFalse (node.IsLiftedToNull);
|
|
|
+ Assert.AreEqual (typeof (bool), node.Type);
|
|
|
+ Assert.IsNotNull (node.Method);
|
|
|
+
|
|
|
+ var eq = Expression.Lambda<Func<Slot?, Slot?, bool>> (node, l, r).Compile ();
|
|
|
+
|
|
|
+ Assert.AreEqual (true, eq (null, null));
|
|
|
+ Assert.AreEqual (false, eq ((Slot?) new Slot (2), null));
|
|
|
+ Assert.AreEqual (false, eq (null, (Slot?) new Slot (2)));
|
|
|
+ Assert.AreEqual (true, eq ((Slot?) new Slot (21), (Slot?) new Slot (21)));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void UserDefinedEqualLiftedToNull ()
|
|
|
+ {
|
|
|
+ var l = Expression.Parameter (typeof (Slot?), "l");
|
|
|
+ var r = Expression.Parameter (typeof (Slot?), "r");
|
|
|
+
|
|
|
+ var node = Expression.Equal (l, r, true, null);
|
|
|
+
|
|
|
+ Assert.IsTrue (node.IsLifted);
|
|
|
+ Assert.IsTrue (node.IsLiftedToNull);
|
|
|
+ Assert.AreEqual (typeof (bool?), node.Type);
|
|
|
+ Assert.IsNotNull (node.Method);
|
|
|
+
|
|
|
+ var eq = Expression.Lambda<Func<Slot?, Slot?, bool?>> (node, l, r).Compile ();
|
|
|
+
|
|
|
+ Assert.AreEqual ((bool?) null, eq (null, null));
|
|
|
+ Assert.AreEqual ((bool?) null, eq ((Slot?) new Slot (2), null));
|
|
|
+ Assert.AreEqual ((bool?) null, eq (null, (Slot?) new Slot (2)));
|
|
|
+ Assert.AreEqual ((bool?) true, eq ((Slot?) new Slot (21), (Slot?) new Slot (21)));
|
|
|
+ Assert.AreEqual ((bool?) false, eq ((Slot?) new Slot (21), (Slot?) new Slot (-21)));
|
|
|
+ }
|
|
|
+
|
|
|
+ struct SlotToNullable {
|
|
|
+ public int Value;
|
|
|
+
|
|
|
+ public SlotToNullable (int value)
|
|
|
+ {
|
|
|
+ this.Value = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override int GetHashCode ()
|
|
|
+ {
|
|
|
+ return Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool Equals (object obj)
|
|
|
+ {
|
|
|
+ if (!(obj is SlotToNullable))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ var other = (SlotToNullable) obj;
|
|
|
+ return other.Value == this.Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool? operator == (SlotToNullable a, SlotToNullable b)
|
|
|
+ {
|
|
|
+ return (bool?) (a.Value == b.Value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool? operator != (SlotToNullable a, SlotToNullable b)
|
|
|
+ {
|
|
|
+ return (bool?) (a.Value != b.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ [ExpectedException (typeof (InvalidOperationException))]
|
|
|
+ public void UserDefinedToNullableEqualFromNullable ()
|
|
|
+ {
|
|
|
+ Expression.Equal (
|
|
|
+ Expression.Parameter (typeof (SlotToNullable?), "l"),
|
|
|
+ Expression.Parameter (typeof (SlotToNullable?), "r"));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void UserDefinedToNullableEqual ()
|
|
|
+ {
|
|
|
+ var l = Expression.Parameter (typeof (SlotToNullable), "l");
|
|
|
+ var r = Expression.Parameter (typeof (SlotToNullable), "r");
|
|
|
+
|
|
|
+ var node = Expression.Equal (l, r, false, null);
|
|
|
+
|
|
|
+ Assert.IsFalse (node.IsLifted);
|
|
|
+ Assert.IsFalse (node.IsLiftedToNull);
|
|
|
+ Assert.AreEqual (typeof (bool?), node.Type);
|
|
|
+ Assert.IsNotNull (node.Method);
|
|
|
+
|
|
|
+ var eq = Expression.Lambda<Func<SlotToNullable, SlotToNullable, bool?>> (node, l, r).Compile ();
|
|
|
+
|
|
|
+ Assert.AreEqual ((bool?) true, eq (new SlotToNullable (2), new SlotToNullable (2)));
|
|
|
+ Assert.AreEqual ((bool?) false, eq (new SlotToNullable (2), new SlotToNullable (-2)));
|
|
|
+ }
|
|
|
+
|
|
|
+ struct SlotFromNullableToNullable {
|
|
|
+ public int Value;
|
|
|
+
|
|
|
+ public SlotFromNullableToNullable (int value)
|
|
|
+ {
|
|
|
+ this.Value = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override bool Equals (object obj)
|
|
|
+ {
|
|
|
+ if (!(obj is SlotFromNullableToNullable))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ var other = (SlotFromNullableToNullable) obj;
|
|
|
+ return other.Value == this.Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override int GetHashCode ()
|
|
|
+ {
|
|
|
+ return Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool? operator == (SlotFromNullableToNullable? a, SlotFromNullableToNullable? b)
|
|
|
+ {
|
|
|
+ if (a.HasValue && b.HasValue)
|
|
|
+ return (bool?) (a.Value.Value == b.Value.Value);
|
|
|
+ else
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool? operator != (SlotFromNullableToNullable? a, SlotFromNullableToNullable? b)
|
|
|
+ {
|
|
|
+ return !(a == b);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void UserDefinedFromNullableToNullableEqual ()
|
|
|
+ {
|
|
|
+ var l = Expression.Parameter (typeof (SlotFromNullableToNullable?), "l");
|
|
|
+ var r = Expression.Parameter (typeof (SlotFromNullableToNullable?), "r");
|
|
|
+
|
|
|
+ var node = Expression.Equal (l, r);
|
|
|
+
|
|
|
+ Assert.IsFalse (node.IsLifted);
|
|
|
+ Assert.IsFalse (node.IsLiftedToNull);
|
|
|
+ Assert.AreEqual (typeof (bool?), node.Type);
|
|
|
+ Assert.IsNotNull (node.Method);
|
|
|
+
|
|
|
+ var eq = Expression.Lambda<Func<SlotFromNullableToNullable?, SlotFromNullableToNullable?, bool?>> (node, l, r).Compile ();
|
|
|
+
|
|
|
+ Assert.AreEqual ((bool?) null, eq (null, null));
|
|
|
+ Assert.AreEqual ((bool?) null, eq (new SlotFromNullableToNullable (2), null));
|
|
|
+ Assert.AreEqual ((bool?) null, eq (null, new SlotFromNullableToNullable (2)));
|
|
|
+ Assert.AreEqual ((bool?) true, eq (new SlotFromNullableToNullable (2), new SlotFromNullableToNullable (2)));
|
|
|
+ Assert.AreEqual ((bool?) false, eq (new SlotFromNullableToNullable (2), new SlotFromNullableToNullable (-2)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|