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 use std::clone::{Clone, DeepClone};
12 use std::cmp::{TotalEq, Ord, TotalOrd, Equiv};
14 use std::container::{Container, Map, MutableMap};
15 use std::default::Default;
16 use std::send_str::{SendStr, SendStrOwned, SendStrStatic};
18 use std::to_str::ToStr;
19 use std::hashmap::HashMap;
20 use std::option::Some;
23 let mut map: HashMap<SendStr, uint> = HashMap::new();
24 assert!(map.insert(SendStrStatic("foo"), 42));
25 assert!(!map.insert(SendStrOwned(~"foo"), 42));
26 assert!(!map.insert(SendStrStatic("foo"), 42));
27 assert!(!map.insert(SendStrOwned(~"foo"), 42));
29 assert!(!map.insert(SendStrStatic("foo"), 43));
30 assert!(!map.insert(SendStrOwned(~"foo"), 44));
31 assert!(!map.insert(SendStrStatic("foo"), 45));
32 assert!(!map.insert(SendStrOwned(~"foo"), 46));
36 assert_eq!(map.find(&SendStrOwned(~"foo")), Some(&v));
37 assert_eq!(map.find(&SendStrStatic("foo")), Some(&v));
39 let (a, b, c, d) = (50, 51, 52, 53);
41 assert!(map.insert(SendStrStatic("abc"), a));
42 assert!(map.insert(SendStrOwned(~"bcd"), b));
43 assert!(map.insert(SendStrStatic("cde"), c));
44 assert!(map.insert(SendStrOwned(~"def"), d));
46 assert!(!map.insert(SendStrStatic("abc"), a));
47 assert!(!map.insert(SendStrOwned(~"bcd"), b));
48 assert!(!map.insert(SendStrStatic("cde"), c));
49 assert!(!map.insert(SendStrOwned(~"def"), d));
51 assert!(!map.insert(SendStrOwned(~"abc"), a));
52 assert!(!map.insert(SendStrStatic("bcd"), b));
53 assert!(!map.insert(SendStrOwned(~"cde"), c));
54 assert!(!map.insert(SendStrStatic("def"), d));
56 assert_eq!(map.find_equiv(&("abc")), Some(&a));
57 assert_eq!(map.find_equiv(&("bcd")), Some(&b));
58 assert_eq!(map.find_equiv(&("cde")), Some(&c));
59 assert_eq!(map.find_equiv(&("def")), Some(&d));
61 assert_eq!(map.find_equiv(&(~"abc")), Some(&a));
62 assert_eq!(map.find_equiv(&(~"bcd")), Some(&b));
63 assert_eq!(map.find_equiv(&(~"cde")), Some(&c));
64 assert_eq!(map.find_equiv(&(~"def")), Some(&d));
66 assert_eq!(map.find_equiv(&SendStrStatic("abc")), Some(&a));
67 assert_eq!(map.find_equiv(&SendStrStatic("bcd")), Some(&b));
68 assert_eq!(map.find_equiv(&SendStrStatic("cde")), Some(&c));
69 assert_eq!(map.find_equiv(&SendStrStatic("def")), Some(&d));
71 assert_eq!(map.find_equiv(&SendStrOwned(~"abc")), Some(&a));
72 assert_eq!(map.find_equiv(&SendStrOwned(~"bcd")), Some(&b));
73 assert_eq!(map.find_equiv(&SendStrOwned(~"cde")), Some(&c));
74 assert_eq!(map.find_equiv(&SendStrOwned(~"def")), Some(&d));