]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/send_str_treemap.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / send_str_treemap.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // pretty-expanded FIXME #23616
12
13 #![feature(collections, into_cow)]
14
15 extern crate collections;
16
17 use self::collections::BTreeMap;
18 use std::borrow::{Cow, IntoCow};
19
20 type SendStr = Cow<'static, str>;
21
22 pub fn main() {
23 let mut map: BTreeMap<SendStr, usize> = BTreeMap::new();
24 assert!(map.insert("foo".into_cow(), 42).is_none());
25 assert!(map.insert("foo".to_string().into_cow(), 42).is_some());
26 assert!(map.insert("foo".into_cow(), 42).is_some());
27 assert!(map.insert("foo".to_string().into_cow(), 42).is_some());
28
29 assert!(map.insert("foo".into_cow(), 43).is_some());
30 assert!(map.insert("foo".to_string().into_cow(), 44).is_some());
31 assert!(map.insert("foo".into_cow(), 45).is_some());
32 assert!(map.insert("foo".to_string().into_cow(), 46).is_some());
33
34 let v = 46;
35
36 assert_eq!(map.get(&"foo".to_string().into_cow()), Some(&v));
37 assert_eq!(map.get(&"foo".into_cow()), Some(&v));
38
39 let (a, b, c, d) = (50, 51, 52, 53);
40
41 assert!(map.insert("abc".into_cow(), a).is_none());
42 assert!(map.insert("bcd".to_string().into_cow(), b).is_none());
43 assert!(map.insert("cde".into_cow(), c).is_none());
44 assert!(map.insert("def".to_string().into_cow(), d).is_none());
45
46 assert!(map.insert("abc".into_cow(), a).is_some());
47 assert!(map.insert("bcd".to_string().into_cow(), b).is_some());
48 assert!(map.insert("cde".into_cow(), c).is_some());
49 assert!(map.insert("def".to_string().into_cow(), d).is_some());
50
51 assert!(map.insert("abc".to_string().into_cow(), a).is_some());
52 assert!(map.insert("bcd".into_cow(), b).is_some());
53 assert!(map.insert("cde".to_string().into_cow(), c).is_some());
54 assert!(map.insert("def".into_cow(), d).is_some());
55
56 assert_eq!(map.get(&"abc".into_cow()), Some(&a));
57 assert_eq!(map.get(&"bcd".into_cow()), Some(&b));
58 assert_eq!(map.get(&"cde".into_cow()), Some(&c));
59 assert_eq!(map.get(&"def".into_cow()), Some(&d));
60
61 assert_eq!(map.get(&"abc".to_string().into_cow()), Some(&a));
62 assert_eq!(map.get(&"bcd".to_string().into_cow()), Some(&b));
63 assert_eq!(map.get(&"cde".to_string().into_cow()), Some(&c));
64 assert_eq!(map.get(&"def".to_string().into_cow()), Some(&d));
65
66 assert!(map.remove(&"foo".into_cow()).is_some());
67 assert_eq!(map.into_iter().map(|(k, v)| format!("{}{}", k, v))
68 .collect::<Vec<String>>()
69 .concat(),
70 "abc50bcd51cde52def53".to_string());
71 }