File tree 2 files changed +84
-0
lines changed
2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 10
10
11
11
use std:: any:: Any ;
12
12
use std:: sync:: { Arc , Weak } ;
13
+ use std:: cell:: RefCell ;
14
+ use std:: cmp:: PartialEq ;
13
15
14
16
#[ test]
15
17
fn uninhabited ( ) {
@@ -53,3 +55,43 @@ fn trait_object() {
53
55
b = b. clone ( ) ;
54
56
assert ! ( b. upgrade( ) . is_none( ) ) ;
55
57
}
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
+ }
Original file line number Diff line number Diff line change 10
10
11
11
use std:: any:: Any ;
12
12
use std:: rc:: { Rc , Weak } ;
13
+ use std:: cell:: RefCell ;
14
+ use std:: cmp:: PartialEq ;
13
15
14
16
#[ test]
15
17
fn uninhabited ( ) {
@@ -53,3 +55,43 @@ fn trait_object() {
53
55
b = b. clone ( ) ;
54
56
assert ! ( b. upgrade( ) . is_none( ) ) ;
55
57
}
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
+ }
You can’t perform that action at this time.
0 commit comments