Skip to content

Commit d828c22

Browse files
committed
Add Arc/Rc Eq tests
1 parent 40d60a4 commit d828c22

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/liballoc/tests/arc.rs

+42
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use std::any::Any;
1212
use std::sync::{Arc, Weak};
13+
use std::cell::RefCell;
14+
use std::cmp::PartialEq;
1315

1416
#[test]
1517
fn uninhabited() {
@@ -53,3 +55,43 @@ fn trait_object() {
5355
b = b.clone();
5456
assert!(b.upgrade().is_none());
5557
}
58+
59+
#[test]
60+
fn float_nan_ne() {
61+
let x = Arc::new(std::f32::NAN);
62+
assert!(x != x);
63+
assert!(!(x == x));
64+
}
65+
66+
#[test]
67+
fn partial_eq() {
68+
struct TestPEq (RefCell<usize>);
69+
impl PartialEq for TestPEq {
70+
fn eq(&self, other: &TestPEq) -> bool {
71+
*self.0.borrow_mut() += 1;
72+
*other.0.borrow_mut() += 1;
73+
true
74+
}
75+
}
76+
let x = Arc::new(TestPEq(RefCell::new(0)));
77+
assert!(x == x);
78+
assert!(!(x != x));
79+
assert_eq!(*x.0.borrow(), 4);
80+
}
81+
82+
#[test]
83+
fn eq() {
84+
#[derive(Eq)]
85+
struct TestEq (RefCell<usize>);
86+
impl PartialEq for TestEq {
87+
fn eq(&self, other: &TestEq) -> bool {
88+
*self.0.borrow_mut() += 1;
89+
*other.0.borrow_mut() += 1;
90+
true
91+
}
92+
}
93+
let x = Arc::new(TestEq(RefCell::new(0)));
94+
assert!(x == x);
95+
assert!(!(x != x));
96+
assert_eq!(*x.0.borrow(), 0);
97+
}

src/liballoc/tests/rc.rs

+42
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use std::any::Any;
1212
use std::rc::{Rc, Weak};
13+
use std::cell::RefCell;
14+
use std::cmp::PartialEq;
1315

1416
#[test]
1517
fn uninhabited() {
@@ -53,3 +55,43 @@ fn trait_object() {
5355
b = b.clone();
5456
assert!(b.upgrade().is_none());
5557
}
58+
59+
#[test]
60+
fn float_nan_ne() {
61+
let x = Rc::new(std::f32::NAN);
62+
assert!(x != x);
63+
assert!(!(x == x));
64+
}
65+
66+
#[test]
67+
fn partial_eq() {
68+
struct TestPEq (RefCell<usize>);
69+
impl PartialEq for TestPEq {
70+
fn eq(&self, other: &TestPEq) -> bool {
71+
*self.0.borrow_mut() += 1;
72+
*other.0.borrow_mut() += 1;
73+
true
74+
}
75+
}
76+
let x = Rc::new(TestPEq(RefCell::new(0)));
77+
assert!(x == x);
78+
assert!(!(x != x));
79+
assert_eq!(*x.0.borrow(), 4);
80+
}
81+
82+
#[test]
83+
fn eq() {
84+
#[derive(Eq)]
85+
struct TestEq (RefCell<usize>);
86+
impl PartialEq for TestEq {
87+
fn eq(&self, other: &TestEq) -> bool {
88+
*self.0.borrow_mut() += 1;
89+
*other.0.borrow_mut() += 1;
90+
true
91+
}
92+
}
93+
let x = Rc::new(TestEq(RefCell::new(0)));
94+
assert!(x == x);
95+
assert!(!(x != x));
96+
assert_eq!(*x.0.borrow(), 0);
97+
}

0 commit comments

Comments
 (0)