@@ -106,3 +106,57 @@ unsafe impl Encode for Bool {
106
106
unsafe impl RefEncode for Bool {
107
107
const ENCODING_REF : Encoding < ' static > = Encoding :: Pointer ( & Self :: ENCODING ) ;
108
108
}
109
+
110
+ #[ cfg( test) ]
111
+ mod tests {
112
+ use super :: * ;
113
+
114
+ #[ test]
115
+ fn test_basic ( ) {
116
+ let b = Bool :: new ( true ) ;
117
+ assert ! ( b. is_true( ) ) ;
118
+ assert ! ( !b. is_false( ) ) ;
119
+ assert ! ( bool :: from( b) ) ;
120
+ assert_eq ! ( b. as_raw( ) as usize , 1 ) ;
121
+
122
+ let b = Bool :: new ( false ) ;
123
+ assert ! ( !b. is_true( ) ) ;
124
+ assert ! ( b. is_false( ) ) ;
125
+ assert ! ( !bool :: from( b) ) ;
126
+ assert_eq ! ( b. as_raw( ) as usize , 0 ) ;
127
+ }
128
+
129
+ #[ test]
130
+ fn test_associated_constants ( ) {
131
+ let b = Bool :: YES ;
132
+ assert ! ( b. is_true( ) ) ;
133
+ assert_eq ! ( b. as_raw( ) as usize , 1 ) ;
134
+
135
+ let b = Bool :: NO ;
136
+ assert ! ( b. is_false( ) ) ;
137
+ assert_eq ! ( b. as_raw( ) as usize , 0 ) ;
138
+ }
139
+
140
+ #[ test]
141
+ fn test_impls ( ) {
142
+ let b: Bool = Default :: default ( ) ;
143
+ assert ! ( b. is_false( ) ) ;
144
+
145
+ assert ! ( Bool :: from( true ) . is_true( ) ) ;
146
+ assert ! ( Bool :: from( false ) . is_false( ) ) ;
147
+
148
+ assert ! ( Bool :: from( true ) . is_true( ) ) ;
149
+ assert ! ( Bool :: from( false ) . is_false( ) ) ;
150
+ }
151
+
152
+ // Can't really do this test since it won't compile on platforms where
153
+ // type BOOL = bool.
154
+ //
155
+ // #[test]
156
+ // fn test_outside_normal() {
157
+ // let b = Bool::from_raw(42);
158
+ // assert!(b.is_true());
159
+ // assert!(!b.is_false());
160
+ // assert_eq!(b.as_raw(), 42);
161
+ // }
162
+ }
0 commit comments