about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThomas Heck <t@b128.net>2018-12-08 09:35:23 +0100
committerThomas Heck <t@b128.net>2018-12-08 13:30:55 +0100
commitd828c22bd6ff6059c75dfa63e024997619eb6e7c (patch)
tree9e7054823e431534a221d12553137e3275a7a289
parent40d60a4608c76e8a74ab643f4629dbaf129e07a4 (diff)
downloadrust-d828c22bd6ff6059c75dfa63e024997619eb6e7c.tar.gz
rust-d828c22bd6ff6059c75dfa63e024997619eb6e7c.zip
Add Arc/Rc Eq tests
-rw-r--r--src/liballoc/tests/arc.rs42
-rw-r--r--src/liballoc/tests/rc.rs42
2 files changed, 84 insertions, 0 deletions
diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs
index d90c22a3b18..ec589710216 100644
--- a/src/liballoc/tests/arc.rs
+++ b/src/liballoc/tests/arc.rs
@@ -10,6 +10,8 @@
 
 use std::any::Any;
 use std::sync::{Arc, Weak};
+use std::cell::RefCell;
+use std::cmp::PartialEq;
 
 #[test]
 fn uninhabited() {
@@ -53,3 +55,43 @@ fn trait_object() {
     b = b.clone();
     assert!(b.upgrade().is_none());
 }
+
+#[test]
+fn float_nan_ne() {
+    let x = Arc::new(std::f32::NAN);
+    assert!(x != x);
+    assert!(!(x == x));
+}
+
+#[test]
+fn partial_eq() {
+    struct TestPEq (RefCell<usize>);
+    impl PartialEq for TestPEq {
+        fn eq(&self, other: &TestPEq) -> bool {
+            *self.0.borrow_mut() += 1;
+            *other.0.borrow_mut() += 1;
+            true
+        }
+    }
+    let x = Arc::new(TestPEq(RefCell::new(0)));
+    assert!(x == x);
+    assert!(!(x != x));
+    assert_eq!(*x.0.borrow(), 4);
+}
+
+#[test]
+fn eq() {
+    #[derive(Eq)]
+    struct TestEq (RefCell<usize>);
+    impl PartialEq for TestEq {
+        fn eq(&self, other: &TestEq) -> bool {
+            *self.0.borrow_mut() += 1;
+            *other.0.borrow_mut() += 1;
+            true
+        }
+    }
+    let x = Arc::new(TestEq(RefCell::new(0)));
+    assert!(x == x);
+    assert!(!(x != x));
+    assert_eq!(*x.0.borrow(), 0);
+}
diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs
index 9ec7c831444..02e1dfe13bb 100644
--- a/src/liballoc/tests/rc.rs
+++ b/src/liballoc/tests/rc.rs
@@ -10,6 +10,8 @@
 
 use std::any::Any;
 use std::rc::{Rc, Weak};
+use std::cell::RefCell;
+use std::cmp::PartialEq;
 
 #[test]
 fn uninhabited() {
@@ -53,3 +55,43 @@ fn trait_object() {
     b = b.clone();
     assert!(b.upgrade().is_none());
 }
+
+#[test]
+fn float_nan_ne() {
+    let x = Rc::new(std::f32::NAN);
+    assert!(x != x);
+    assert!(!(x == x));
+}
+
+#[test]
+fn partial_eq() {
+    struct TestPEq (RefCell<usize>);
+    impl PartialEq for TestPEq {
+        fn eq(&self, other: &TestPEq) -> bool {
+            *self.0.borrow_mut() += 1;
+            *other.0.borrow_mut() += 1;
+            true
+        }
+    }
+    let x = Rc::new(TestPEq(RefCell::new(0)));
+    assert!(x == x);
+    assert!(!(x != x));
+    assert_eq!(*x.0.borrow(), 4);
+}
+
+#[test]
+fn eq() {
+    #[derive(Eq)]
+    struct TestEq (RefCell<usize>);
+    impl PartialEq for TestEq {
+        fn eq(&self, other: &TestEq) -> bool {
+            *self.0.borrow_mut() += 1;
+            *other.0.borrow_mut() += 1;
+            true
+        }
+    }
+    let x = Rc::new(TestEq(RefCell::new(0)));
+    assert!(x == x);
+    assert!(!(x != x));
+    assert_eq!(*x.0.borrow(), 0);
+}