Skip to content

Commit

Permalink
Modify collection's Debug output to resemble in their content only
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Feb 24, 2015
1 parent c9ace05 commit 408f7b5
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/libcollections/bit.rs
Expand Up @@ -978,7 +978,7 @@ impl Ord for BitVec {
impl fmt::Debug for BitVec {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
for bit in self {
try!(write!(fmt, "{}", if bit { 1u32 } else { 0u32 }));
try!(write!(fmt, "{}", if bit { 1 } else { 0 }));
}
Ok(())
}
Expand Down Expand Up @@ -1752,7 +1752,7 @@ impl BitSet {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for BitSet {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(write!(fmt, "BitSet {{"));
try!(write!(fmt, "{{"));
let mut first = true;
for n in self {
if !first {
Expand Down Expand Up @@ -2655,7 +2655,7 @@ mod bit_set_test {
s.insert(10);
s.insert(50);
s.insert(2);
assert_eq!("BitSet {1, 2, 10, 50}", format!("{:?}", s));
assert_eq!("{1, 2, 10, 50}", format!("{:?}", s));
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/enum_set.rs
Expand Up @@ -36,7 +36,7 @@ impl<E> Copy for EnumSet<E> {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(write!(fmt, "EnumSet {{"));
try!(write!(fmt, "{{"));
let mut first = true;
for e in self {
if !first {
Expand Down Expand Up @@ -314,11 +314,11 @@ mod test {
#[test]
fn test_show() {
let mut e = EnumSet::new();
assert!(format!("{:?}", e) == "EnumSet {}");
assert!(format!("{:?}", e) == "{}");
e.insert(A);
assert!(format!("{:?}", e) == "EnumSet {A}");
assert!(format!("{:?}", e) == "{A}");
e.insert(C);
assert!(format!("{:?}", e) == "EnumSet {A, C}");
assert!(format!("{:?}", e) == "{A, C}");
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/linked_list.rs
Expand Up @@ -918,7 +918,7 @@ impl<A: Clone> Clone for LinkedList<A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: fmt::Debug> fmt::Debug for LinkedList<A> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "LinkedList ["));
try!(write!(f, "["));

for (i, e) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
Expand Down Expand Up @@ -1387,10 +1387,10 @@ mod tests {
#[test]
fn test_show() {
let list: LinkedList<_> = (0..10).collect();
assert_eq!(format!("{:?}", list), "LinkedList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");

let list: LinkedList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect();
assert_eq!(format!("{:?}", list), "LinkedList [\"just\", \"one\", \"test\", \"more\"]");
assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]");
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/vec_deque.rs
Expand Up @@ -1754,7 +1754,7 @@ impl<A> Extend<A> for VecDeque<A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for VecDeque<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "VecDeque ["));
try!(write!(f, "["));

for (i, e) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
Expand Down Expand Up @@ -2435,12 +2435,12 @@ mod tests {
#[test]
fn test_show() {
let ringbuf: VecDeque<_> = (0..10).collect();
assert_eq!(format!("{:?}", ringbuf), "VecDeque [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
assert_eq!(format!("{:?}", ringbuf), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");

let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"].iter()
.cloned()
.collect();
assert_eq!(format!("{:?}", ringbuf), "VecDeque [\"just\", \"one\", \"test\", \"more\"]");
assert_eq!(format!("{:?}", ringbuf), "[\"just\", \"one\", \"test\", \"more\"]");
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/vec_map.rs
Expand Up @@ -739,7 +739,7 @@ impl<V: Ord> Ord for VecMap<V> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<V: fmt::Debug> fmt::Debug for VecMap<V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "VecMap {{"));
try!(write!(f, "{{"));

for (i, (k, v)) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
Expand Down Expand Up @@ -1318,8 +1318,8 @@ mod test_map {
map.insert(3, 4);

let map_str = format!("{:?}", map);
assert!(map_str == "VecMap {1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
assert_eq!(format!("{:?}", empty), "VecMap {}");
assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
assert_eq!(format!("{:?}", empty), "{}");
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/collections/hash/map.rs
Expand Up @@ -1212,7 +1212,7 @@ impl<K, V, S> Debug for HashMap<K, V, S>
where K: Eq + Hash + Debug, V: Debug, S: HashState
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "HashMap {{"));
try!(write!(f, "{{"));

for (i, (k, v)) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
Expand Down Expand Up @@ -1999,9 +1999,9 @@ mod test_map {

let map_str = format!("{:?}", map);

assert!(map_str == "HashMap {1: 2, 3: 4}" ||
map_str == "HashMap {3: 4, 1: 2}");
assert_eq!(format!("{:?}", empty), "HashMap {}");
assert!(map_str == "{1: 2, 3: 4}" ||
map_str == "{3: 4, 1: 2}");
assert_eq!(format!("{:?}", empty), "{}");
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/collections/hash/set.rs
Expand Up @@ -598,7 +598,7 @@ impl<T, S> fmt::Debug for HashSet<T, S>
S: HashState
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "HashSet {{"));
try!(write!(f, "{{"));

for (i, x) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
Expand Down Expand Up @@ -1186,8 +1186,8 @@ mod test_set {

let set_str = format!("{:?}", set);

assert!(set_str == "HashSet {1, 2}" || set_str == "HashSet {2, 1}");
assert_eq!(format!("{:?}", empty), "HashSet {}");
assert!(set_str == "{1, 2}" || set_str == "{2, 1}");
assert_eq!(format!("{:?}", empty), "{}");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/issue-3559.rs
Expand Up @@ -24,6 +24,6 @@ pub fn main() {
let mut table = HashMap::new();
table.insert("one".to_string(), 1);
table.insert("two".to_string(), 2);
assert!(check_strs(&format!("{:?}", table), "HashMap {\"one\": 1, \"two\": 2}") ||
check_strs(&format!("{:?}", table), "HashMap {\"two\": 2, \"one\": 1}"));
assert!(check_strs(&format!("{:?}", table), "{\"one\": 1, \"two\": 2}") ||
check_strs(&format!("{:?}", table), "{\"two\": 2, \"one\": 1}"));
}

0 comments on commit 408f7b5

Please sign in to comment.