diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 227712e31e675..50cbd36ced9f9 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -50,7 +50,7 @@ impl ToStr for (A,) { } } -impl ToStr for HashMap { +impl ToStr for HashMap { #[inline] fn to_str(&self) -> ~str { let mut acc = ~"{"; @@ -182,6 +182,8 @@ mod tests { use hashmap::HashMap; use hashmap::HashSet; use container::{MutableSet, MutableMap}; + use super::*; + #[test] fn test_simple_types() { assert_eq!(1i.to_str(), ~"1"); @@ -212,17 +214,27 @@ mod tests { ~"[[], [1], [1, 1]]"); } + struct StructWithToStrWithoutEqOrHash { + value: int + } + + impl ToStr for StructWithToStrWithoutEqOrHash { + fn to_str(&self) -> ~str { + fmt!("s%d", self.value) + } + } + #[test] fn test_hashmap() { - let mut table: HashMap = HashMap::new(); - let empty: HashMap = HashMap::new(); + let mut table: HashMap = HashMap::new(); + let empty: HashMap = HashMap::new(); - table.insert(3, 4); - table.insert(1, 2); + table.insert(3, StructWithToStrWithoutEqOrHash { value: 4 }); + table.insert(1, StructWithToStrWithoutEqOrHash { value: 2 }); let table_str = table.to_str(); - assert!(table_str == ~"{1: 2, 3: 4}" || table_str == ~"{3: 4, 1: 2}"); + assert!(table_str == ~"{1: s2, 3: s4}" || table_str == ~"{3: s4, 1: s2}"); assert_eq!(empty.to_str(), ~"{}"); }