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.
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.
11 extern crate collections;
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;
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));
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));
33 assert_eq!(map.find(&Owned(~"foo")), Some(&v));
34 assert_eq!(map.find(&Slice("foo")), Some(&v));
36 let (a, b, c, d) = (50, 51, 52, 53);
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));
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));
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));
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));
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));
63 assert!(map.pop(&Slice("foo")).is_some());
64 assert_eq!(map.move_iter().map(|(k, v)| k.to_str() + v.to_str())
67 ~"abc50bcd51cde52def53");