@@ -50,7 +50,7 @@ impl<A:ToStr> ToStr for (A,) {
50
50
}
51
51
}
52
52
53
- impl < A : ToStr +Hash +Eq , B : ToStr + Hash + Eq > ToStr for HashMap < A , B > {
53
+ impl < A : ToStr +Hash +Eq , B : ToStr > ToStr for HashMap < A , B > {
54
54
#[ inline]
55
55
fn to_str ( & self ) -> ~str {
56
56
let mut acc = ~"{ ";
@@ -182,6 +182,8 @@ mod tests {
182
182
use hashmap::HashMap;
183
183
use hashmap::HashSet;
184
184
use container::{MutableSet, MutableMap};
185
+ use super::*;
186
+
185
187
#[test]
186
188
fn test_simple_types() {
187
189
assert_eq!(1i.to_str(), ~" 1 ") ;
@@ -212,17 +214,27 @@ mod tests {
212
214
~" [ [ ] , [ 1 ] , [ 1 , 1 ] ] ");
213
215
}
214
216
217
+ struct StructWithToStrWithoutEqOrHash {
218
+ value: int
219
+ }
220
+
221
+ impl ToStr for StructWithToStrWithoutEqOrHash {
222
+ fn to_str(&self) -> ~str {
223
+ fmt!(" s%d", self.value)
224
+ }
225
+ }
226
+
215
227
#[test]
216
228
fn test_hashmap() {
217
- let mut table: HashMap<int, int > = HashMap::new();
218
- let empty: HashMap<int, int > = HashMap::new();
229
+ let mut table: HashMap<int, StructWithToStrWithoutEqOrHash > = HashMap::new();
230
+ let empty: HashMap<int, StructWithToStrWithoutEqOrHash > = HashMap::new();
219
231
220
- table.insert(3, 4 );
221
- table.insert(1, 2 );
232
+ table.insert(3, StructWithToStrWithoutEqOrHash { value: 4 } );
233
+ table.insert(1, StructWithToStrWithoutEqOrHash { value: 2 } );
222
234
223
235
let table_str = table.to_str();
224
236
225
- assert!(table_str == ~" { 1 : 2 , 3 : 4 } " || table_str == ~" { 3 : 4 , 1 : 2 } ");
237
+ assert!(table_str == ~" { 1 : s2 , 3 : s4 } " || table_str == ~" { 3 : s4 , 1 : s2 } ");
226
238
assert_eq!(empty.to_str(), ~" { } ");
227
239
}
228
240
0 commit comments