12
12
13
13
use clone:: { Clone , DeepClone } ;
14
14
use cmp:: { Eq , TotalEq , Ord , TotalOrd , Equiv } ;
15
- use cmp:: { Ordering , Less } ;
15
+ use cmp:: Ordering ;
16
16
use container:: Container ;
17
17
use default:: Default ;
18
18
use str:: { Str , StrSlice } ;
@@ -64,9 +64,8 @@ impl IntoSendStr for &'static str {
64
64
}
65
65
66
66
/*
67
- Section: string trait impls
68
-
69
- `SendStr `should behave like a normal string, so we don't derive.
67
+ Section: String trait impls.
68
+ `SendStr` should behave like a normal string, so we don't derive.
70
69
*/
71
70
72
71
impl ToStr for SendStr {
@@ -90,7 +89,9 @@ impl TotalEq for SendStr {
90
89
91
90
impl Ord for SendStr {
92
91
#[ inline]
93
- fn lt ( & self , other : & SendStr ) -> bool { self . cmp ( other) == Less }
92
+ fn lt ( & self , other : & SendStr ) -> bool {
93
+ self . as_slice ( ) . lt ( & other. as_slice ( ) )
94
+ }
94
95
}
95
96
96
97
impl TotalOrd for SendStr {
@@ -179,20 +180,14 @@ mod tests {
179
180
use to_str:: ToStr ;
180
181
181
182
#[ test]
182
- fn test_send_str ( ) {
183
+ fn test_send_str_traits ( ) {
183
184
let s = SendStrStatic ( "abcde" ) ;
184
185
assert_eq ! ( s. len( ) , 5 ) ;
185
186
assert_eq ! ( s. as_slice( ) , "abcde" ) ;
186
187
assert_eq ! ( s. to_str( ) , ~"abcde");
187
188
assert!(s.equiv(&@" abcde"));
188
189
assert!(s.lt(&SendStrOwned(~" bcdef")));
189
190
assert_eq!(SendStrStatic(" "), Default::default());
190
- assert!(s.is_static());
191
- assert!(!s.is_owned());
192
-
193
- assert_eq!(s.clone(), s.clone());
194
- assert_eq!(s.clone().into_owned(), ~" abcde");
195
- assert_eq!(s.clone().deep_clone(), s.clone());
196
191
197
192
let o = SendStrOwned(~" abcde");
198
193
assert_eq!(o.len(), 5);
@@ -201,20 +196,50 @@ mod tests {
201
196
assert!(o.equiv(&@" abcde"));
202
197
assert!(o.lt(&SendStrStatic(" bcdef")));
203
198
assert_eq!(SendStrOwned(~" "), Default::default());
204
- assert!(!o.is_static());
205
- assert!(o.is_owned());
206
-
207
- assert_eq!(o.clone(), o.clone());
208
- assert_eq!(o.clone().into_owned(), ~" abcde");
209
- assert_eq!(o.clone().deep_clone(), o.clone());
210
199
211
200
assert_eq!(s.cmp(&o), Equal);
212
201
assert!(s.equals(&o));
213
202
assert!(s.equiv(&o));
203
+
214
204
assert_eq!(o.cmp(&s), Equal);
215
205
assert!(o.equals(&s));
216
206
assert!(o.equiv(&s));
207
+ }
208
+
209
+ #[test]
210
+ fn test_send_str_methods() {
211
+ let s = SendStrStatic(" abcde");
212
+ assert!(s.is_static());
213
+ assert!(!s.is_owned());
217
214
215
+ let o = SendStrOwned(~" abcde");
216
+ assert!(!o.is_static());
217
+ assert!(o.is_owned());
218
+ }
219
+
220
+ #[test]
221
+ fn test_send_str_clone() {
222
+ assert_eq!(SendStrOwned(~" abcde"), SendStrStatic(" abcde").clone());
223
+ assert_eq!(SendStrOwned(~" abcde"), SendStrStatic(" abcde").deep_clone());
224
+
225
+ assert_eq!(SendStrOwned(~" abcde"), SendStrOwned(~" abcde").clone());
226
+ assert_eq!(SendStrOwned(~" abcde"), SendStrOwned(~" abcde").deep_clone());
227
+
228
+ assert_eq!(SendStrStatic(" abcde"), SendStrStatic(" abcde").clone());
229
+ assert_eq!(SendStrStatic(" abcde"), SendStrStatic(" abcde").deep_clone());
230
+
231
+ assert_eq!(SendStrStatic(" abcde"), SendStrOwned(~" abcde").clone());
232
+ assert_eq!(SendStrStatic(" abcde"), SendStrOwned(~" abcde").deep_clone());
233
+ }
234
+
235
+ #[test]
236
+ fn test_send_str_into_owned() {
237
+ assert_eq!(SendStrStatic(" abcde").into_owned(), ~" abcde");
238
+ assert_eq!(SendStrOwned(~" abcde").into_owned(), ~" abcde");
239
+ }
240
+
241
+ #[test]
242
+ fn test_into_send_str() {
218
243
assert_eq!(" abcde".into_send_str(), SendStrStatic(" abcde"));
219
244
assert_eq!((~" abcde").into_send_str(), SendStrStatic(" abcde"));
220
245
assert_eq!(" abcde".into_send_str(), SendStrOwned(~" abcde"));
0 commit comments