Skip to content

std: Change assert_eq!() to use {} instead of {:?} #12626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/guide-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ the trailing underscore is a workaround for issue #5898 and will be removed.
~~~
let mut ys = [1, 2, 3, 4, 5];
ys.mut_iter().reverse_();
assert_eq!(ys, [5, 4, 3, 2, 1]);
assert!(ys == [5, 4, 3, 2, 1]);
~~~

## Random-access iterators
Expand Down
4 changes: 2 additions & 2 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ let x = Rc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let y = x.clone(); // a new owner
let z = x; // this moves `x` into `z`, rather than creating a new owner

assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
assert!(*z.borrow() == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

// the variable is mutable, but not the contents of the box
let mut a = Rc::new([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
Expand All @@ -1707,7 +1707,7 @@ let x = Gc::new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let y = x; // does not perform a move, unlike with `Rc`
let z = x;

assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
assert!(*z.borrow() == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
~~~

With shared ownership, mutability cannot be inherited so the boxes are always immutable. However,
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ mod tests {

let mut b = a.clone();

assert_eq!(&a, &b);
assert!(a == b);

assert!(b.remove(&1));
assert!(a.contains(&1));
Expand All @@ -1561,7 +1561,7 @@ mod tests {
let mut r = rng();
let mut bitv = 0 as uint;
b.iter(|| {
bitv |= (1 << ((r.next_u32() as uint) % uint::BITS));
bitv |= 1 << ((r.next_u32() as uint) % uint::BITS);
&bitv
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,11 +982,11 @@ mod tests {
fn test_eq() {
let mut n: DList<u8> = list_from([]);
let mut m = list_from([]);
assert_eq!(&n, &m);
assert!(n == m);
n.push_front(1);
assert!(n != m);
m.push_back(1);
assert_eq!(&n, &m);
assert!(n == m);

let n = list_from([2,3,4]);
let m = list_from([1,2,3]);
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod test {

use enum_set::{EnumSet, CLike};

#[deriving(Eq)]
#[deriving(Eq, Show)]
#[repr(uint)]
enum Foo {
A, B, C
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ mod test_map {
let mut observed = 0;
for (k, v) in m.iter() {
assert_eq!(*v, *k * 2);
observed |= (1 << *k);
observed |= 1 << *k;
}
assert_eq!(observed, 0xFFFF_FFFF);
}
Expand Down Expand Up @@ -1293,7 +1293,7 @@ mod test_set {
}
let mut observed = 0;
for k in a.iter() {
observed |= (1 << *k);
observed |= 1 << *k;
}
assert_eq!(observed, 0xFFFF_FFFF);
}
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ mod tests {
#[test]
fn test_from_vec_empty() {
let empty : list::List<int> = List::from_vec([]);
assert_eq!(empty, Nil::<int>);
assert!(empty == Nil::<int>);
}

#[test]
Expand Down Expand Up @@ -222,8 +222,8 @@ mod tests {

#[test]
fn test_append() {
assert_eq!(List::from_vec([1, 2, 3, 4]),
List::from_vec([1, 2]).append(List::from_vec([3, 4])));
assert!(List::from_vec([1, 2, 3, 4]) ==
List::from_vec([1, 2]).append(List::from_vec([3, 4])));
}

#[test]
Expand All @@ -232,6 +232,6 @@ mod tests {
let new_list = list.unshift(0);
assert_eq!(list.len(), 1u);
assert_eq!(new_list.len(), 2u);
assert_eq!(new_list, List::from_vec([0, 1]));
assert!(new_list == List::from_vec([0, 1]));
}
}
2 changes: 1 addition & 1 deletion src/libcollections/lru_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ mod tests {

fn assert_opt_eq<V: Eq>(opt: Option<&V>, v: V) {
assert!(opt.is_some());
assert_eq!(opt.unwrap(), &v);
assert!(opt.unwrap() == &v);
}

#[test]
Expand Down
15 changes: 8 additions & 7 deletions src/libcollections/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ mod tests {
use deque::Deque;
use std::clone::Clone;
use std::cmp::Eq;
use std::fmt::Show;
use super::RingBuf;

#[test]
Expand Down Expand Up @@ -493,7 +494,7 @@ mod tests {
}

#[cfg(test)]
fn test_parameterized<T:Clone + Eq>(a: T, b: T, c: T, d: T) {
fn test_parameterized<T:Clone + Eq + Show>(a: T, b: T, c: T, d: T) {
let mut deq = RingBuf::new();
assert_eq!(deq.len(), 0);
deq.push_front(a.clone());
Expand Down Expand Up @@ -578,21 +579,21 @@ mod tests {
})
}

#[deriving(Clone, Eq)]
#[deriving(Clone, Eq, Show)]
enum Taggy {
One(int),
Two(int, int),
Three(int, int, int),
}

#[deriving(Clone, Eq)]
#[deriving(Clone, Eq, Show)]
enum Taggypar<T> {
Onepar(int),
Twopar(int, int),
Threepar(int, int, int),
}

#[deriving(Clone, Eq)]
#[deriving(Clone, Eq, Show)]
struct RecCy {
x: int,
y: int,
Expand Down Expand Up @@ -812,7 +813,7 @@ mod tests {
#[test]
fn test_eq() {
let mut d = RingBuf::new();
assert_eq!(&d, &RingBuf::with_capacity(0));
assert!(d == RingBuf::with_capacity(0));
d.push_front(137);
d.push_front(17);
d.push_front(42);
Expand All @@ -822,11 +823,11 @@ mod tests {
e.push_back(17);
e.push_back(137);
e.push_back(137);
assert_eq!(&e, &d);
assert!(&e == &d);
e.pop_back();
e.push_back(0);
assert!(e != d);
e.clear();
assert_eq!(e, RingBuf::new());
assert!(e == RingBuf::new());
}
}
2 changes: 1 addition & 1 deletion src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ mod tests {
aliases: ~[] }];
let verbose = reqopt("b", "banana", "some bananas", "VAL");

assert_eq!(verbose.long_to_short(), short);
assert!(verbose.long_to_short() == short);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libnum/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ fn get_radix_base(radix: uint) -> (uint, uint) {
}

/// A Sign is a `BigInt`'s composing element.
#[deriving(Eq, Clone)]
#[deriving(Eq, Clone, Show)]
pub enum Sign { Minus, Zero, Plus }

impl Ord for Sign {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod test {
#[test]
fn test_minimize1() {
let res = minimize_rpaths([~"rpath1", ~"rpath2", ~"rpath1"]);
assert_eq!(res.as_slice(), [~"rpath1", ~"rpath2"]);
assert!(res.as_slice() == [~"rpath1", ~"rpath2"]);
}

#[test]
Expand All @@ -224,7 +224,7 @@ mod test {
~"1a", ~"4a", ~"1a",
~"2", ~"3", ~"4a",
~"3"]);
assert_eq!(res.as_slice(), [~"1a", ~"2", ~"4a", ~"3"]);
assert!(res.as_slice() == [~"1a", ~"2", ~"4a", ~"3"]);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ fn roundtrip(in_item: Option<@ast::Item>) {
let ebml_doc = reader::Doc(wr.get_ref());
let out_item = decode_item_ast(ebml_doc);

assert_eq!(in_item, out_item);
assert!(in_item == out_item);
}

#[test]
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/middle/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,19 @@ mod test {
start_data: N,
expected_incoming: &[(E,N)],
expected_outgoing: &[(E,N)]) {
assert_eq!(graph.node_data(start_index), &start_data);
assert!(graph.node_data(start_index) == &start_data);

let mut counter = 0;
graph.each_incoming_edge(start_index, |edge_index, edge| {
assert_eq!(graph.edge_data(edge_index), &edge.data);
assert!(graph.edge_data(edge_index) == &edge.data);
assert!(counter < expected_incoming.len());
debug!("counter={:?} expected={:?} edge_index={:?} edge={:?}",
counter, expected_incoming[counter], edge_index, edge);
match expected_incoming[counter] {
(ref e, ref n) => {
assert_eq!(e, &edge.data);
assert_eq!(n, graph.node_data(edge.source));
assert_eq!(start_index, edge.target);
assert!(e == &edge.data);
assert!(n == graph.node_data(edge.source));
assert!(start_index == edge.target);
}
}
counter += 1;
Expand All @@ -371,15 +371,15 @@ mod test {

let mut counter = 0;
graph.each_outgoing_edge(start_index, |edge_index, edge| {
assert_eq!(graph.edge_data(edge_index), &edge.data);
assert!(graph.edge_data(edge_index) == &edge.data);
assert!(counter < expected_outgoing.len());
debug!("counter={:?} expected={:?} edge_index={:?} edge={:?}",
counter, expected_outgoing[counter], edge_index, edge);
match expected_outgoing[counter] {
(ref e, ref n) => {
assert_eq!(e, &edge.data);
assert_eq!(start_index, edge.source);
assert_eq!(n, graph.node_data(edge.target));
assert!(e == &edge.data);
assert!(start_index == edge.source);
assert!(n == graph.node_data(edge.target));
}
}
counter += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::cast;

use std::libc::{c_uint};

#[deriving(Clone, Eq)]
#[deriving(Clone, Eq, Show)]
pub struct Type {
priv rf: TypeRef
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/infer/region_inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ impl RegionVarBindings {

// ______________________________________________________________________

#[deriving(Eq)]
#[deriving(Eq, Show)]
enum Classification { Expanding, Contracting }

enum VarValue { NoValue, Value(Region), ErrorValue }
Expand Down
6 changes: 3 additions & 3 deletions src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,20 +1588,20 @@ mod tests {
use std::io;
use collections::TreeMap;

#[deriving(Eq, Encodable, Decodable)]
#[deriving(Eq, Encodable, Decodable, Show)]
enum Animal {
Dog,
Frog(~str, int)
}

#[deriving(Eq, Encodable, Decodable)]
#[deriving(Eq, Encodable, Decodable, Show)]
struct Inner {
a: (),
b: uint,
c: ~[~str],
}

#[deriving(Eq, Encodable, Decodable)]
#[deriving(Eq, Encodable, Decodable, Show)]
struct Outer {
inner: ~[Inner],
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod tests {
use prelude::*;
use super::*;

#[deriving(Eq)]
#[deriving(Eq, Show)]
struct Test;

static TEST: &'static str = "Test";
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ mod tests {
use char::from_u32;

macro_rules! v2ascii (
( [$($e:expr),*]) => ( [$(Ascii{chr:$e}),*]);
( [$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
(&[$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
(~[$($e:expr),*]) => (~[$(Ascii{chr:$e}),*]);
)
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ mod tests {

#[test]
fn test_totalord() {
assert_eq!(true.cmp(&true), Equal);
assert_eq!(false.cmp(&false), Equal);
assert_eq!(true.cmp(&false), Greater);
assert_eq!(false.cmp(&true), Less);
assert!(true.cmp(&true) == Equal);
assert!(false.cmp(&false) == Equal);
assert!(true.cmp(&false) == Greater);
assert!(false.cmp(&true) == Less);
}
}
11 changes: 9 additions & 2 deletions src/libstd/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

//! Types dealing with dynamic mutability

use cast;
use clone::{Clone, DeepClone};
use cmp::Eq;
use fmt;
use kinds::{marker, Pod};
use ops::Drop;
use option::{None, Option, Some};
use cast;
use kinds::{marker, Pod};

/// A mutable memory location that admits only `Pod` data.
pub struct Cell<T> {
Expand Down Expand Up @@ -61,6 +62,12 @@ impl<T:Eq + Pod> Eq for Cell<T> {
}
}

impl<T: fmt::Show> fmt::Show for Cell<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, r"Cell \{ value: {} \}", self.value)
}
}

/// A mutable memory location with dynamically checked borrow rules
pub struct RefCell<T> {
priv value: T,
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ totaleq_impl!(uint)

totaleq_impl!(char)

#[deriving(Clone, Eq)]
#[deriving(Clone, Eq, Show)]
pub enum Ordering { Less = -1, Equal = 0, Greater = 1 }

/// Trait for types that form a total order
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/comm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub struct Chan<T> {

/// This enumeration is the list of the possible reasons that try_recv could not
/// return data when called.
#[deriving(Eq, Clone)]
#[deriving(Eq, Clone, Show)]
pub enum TryRecvResult<T> {
/// This channel is currently empty, but the sender(s) have not yet
/// disconnected, so data may yet become available.
Expand Down
Loading