]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/send_str_treemap.rs
auto merge of #13600 : brandonw/rust/master, r=brson
[rust.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 extern crate collections;
12
13 use std::container::{ Map, MutableMap};
14 use std::str::{SendStr, Owned, Slice};
15 use std::to_str::ToStr;
16 use self::collections::TreeMap;
17 use std::option::Some;
18
19 pub fn main() {
20     let mut map: TreeMap<SendStr, uint> = TreeMap::new();
21     assert!(map.insert(Slice("foo"), 42));
22     assert!(!map.insert(Owned(~"foo"), 42));
23     assert!(!map.insert(Slice("foo"), 42));
24     assert!(!map.insert(Owned(~"foo"), 42));
25
26     assert!(!map.insert(Slice("foo"), 43));
27     assert!(!map.insert(Owned(~"foo"), 44));
28     assert!(!map.insert(Slice("foo"), 45));
29     assert!(!map.insert(Owned(~"foo"), 46));
30
31     let v = 46;
32
33     assert_eq!(map.find(&Owned(~"foo")), Some(&v));
34     assert_eq!(map.find(&Slice("foo")), Some(&v));
35
36     let (a, b, c, d) = (50, 51, 52, 53);
37
38     assert!(map.insert(Slice("abc"), a));
39     assert!(map.insert(Owned(~"bcd"), b));
40     assert!(map.insert(Slice("cde"), c));
41     assert!(map.insert(Owned(~"def"), d));
42
43     assert!(!map.insert(Slice("abc"), a));
44     assert!(!map.insert(Owned(~"bcd"), b));
45     assert!(!map.insert(Slice("cde"), c));
46     assert!(!map.insert(Owned(~"def"), d));
47
48     assert!(!map.insert(Owned(~"abc"), a));
49     assert!(!map.insert(Slice("bcd"), b));
50     assert!(!map.insert(Owned(~"cde"), c));
51     assert!(!map.insert(Slice("def"), d));
52
53     assert_eq!(map.find(&Slice("abc")), Some(&a));
54     assert_eq!(map.find(&Slice("bcd")), Some(&b));
55     assert_eq!(map.find(&Slice("cde")), Some(&c));
56     assert_eq!(map.find(&Slice("def")), Some(&d));
57
58     assert_eq!(map.find(&Owned(~"abc")), Some(&a));
59     assert_eq!(map.find(&Owned(~"bcd")), Some(&b));
60     assert_eq!(map.find(&Owned(~"cde")), Some(&c));
61     assert_eq!(map.find(&Owned(~"def")), Some(&d));
62
63     assert!(map.pop(&Slice("foo")).is_some());
64     assert_eq!(map.move_iter().map(|(k, v)| k.to_str() + v.to_str())
65                               .collect::<~[~str]>()
66                               .concat(),
67                ~"abc50bcd51cde52def53");
68 }