Skip to content

Commit 0635cb7

Browse files
committed
Corrected a few small style issues
Split up test function a bit
1 parent 76c3e8a commit 0635cb7

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

src/libstd/send_str.rs

+43-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use clone::{Clone, DeepClone};
1414
use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv};
15-
use cmp::{Ordering, Less};
15+
use cmp::Ordering;
1616
use container::Container;
1717
use default::Default;
1818
use str::{Str, StrSlice};
@@ -64,9 +64,8 @@ impl IntoSendStr for &'static str {
6464
}
6565

6666
/*
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.
7069
*/
7170

7271
impl ToStr for SendStr {
@@ -90,7 +89,9 @@ impl TotalEq for SendStr {
9089

9190
impl Ord for SendStr {
9291
#[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+
}
9495
}
9596

9697
impl TotalOrd for SendStr {
@@ -179,20 +180,14 @@ mod tests {
179180
use to_str::ToStr;
180181

181182
#[test]
182-
fn test_send_str() {
183+
fn test_send_str_traits() {
183184
let s = SendStrStatic("abcde");
184185
assert_eq!(s.len(), 5);
185186
assert_eq!(s.as_slice(), "abcde");
186187
assert_eq!(s.to_str(), ~"abcde");
187188
assert!(s.equiv(&@"abcde"));
188189
assert!(s.lt(&SendStrOwned(~"bcdef")));
189190
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());
196191
197192
let o = SendStrOwned(~"abcde");
198193
assert_eq!(o.len(), 5);
@@ -201,20 +196,50 @@ mod tests {
201196
assert!(o.equiv(&@"abcde"));
202197
assert!(o.lt(&SendStrStatic("bcdef")));
203198
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());
210199
211200
assert_eq!(s.cmp(&o), Equal);
212201
assert!(s.equals(&o));
213202
assert!(s.equiv(&o));
203+
214204
assert_eq!(o.cmp(&s), Equal);
215205
assert!(o.equals(&s));
216206
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());
217214
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() {
218243
assert_eq!("abcde".into_send_str(), SendStrStatic("abcde"));
219244
assert_eq!((~"abcde").into_send_str(), SendStrStatic("abcde"));
220245
assert_eq!("abcde".into_send_str(), SendStrOwned(~"abcde"));

src/test/run-pass/send_str_treemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::default::Default;
1818
use std::send_str::{SendStr, SendStrOwned, SendStrStatic};
1919
use std::str::Str;
2020
use std::to_str::ToStr;
21-
use extra::treemap::TreeMap;
21+
use self::extra::treemap::TreeMap;
2222
use std::option::Some;
2323

2424
fn main() {

0 commit comments

Comments
 (0)