]> git.lizzy.rs Git - rust.git/commitdiff
collections: add Show impl test for HashMap
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Mon, 26 May 2014 22:20:39 +0000 (15:20 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 27 May 2014 17:20:02 +0000 (10:20 -0700)
src/libcollections/hashmap.rs

index 1b79b84ff90852dd9691bb4b689a7ced11aa8400..c51061067dc1e72867c1c7197cc38f2e46fd7727 100644 (file)
@@ -2003,6 +2003,20 @@ fn test_eq() {
         assert_eq!(m1, m2);
     }
 
+    #[test]
+    fn test_show() {
+        let mut map: HashMap<int, int> = HashMap::new();
+        let empty: HashMap<int, int> = HashMap::new();
+
+        map.insert(1, 2);
+        map.insert(3, 4);
+
+        let map_str = format!("{}", map);
+
+        assert!(map_str == "{1: 2, 3: 4}".to_owned() || map_str == "{3: 4, 1: 2}".to_owned());
+        assert_eq!(format!("{}", empty), "{}".to_owned());
+    }
+
     #[test]
     fn test_expand() {
         let mut m = HashMap::new();