diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 7922103029b..f2db9ca919d 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -288,16 +288,16 @@ fn test_is_whitespace() { #[test] fn test_to_digit() { - fail_unless!(to_digit('0', 10u) == Some(0u)); - fail_unless!(to_digit('1', 2u) == Some(1u)); - fail_unless!(to_digit('2', 3u) == Some(2u)); - fail_unless!(to_digit('9', 10u) == Some(9u)); - fail_unless!(to_digit('a', 16u) == Some(10u)); - fail_unless!(to_digit('A', 16u) == Some(10u)); - fail_unless!(to_digit('b', 16u) == Some(11u)); - fail_unless!(to_digit('B', 16u) == Some(11u)); - fail_unless!(to_digit('z', 36u) == Some(35u)); - fail_unless!(to_digit('Z', 36u) == Some(35u)); + assert_eq!(to_digit('0', 10u), Some(0u)); + assert_eq!(to_digit('1', 2u), Some(1u)); + assert_eq!(to_digit('2', 3u), Some(2u)); + assert_eq!(to_digit('9', 10u), Some(9u)); + assert_eq!(to_digit('a', 16u), Some(10u)); + assert_eq!(to_digit('A', 16u), Some(10u)); + assert_eq!(to_digit('b', 16u), Some(11u)); + assert_eq!(to_digit('B', 16u), Some(11u)); + assert_eq!(to_digit('z', 36u), Some(35u)); + assert_eq!(to_digit('Z', 36u), Some(35u)); fail_unless!(to_digit(' ', 10u).is_none()); fail_unless!(to_digit('$', 36u).is_none()); @@ -321,28 +321,28 @@ fn test_is_digit() { #[test] fn test_escape_default() { - fail_unless!(escape_default('\n') == ~"\\n"); - fail_unless!(escape_default('\r') == ~"\\r"); - fail_unless!(escape_default('\'') == ~"\\'"); - fail_unless!(escape_default('"') == ~"\\\""); - fail_unless!(escape_default(' ') == ~" "); - fail_unless!(escape_default('a') == ~"a"); - fail_unless!(escape_default('~') == ~"~"); - fail_unless!(escape_default('\x00') == ~"\\x00"); - fail_unless!(escape_default('\x1f') == ~"\\x1f"); - fail_unless!(escape_default('\x7f') == ~"\\x7f"); - fail_unless!(escape_default('\xff') == ~"\\xff"); - fail_unless!(escape_default('\u011b') == ~"\\u011b"); - fail_unless!(escape_default('\U0001d4b6') == ~"\\U0001d4b6"); + assert_eq!(escape_default('\n'), ~"\\n"); + assert_eq!(escape_default('\r'), ~"\\r"); + assert_eq!(escape_default('\''), ~"\\'"); + assert_eq!(escape_default('"'), ~"\\\""); + assert_eq!(escape_default(' '), ~" "); + assert_eq!(escape_default('a'), ~"a"); + assert_eq!(escape_default('~'), ~"~"); + assert_eq!(escape_default('\x00'), ~"\\x00"); + assert_eq!(escape_default('\x1f'), ~"\\x1f"); + assert_eq!(escape_default('\x7f'), ~"\\x7f"); + assert_eq!(escape_default('\xff'), ~"\\xff"); + assert_eq!(escape_default('\u011b'), ~"\\u011b"); + assert_eq!(escape_default('\U0001d4b6'), ~"\\U0001d4b6"); } #[test] fn test_escape_unicode() { - fail_unless!(escape_unicode('\x00') == ~"\\x00"); - fail_unless!(escape_unicode('\n') == ~"\\x0a"); - fail_unless!(escape_unicode(' ') == ~"\\x20"); - fail_unless!(escape_unicode('a') == ~"\\x61"); - fail_unless!(escape_unicode('\u011b') == ~"\\u011b"); - fail_unless!(escape_unicode('\U0001d4b6') == ~"\\U0001d4b6"); + assert_eq!(escape_unicode('\x00'), ~"\\x00"); + assert_eq!(escape_unicode('\n'), ~"\\x0a"); + assert_eq!(escape_unicode(' '), ~"\\x20"); + assert_eq!(escape_unicode('a'), ~"\\x61"); + assert_eq!(escape_unicode('\u011b'), ~"\\u011b"); + assert_eq!(escape_unicode('\U0001d4b6'), ~"\\U0001d4b6"); } diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 81f6a7e4266..25778f08757 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -172,10 +172,10 @@ pub pure fn max(v1: T, v2: T) -> T { mod test { #[test] fn test_int() { - fail_unless!(5.cmp(&10) == Less); - fail_unless!(10.cmp(&5) == Greater); - fail_unless!(5.cmp(&5) == Equal); - fail_unless!((-5).cmp(&12) == Less); - fail_unless!(12.cmp(-5) == Greater); + assert_eq!(5.cmp(&10), Less); + assert_eq!(10.cmp(&5), Greater); + assert_eq!(5.cmp(&5), Equal); + assert_eq!((-5).cmp(&12), Less); + assert_eq!(12.cmp(-5), Greater); } } diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 1b5d03d9eb8..5a230da877f 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -555,15 +555,15 @@ mod tests { let ab = from_vec(~[a,b]); let cd = from_vec(~[c,d]); let abcd = concat(concat(from_vec(~[ab,cd]))); - abcd.assert_consistent(); fail_unless!(abcd.len() == 8); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 1); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 2); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 3); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 4); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 5); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 6); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 7); - abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 8); + abcd.assert_consistent(); assert_eq!(abcd.len(), 8); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 1); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 2); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 3); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 4); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 5); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 6); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 7); + abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 8); abcd.assert_consistent(); fail_unless!(abcd.is_empty()); } #[test] @@ -571,15 +571,15 @@ mod tests { let a = from_vec(~[1,2,3]); let b = from_vec(~[4,5,6]); a.append(b); - fail_unless!(a.len() == 6); - fail_unless!(b.len() == 0); + assert_eq!(a.len(), 6); + assert_eq!(b.len(), 0); b.assert_consistent(); - a.assert_consistent(); fail_unless!(a.pop().get() == 1); - a.assert_consistent(); fail_unless!(a.pop().get() == 2); - a.assert_consistent(); fail_unless!(a.pop().get() == 3); - a.assert_consistent(); fail_unless!(a.pop().get() == 4); - a.assert_consistent(); fail_unless!(a.pop().get() == 5); - a.assert_consistent(); fail_unless!(a.pop().get() == 6); + a.assert_consistent(); assert_eq!(a.pop().get(), 1); + a.assert_consistent(); assert_eq!(a.pop().get(), 2); + a.assert_consistent(); assert_eq!(a.pop().get(), 3); + a.assert_consistent(); assert_eq!(a.pop().get(), 4); + a.assert_consistent(); assert_eq!(a.pop().get(), 5); + a.assert_consistent(); assert_eq!(a.pop().get(), 6); a.assert_consistent(); fail_unless!(a.is_empty()); } #[test] @@ -587,12 +587,12 @@ mod tests { let a = from_vec(~[1,2,3]); let b = DList::(); a.append(b); - fail_unless!(a.len() == 3); - fail_unless!(b.len() == 0); + assert_eq!(a.len(), 3); + assert_eq!(b.len(), 0); b.assert_consistent(); - a.assert_consistent(); fail_unless!(a.pop().get() == 1); - a.assert_consistent(); fail_unless!(a.pop().get() == 2); - a.assert_consistent(); fail_unless!(a.pop().get() == 3); + a.assert_consistent(); assert_eq!(a.pop().get(), 1); + a.assert_consistent(); assert_eq!(a.pop().get(), 2); + a.assert_consistent(); assert_eq!(a.pop().get(), 3); a.assert_consistent(); fail_unless!(a.is_empty()); } #[test] @@ -600,12 +600,12 @@ mod tests { let a = DList::(); let b = from_vec(~[4,5,6]); a.append(b); - fail_unless!(a.len() == 3); - fail_unless!(b.len() == 0); + assert_eq!(a.len(), 3); + assert_eq!(b.len(), 0); b.assert_consistent(); - a.assert_consistent(); fail_unless!(a.pop().get() == 4); - a.assert_consistent(); fail_unless!(a.pop().get() == 5); - a.assert_consistent(); fail_unless!(a.pop().get() == 6); + a.assert_consistent(); assert_eq!(a.pop().get(), 4); + a.assert_consistent(); assert_eq!(a.pop().get(), 5); + a.assert_consistent(); assert_eq!(a.pop().get(), 6); a.assert_consistent(); fail_unless!(a.is_empty()); } #[test] @@ -613,8 +613,8 @@ mod tests { let a = DList::(); let b = DList::(); a.append(b); - fail_unless!(a.len() == 0); - fail_unless!(b.len() == 0); + assert_eq!(a.len(), 0); + assert_eq!(b.len(), 0); b.assert_consistent(); a.assert_consistent(); } @@ -637,34 +637,34 @@ mod tests { let a = from_vec(~[1,2,3]); let b = from_vec(~[4,5,6]); b.prepend(a); - fail_unless!(a.len() == 0); - fail_unless!(b.len() == 6); + assert_eq!(a.len(), 0); + assert_eq!(b.len(), 6); a.assert_consistent(); - b.assert_consistent(); fail_unless!(b.pop().get() == 1); - b.assert_consistent(); fail_unless!(b.pop().get() == 2); - b.assert_consistent(); fail_unless!(b.pop().get() == 3); - b.assert_consistent(); fail_unless!(b.pop().get() == 4); - b.assert_consistent(); fail_unless!(b.pop().get() == 5); - b.assert_consistent(); fail_unless!(b.pop().get() == 6); + b.assert_consistent(); assert_eq!(b.pop().get(), 1); + b.assert_consistent(); assert_eq!(b.pop().get(), 2); + b.assert_consistent(); assert_eq!(b.pop().get(), 3); + b.assert_consistent(); assert_eq!(b.pop().get(), 4); + b.assert_consistent(); assert_eq!(b.pop().get(), 5); + b.assert_consistent(); assert_eq!(b.pop().get(), 6); b.assert_consistent(); fail_unless!(b.is_empty()); } #[test] pub fn test_dlist_reverse() { let a = from_vec(~[5,4,3,2,1]); a.reverse(); - fail_unless!(a.len() == 5); - a.assert_consistent(); fail_unless!(a.pop().get() == 1); - a.assert_consistent(); fail_unless!(a.pop().get() == 2); - a.assert_consistent(); fail_unless!(a.pop().get() == 3); - a.assert_consistent(); fail_unless!(a.pop().get() == 4); - a.assert_consistent(); fail_unless!(a.pop().get() == 5); + assert_eq!(a.len(), 5); + a.assert_consistent(); assert_eq!(a.pop().get(), 1); + a.assert_consistent(); assert_eq!(a.pop().get(), 2); + a.assert_consistent(); assert_eq!(a.pop().get(), 3); + a.assert_consistent(); assert_eq!(a.pop().get(), 4); + a.assert_consistent(); assert_eq!(a.pop().get(), 5); a.assert_consistent(); fail_unless!(a.is_empty()); } #[test] pub fn test_dlist_reverse_empty() { let a = DList::(); a.reverse(); - fail_unless!(a.len() == 0); + assert_eq!(a.len(), 0); a.assert_consistent(); } #[test] @@ -675,20 +675,20 @@ mod tests { a.insert_before(3, nobe); } } - fail_unless!(a.len() == 6); - a.assert_consistent(); fail_unless!(a.pop().get() == 1); - a.assert_consistent(); fail_unless!(a.pop().get() == 2); - a.assert_consistent(); fail_unless!(a.pop().get() == 3); - a.assert_consistent(); fail_unless!(a.pop().get() == 4); - a.assert_consistent(); fail_unless!(a.pop().get() == 3); - a.assert_consistent(); fail_unless!(a.pop().get() == 5); + assert_eq!(a.len(), 6); + a.assert_consistent(); assert_eq!(a.pop().get(), 1); + a.assert_consistent(); assert_eq!(a.pop().get(), 2); + a.assert_consistent(); assert_eq!(a.pop().get(), 3); + a.assert_consistent(); assert_eq!(a.pop().get(), 4); + a.assert_consistent(); assert_eq!(a.pop().get(), 3); + a.assert_consistent(); assert_eq!(a.pop().get(), 5); a.assert_consistent(); fail_unless!(a.is_empty()); } #[test] pub fn test_dlist_clear() { let a = from_vec(~[5,4,3,2,1]); a.clear(); - fail_unless!(a.len() == 0); + assert_eq!(a.len(), 0); a.assert_consistent(); } #[test] @@ -701,33 +701,33 @@ mod tests { #[test] pub fn test_dlist_head_tail() { let l = from_vec(~[1,2,3]); - fail_unless!(l.head() == 1); - fail_unless!(l.tail() == 3); - fail_unless!(l.len() == 3); + assert_eq!(l.head(), 1); + assert_eq!(l.tail(), 3); + assert_eq!(l.len(), 3); } #[test] pub fn test_dlist_pop() { let l = from_vec(~[1,2,3]); - fail_unless!(l.pop().get() == 1); - fail_unless!(l.tail() == 3); - fail_unless!(l.head() == 2); - fail_unless!(l.pop().get() == 2); - fail_unless!(l.tail() == 3); - fail_unless!(l.head() == 3); - fail_unless!(l.pop().get() == 3); + assert_eq!(l.pop().get(), 1); + assert_eq!(l.tail(), 3); + assert_eq!(l.head(), 2); + assert_eq!(l.pop().get(), 2); + assert_eq!(l.tail(), 3); + assert_eq!(l.head(), 3); + assert_eq!(l.pop().get(), 3); fail_unless!(l.is_empty()); fail_unless!(l.pop().is_none()); } #[test] pub fn test_dlist_pop_tail() { let l = from_vec(~[1,2,3]); - fail_unless!(l.pop_tail().get() == 3); - fail_unless!(l.tail() == 2); - fail_unless!(l.head() == 1); - fail_unless!(l.pop_tail().get() == 2); - fail_unless!(l.tail() == 1); - fail_unless!(l.head() == 1); - fail_unless!(l.pop_tail().get() == 1); + assert_eq!(l.pop_tail().get(), 3); + assert_eq!(l.tail(), 2); + assert_eq!(l.head(), 1); + assert_eq!(l.pop_tail().get(), 2); + assert_eq!(l.tail(), 1); + assert_eq!(l.head(), 1); + assert_eq!(l.pop_tail().get(), 1); fail_unless!(l.is_empty()); fail_unless!(l.pop_tail().is_none()); } @@ -735,34 +735,34 @@ mod tests { pub fn test_dlist_push() { let l = DList::(); l.push(1); - fail_unless!(l.head() == 1); - fail_unless!(l.tail() == 1); + assert_eq!(l.head(), 1); + assert_eq!(l.tail(), 1); l.push(2); - fail_unless!(l.head() == 1); - fail_unless!(l.tail() == 2); + assert_eq!(l.head(), 1); + assert_eq!(l.tail(), 2); l.push(3); - fail_unless!(l.head() == 1); - fail_unless!(l.tail() == 3); - fail_unless!(l.len() == 3); + assert_eq!(l.head(), 1); + assert_eq!(l.tail(), 3); + assert_eq!(l.len(), 3); } #[test] pub fn test_dlist_push_head() { let l = DList::(); l.push_head(3); - fail_unless!(l.head() == 3); - fail_unless!(l.tail() == 3); + assert_eq!(l.head(), 3); + assert_eq!(l.tail(), 3); l.push_head(2); - fail_unless!(l.head() == 2); - fail_unless!(l.tail() == 3); + assert_eq!(l.head(), 2); + assert_eq!(l.tail(), 3); l.push_head(1); - fail_unless!(l.head() == 1); - fail_unless!(l.tail() == 3); - fail_unless!(l.len() == 3); + assert_eq!(l.head(), 1); + assert_eq!(l.tail(), 3); + assert_eq!(l.len(), 3); } #[test] pub fn test_dlist_foldl() { let l = from_vec(vec::from_fn(101, |x|x)); - fail_unless!(iter::foldl(&l, 0, |accum,elem| *accum+*elem) == 5050); + assert_eq!(iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050); } #[test] pub fn test_dlist_break_early() { @@ -772,7 +772,7 @@ mod tests { x += 1; if (*i == 3) { break; } } - fail_unless!(x == 3); + assert_eq!(x, 3); } #[test] pub fn test_dlist_remove_head() { @@ -780,13 +780,13 @@ mod tests { l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _three = l.push_n(3); - l.assert_consistent(); fail_unless!(l.len() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); l.assert_consistent(); l.remove(one); - l.assert_consistent(); fail_unless!(l.len() == 2); - l.assert_consistent(); fail_unless!(l.head() == 2); - l.assert_consistent(); fail_unless!(l.tail() == 3); - l.assert_consistent(); fail_unless!(l.pop().get() == 2); - l.assert_consistent(); fail_unless!(l.pop().get() == 3); + l.assert_consistent(); assert_eq!(l.len(), 2); + l.assert_consistent(); assert_eq!(l.head(), 2); + l.assert_consistent(); assert_eq!(l.tail(), 3); + l.assert_consistent(); assert_eq!(l.pop().get(), 2); + l.assert_consistent(); assert_eq!(l.pop().get(), 3); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -795,13 +795,13 @@ mod tests { l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let _three = l.push_n(3); - l.assert_consistent(); fail_unless!(l.len() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); l.assert_consistent(); l.remove(two); - l.assert_consistent(); fail_unless!(l.len() == 2); - l.assert_consistent(); fail_unless!(l.head() == 1); - l.assert_consistent(); fail_unless!(l.tail() == 3); - l.assert_consistent(); fail_unless!(l.pop().get() == 1); - l.assert_consistent(); fail_unless!(l.pop().get() == 3); + l.assert_consistent(); assert_eq!(l.len(), 2); + l.assert_consistent(); assert_eq!(l.head(), 1); + l.assert_consistent(); assert_eq!(l.tail(), 3); + l.assert_consistent(); assert_eq!(l.pop().get(), 1); + l.assert_consistent(); assert_eq!(l.pop().get(), 3); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -810,13 +810,13 @@ mod tests { l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let three = l.push_n(3); - l.assert_consistent(); fail_unless!(l.len() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); l.assert_consistent(); l.remove(three); - l.assert_consistent(); fail_unless!(l.len() == 2); - l.assert_consistent(); fail_unless!(l.head() == 1); - l.assert_consistent(); fail_unless!(l.tail() == 2); - l.assert_consistent(); fail_unless!(l.pop().get() == 1); - l.assert_consistent(); fail_unless!(l.pop().get() == 2); + l.assert_consistent(); assert_eq!(l.len(), 2); + l.assert_consistent(); assert_eq!(l.head(), 1); + l.assert_consistent(); assert_eq!(l.tail(), 2); + l.assert_consistent(); assert_eq!(l.pop().get(), 1); + l.assert_consistent(); assert_eq!(l.pop().get(), 2); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -825,14 +825,14 @@ mod tests { l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let _three = l.push_n(3); - l.assert_consistent(); fail_unless!(l.len() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); l.assert_consistent(); l.remove(one); l.assert_consistent(); l.remove(two); // and through and through, the vorpal blade went snicker-snack - l.assert_consistent(); fail_unless!(l.len() == 1); - l.assert_consistent(); fail_unless!(l.head() == 3); - l.assert_consistent(); fail_unless!(l.tail() == 3); - l.assert_consistent(); fail_unless!(l.pop().get() == 3); + l.assert_consistent(); assert_eq!(l.len(), 1); + l.assert_consistent(); assert_eq!(l.head(), 3); + l.assert_consistent(); assert_eq!(l.tail(), 3); + l.assert_consistent(); assert_eq!(l.pop().get(), 3); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -841,13 +841,13 @@ mod tests { l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let three = l.push_n(3); - l.assert_consistent(); fail_unless!(l.len() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); l.assert_consistent(); l.remove(one); l.assert_consistent(); l.remove(three); - l.assert_consistent(); fail_unless!(l.len() == 1); - l.assert_consistent(); fail_unless!(l.head() == 2); - l.assert_consistent(); fail_unless!(l.tail() == 2); - l.assert_consistent(); fail_unless!(l.pop().get() == 2); + l.assert_consistent(); assert_eq!(l.len(), 1); + l.assert_consistent(); assert_eq!(l.head(), 2); + l.assert_consistent(); assert_eq!(l.tail(), 2); + l.assert_consistent(); assert_eq!(l.pop().get(), 2); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -856,13 +856,13 @@ mod tests { l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let three = l.push_n(3); - l.assert_consistent(); fail_unless!(l.len() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); l.assert_consistent(); l.remove(two); l.assert_consistent(); l.remove(three); - l.assert_consistent(); fail_unless!(l.len() == 1); - l.assert_consistent(); fail_unless!(l.head() == 1); - l.assert_consistent(); fail_unless!(l.tail() == 1); - l.assert_consistent(); fail_unless!(l.pop().get() == 1); + l.assert_consistent(); assert_eq!(l.len(), 1); + l.assert_consistent(); assert_eq!(l.head(), 1); + l.assert_consistent(); assert_eq!(l.tail(), 1); + l.assert_consistent(); assert_eq!(l.pop().get(), 1); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -871,7 +871,7 @@ mod tests { l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let three = l.push_n(3); - l.assert_consistent(); fail_unless!(l.len() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); l.assert_consistent(); l.remove(two); l.assert_consistent(); l.remove(three); l.assert_consistent(); l.remove(one); // Twenty-three is number one! @@ -884,14 +884,14 @@ mod tests { l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let three = new_dlist_node(3); - l.assert_consistent(); fail_unless!(l.len() == 2); + l.assert_consistent(); assert_eq!(l.len(), 2); l.assert_consistent(); l.insert_n_before(three, two); - l.assert_consistent(); fail_unless!(l.len() == 3); - l.assert_consistent(); fail_unless!(l.head() == 1); - l.assert_consistent(); fail_unless!(l.tail() == 2); - l.assert_consistent(); fail_unless!(l.pop().get() == 1); - l.assert_consistent(); fail_unless!(l.pop().get() == 3); - l.assert_consistent(); fail_unless!(l.pop().get() == 2); + l.assert_consistent(); assert_eq!(l.len(), 3); + l.assert_consistent(); assert_eq!(l.head(), 1); + l.assert_consistent(); assert_eq!(l.tail(), 2); + l.assert_consistent(); assert_eq!(l.pop().get(), 1); + l.assert_consistent(); assert_eq!(l.pop().get(), 3); + l.assert_consistent(); assert_eq!(l.pop().get(), 2); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -900,14 +900,14 @@ mod tests { l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let three = new_dlist_node(3); - l.assert_consistent(); fail_unless!(l.len() == 2); + l.assert_consistent(); assert_eq!(l.len(), 2); l.assert_consistent(); l.insert_n_after(three, one); - l.assert_consistent(); fail_unless!(l.len() == 3); - l.assert_consistent(); fail_unless!(l.head() == 1); - l.assert_consistent(); fail_unless!(l.tail() == 2); - l.assert_consistent(); fail_unless!(l.pop().get() == 1); - l.assert_consistent(); fail_unless!(l.pop().get() == 3); - l.assert_consistent(); fail_unless!(l.pop().get() == 2); + l.assert_consistent(); assert_eq!(l.len(), 3); + l.assert_consistent(); assert_eq!(l.head(), 1); + l.assert_consistent(); assert_eq!(l.tail(), 2); + l.assert_consistent(); assert_eq!(l.pop().get(), 1); + l.assert_consistent(); assert_eq!(l.pop().get(), 3); + l.assert_consistent(); assert_eq!(l.pop().get(), 2); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -915,14 +915,14 @@ mod tests { let l = DList::(); l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); - l.assert_consistent(); fail_unless!(l.len() == 2); + l.assert_consistent(); assert_eq!(l.len(), 2); l.assert_consistent(); l.insert_before(3, one); - l.assert_consistent(); fail_unless!(l.len() == 3); - l.assert_consistent(); fail_unless!(l.head() == 3); - l.assert_consistent(); fail_unless!(l.tail() == 2); - l.assert_consistent(); fail_unless!(l.pop().get() == 3); - l.assert_consistent(); fail_unless!(l.pop().get() == 1); - l.assert_consistent(); fail_unless!(l.pop().get() == 2); + l.assert_consistent(); assert_eq!(l.len(), 3); + l.assert_consistent(); assert_eq!(l.head(), 3); + l.assert_consistent(); assert_eq!(l.tail(), 2); + l.assert_consistent(); assert_eq!(l.pop().get(), 3); + l.assert_consistent(); assert_eq!(l.pop().get(), 1); + l.assert_consistent(); assert_eq!(l.pop().get(), 2); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] @@ -930,14 +930,14 @@ mod tests { let l = DList::(); l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); - l.assert_consistent(); fail_unless!(l.len() == 2); + l.assert_consistent(); assert_eq!(l.len(), 2); l.assert_consistent(); l.insert_after(3, two); - l.assert_consistent(); fail_unless!(l.len() == 3); - l.assert_consistent(); fail_unless!(l.head() == 1); - l.assert_consistent(); fail_unless!(l.tail() == 3); - l.assert_consistent(); fail_unless!(l.pop().get() == 1); - l.assert_consistent(); fail_unless!(l.pop().get() == 2); - l.assert_consistent(); fail_unless!(l.pop().get() == 3); + l.assert_consistent(); assert_eq!(l.len(), 3); + l.assert_consistent(); assert_eq!(l.head(), 1); + l.assert_consistent(); assert_eq!(l.tail(), 3); + l.assert_consistent(); assert_eq!(l.pop().get(), 1); + l.assert_consistent(); assert_eq!(l.pop().get(), 2); + l.assert_consistent(); assert_eq!(l.pop().get(), 3); l.assert_consistent(); fail_unless!(l.is_empty()); } #[test] #[should_fail] #[ignore(cfg(windows))] diff --git a/src/libcore/either.rs b/src/libcore/either.rs index e4b7bbbd99e..2410ef39332 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -191,77 +191,77 @@ fn test_either_right() { fn test_lefts() { let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let result = lefts(input); - fail_unless!((result == ~[10, 12, 14])); + assert_eq!(result, ~[10, 12, 14]); } #[test] fn test_lefts_none() { let input: ~[Either] = ~[Right(10), Right(10)]; let result = lefts(input); - fail_unless!((vec::len(result) == 0u)); + assert_eq!(vec::len(result), 0u); } #[test] fn test_lefts_empty() { let input: ~[Either] = ~[]; let result = lefts(input); - fail_unless!((vec::len(result) == 0u)); + assert_eq!(vec::len(result), 0u); } #[test] fn test_rights() { let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let result = rights(input); - fail_unless!((result == ~[11, 13])); + assert_eq!(result, ~[11, 13]); } #[test] fn test_rights_none() { let input: ~[Either] = ~[Left(10), Left(10)]; let result = rights(input); - fail_unless!((vec::len(result) == 0u)); + assert_eq!(vec::len(result), 0u); } #[test] fn test_rights_empty() { let input: ~[Either] = ~[]; let result = rights(input); - fail_unless!((vec::len(result) == 0u)); + assert_eq!(vec::len(result), 0u); } #[test] fn test_partition() { let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)]; let (lefts, rights) = partition(input); - fail_unless!((lefts[0] == 10)); - fail_unless!((lefts[1] == 12)); - fail_unless!((lefts[2] == 14)); - fail_unless!((rights[0] == 11)); - fail_unless!((rights[1] == 13)); + assert_eq!(lefts[0], 10); + assert_eq!(lefts[1], 12); + assert_eq!(lefts[2], 14); + assert_eq!(rights[0], 11); + assert_eq!(rights[1], 13); } #[test] fn test_partition_no_lefts() { let input: ~[Either] = ~[Right(10), Right(11)]; let (lefts, rights) = partition(input); - fail_unless!((vec::len(lefts) == 0u)); - fail_unless!((vec::len(rights) == 2u)); + assert_eq!(vec::len(lefts), 0u); + assert_eq!(vec::len(rights), 2u); } #[test] fn test_partition_no_rights() { let input: ~[Either] = ~[Left(10), Left(11)]; let (lefts, rights) = partition(input); - fail_unless!((vec::len(lefts) == 2u)); - fail_unless!((vec::len(rights) == 0u)); + assert_eq!(vec::len(lefts), 2u); + assert_eq!(vec::len(rights), 0u); } #[test] fn test_partition_empty() { let input: ~[Either] = ~[]; let (lefts, rights) = partition(input); - fail_unless!((vec::len(lefts) == 0u)); - fail_unless!((vec::len(rights) == 0u)); + assert_eq!(vec::len(lefts), 0u); + assert_eq!(vec::len(rights), 0u); } // diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 7503f28e848..00b6501ffce 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -1278,20 +1278,6 @@ mod tests { fail_unless!(a == b); } - // two fns copied from libsyntax/util/testing.rs. - // Should they be in their own crate? - pub pure fn check_equal_ptr (given : &T, expected: &T) { - if !((given == expected) && (expected == given )) { - fail!(fmt!("given %?, expected %?",given,expected)); - } - } - - pub pure fn check_equal (given : T, expected: T) { - if !((given == expected) && (expected == given )) { - fail!(fmt!("given %?, expected %?",given,expected)); - } - } - #[test] fn test_write_enum () { let bw = @io::BytesWriter(); @@ -1309,7 +1295,7 @@ mod tests { } } } - check_equal(str::from_bytes(bw.bytes), ~"[\"frog\",[\"Henry\",349]]"); + assert_eq!(str::from_bytes(bw.bytes), ~"[\"frog\",[\"Henry\",349]]"); } #[test] @@ -1324,7 +1310,7 @@ mod tests { } } } - check_equal(str::from_bytes(bw.bytes), ~"\"jodhpurs\""); + assert_eq!(str::from_bytes(bw.bytes), ~"\"jodhpurs\""); } #[test] @@ -1336,7 +1322,7 @@ mod tests { do encoder.emit_enum_variant (~"None",37,1242) { } } - check_equal(str::from_bytes(bw.bytes), ~"null"); + assert_eq!(str::from_bytes(bw.bytes), ~"null"); } #[test] diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 727d386f277..c2309dbf0e8 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -208,7 +208,8 @@ pub enum ExpnInfo { pub type FileName = ~str; -pub struct FileLines { +pub struct FileLines +{ file: @FileMap, lines: ~[uint] } @@ -509,17 +510,16 @@ priv impl CodeMap { #[cfg(test)] mod test { use super::*; - use util::testing::check_equal; #[test] fn t1 () { let cm = CodeMap::new(); let fm = cm.new_filemap(~"blork.rs",@~"first line.\nsecond line"); fm.next_line(BytePos(0)); - check_equal(&fm.get_line(0),&~"first line."); + assert_eq!(&fm.get_line(0),&~"first line."); // TESTING BROKEN BEHAVIOR: fm.next_line(BytePos(10)); - check_equal(&fm.get_line(1),&~"."); + assert_eq!(&fm.get_line(1),&~"."); } #[test] diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 294174dc8f9..3ab95258f03 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -1202,7 +1202,6 @@ fn mk_enum_deser_body( mod test { use std::serialize::Encodable; use std::serialize::Encoder; - use util::testing::*; // just adding the ones I want to test, for now: #[deriving_eq] @@ -1321,7 +1320,7 @@ mod test { } #[test] fn encode_enum_test () { - check_equal (to_call_log(Book(34,44)), + assert_eq!(to_call_log(Book(34,44)), ~[CallToEmitEnum (~"Written"), CallToEmitEnumVariant (~"Book",0,2), CallToEmitEnumVariantArg (0), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 447ca71dc6b..34e4d8c73e7 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -509,7 +509,6 @@ impl MapChain{ #[cfg(test)] mod test { use super::MapChain; - use util::testing::check_equal; use core::hashmap::linear::LinearMap; #[test] fn testenv () { @@ -517,23 +516,23 @@ mod test { a.insert (@~"abc",@15); let m = MapChain::new(~a); m.insert (@~"def",@16); - // FIXME: #4492 (ICE) check_equal(m.find(&@~"abc"),Some(@15)); - // .... check_equal(m.find(&@~"def"),Some(@16)); - check_equal(*(m.find(&@~"abc").get()),15); - check_equal(*(m.find(&@~"def").get()),16); + // FIXME: #4492 (ICE) assert_eq!(m.find(&@~"abc"),Some(@15)); + // .... assert_eq!(m.find(&@~"def"),Some(@16)); + assert_eq!(*(m.find(&@~"abc").get()),15); + assert_eq!(*(m.find(&@~"def").get()),16); let n = m.push_frame(); // old bindings are still present: - check_equal(*(n.find(&@~"abc").get()),15); - check_equal(*(n.find(&@~"def").get()),16); + assert_eq!(*(n.find(&@~"abc").get()),15); + assert_eq!(*(n.find(&@~"def").get()),16); n.insert (@~"def",@17); // n shows the new binding - check_equal(*(n.find(&@~"abc").get()),15); - check_equal(*(n.find(&@~"def").get()),17); + assert_eq!(*(n.find(&@~"abc").get()),15); + assert_eq!(*(n.find(&@~"def").get()),17); // ... but m still has the old ones - // FIXME: #4492: check_equal(m.find(&@~"abc"),Some(@15)); - // FIXME: #4492: check_equal(m.find(&@~"def"),Some(@16)); - check_equal(*(m.find(&@~"abc").get()),15); - check_equal(*(m.find(&@~"def").get()),16); + // FIXME: #4492: assert_eq!(m.find(&@~"abc"),Some(@15)); + // FIXME: #4492: assert_eq!(m.find(&@~"def"),Some(@16)); + assert_eq!(*(m.find(&@~"abc").get()),15); + assert_eq!(*(m.find(&@~"def").get()),16); } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ad05e2f21e6..27b35b37849 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -464,6 +464,15 @@ pub fn core_macros() -> ~str { } ) + macro_rules! assert_eq ( + ($given:expr , $expected:expr) => + ({let given_val = $given; + let expected_val = $expected; + // check both directions of equality.... + if !((given_val == expected_val) && (expected_val == given_val)) { + fail!(fmt!(\"expected: %?, given: %?\",expected_val,given_val)); + }})) + macro_rules! condition ( { $c:ident: $in:ty -> $out:ty; } => { @@ -481,6 +490,7 @@ pub fn core_macros() -> ~str { } ) + }"; } @@ -547,7 +557,6 @@ mod test { use codemap; use codemap::spanned; use parse; - use util::testing::check_equal; use core::option::{None, Some}; // make sure that fail! is present @@ -634,9 +643,9 @@ mod test { let attr2 = make_dummy_attr (@~"bar"); let escape_attr = make_dummy_attr (@~"macro_escape"); let attrs1 = ~[attr1, escape_attr, attr2]; - check_equal (contains_macro_escape (attrs1),true); + assert_eq!(contains_macro_escape (attrs1),true); let attrs2 = ~[attr1,attr2]; - check_equal (contains_macro_escape (attrs2),false); + assert_eq!(contains_macro_escape (attrs2),false); } // make a "meta_word" outer attribute with the given name diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 6cb4065935c..b92b7282274 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -779,7 +779,6 @@ pub mod test { use core::option::None; use diagnostic; use parse::token; - use util::testing::{check_equal, check_equal_ptr}; // represents a testing reader (incl. both reader and interner) struct Env { @@ -809,17 +808,17 @@ pub mod test { let tok2 = TokenAndSpan{ tok:token::IDENT(id, false), sp:span {lo:BytePos(21),hi:BytePos(23),expn_info: None}}; - check_equal (tok1,tok2); + assert_eq!(tok1,tok2); // the 'main' id is already read: - check_equal (copy string_reader.last_pos,BytePos(28)); + assert_eq!(copy string_reader.last_pos,BytePos(28)); // read another token: let tok3 = string_reader.next_token(); let tok4 = TokenAndSpan{ tok:token::IDENT(ident_interner.intern (@~"main"), false), sp:span {lo:BytePos(24),hi:BytePos(28),expn_info: None}}; - check_equal (tok3,tok4); + assert_eq!(tok3,tok4); // the lparen is already read: - check_equal (copy string_reader.last_pos,BytePos(29)) + assert_eq!(copy string_reader.last_pos,BytePos(29)) } // check that the given reader produces the desired stream @@ -828,7 +827,7 @@ pub mod test { for expected.each |expected_tok| { let TokenAndSpan {tok:actual_tok, sp: _} = env.string_reader.next_token(); - check_equal(&actual_tok,expected_tok); + assert_eq!(&actual_tok,expected_tok); } } @@ -872,21 +871,21 @@ pub mod test { let env = setup(~"'a'"); let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); - fail_unless!(tok == token::LIT_INT('a' as i64, ast::ty_char)); + assert_eq!(tok,token::LIT_INT('a' as i64, ast::ty_char)); } #[test] fn character_space() { let env = setup(~"' '"); let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); - fail_unless!(tok == token::LIT_INT(' ' as i64, ast::ty_char)); + assert_eq!(tok, token::LIT_INT(' ' as i64, ast::ty_char)); } #[test] fn character_escaped() { let env = setup(~"'\n'"); let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); - fail_unless!(tok == token::LIT_INT('\n' as i64, ast::ty_char)); + assert_eq!(tok, token::LIT_INT('\n' as i64, ast::ty_char)); } #[test] fn lifetime_name() { @@ -894,7 +893,7 @@ pub mod test { let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); let id = env.interner.intern(@~"abc"); - fail_unless!(tok == token::LIFETIME(id)); + assert_eq!(tok, token::LIFETIME(id)); } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a133befb046..a0c73668a05 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -313,7 +313,6 @@ mod test { use std; use core::io; use core::option::None; - use util::testing::*; #[test] fn to_json_str>(val: @E) -> ~str { do io::with_str_writer |writer| { @@ -327,7 +326,7 @@ mod test { @~"fn foo (x : int) { x; }", ~[], new_parse_sess(None)); - check_equal(to_json_str(@tts), + assert_eq!(to_json_str(@tts), ~"[[\"tt_tok\",[null,[\"IDENT\",[\"fn\",false]]]],\ [\"tt_tok\",[null,[\"IDENT\",[\"foo\",false]]]],\ [\"tt_delim\",[[[\"tt_tok\",[null,[\"LPAREN\",[]]]],\ @@ -347,7 +346,7 @@ mod test { @~"fn foo (x : int) { x; }", ~[],~[], new_parse_sess(None)); - check_equal(ast1,ast2); + assert_eq!(ast1,ast2); } } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 492ecdb3f4d..ed108df7db2 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -117,7 +117,7 @@ pub fn tok_str(++t: token) -> ~str { pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint, lim: uint) -> ~str { let n = vec::len(toks); - fail_unless!((n == vec::len(szs))); + fail_unless!(n == vec::len(szs)); let mut i = left; let mut L = lim; let mut s = ~"["; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 72b734ed73d..2bb053cc03a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2254,7 +2254,6 @@ pub mod test { use core::cmp::Eq; use core::option::None; use parse; - use util::testing::check_equal; fn string_check (given : &T, expected: &T) { if !(given == expected) { @@ -2275,7 +2274,7 @@ pub mod test { cf: ast::return_val }; let generics = ast_util::empty_generics(); - check_equal (&fun_to_str(&decl, abba_ident, None, &generics, mock_interner), + assert_eq!(&fun_to_str(&decl, abba_ident, None, &generics, mock_interner), &~"fn abba()"); } @@ -2295,7 +2294,7 @@ pub mod test { }); let varstr = variant_to_str(var,mock_interner); - check_equal(&varstr,&~"pub principal_skinner"); + assert_eq!(&varstr,&~"pub principal_skinner"); } } diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 01ed707b0ae..19ed6809326 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -46,7 +46,6 @@ pub mod visit; pub mod fold; pub mod util { pub mod interner; - pub mod testing; } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 47f49ebadaa..b4a85ce1617 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -77,32 +77,32 @@ pub fn i1 () { pub fn i2 () { let i : Interner<@~str> = Interner::new(); // first one is zero: - fail_unless!(i.intern (@~"dog") == 0); + assert_eq!(i.intern (@~"dog"), 0); // re-use gets the same entry: - fail_unless!(i.intern (@~"dog") == 0); + assert_eq!(i.intern (@~"dog"), 0); // different string gets a different #: - fail_unless!(i.intern (@~"cat") == 1); - fail_unless!(i.intern (@~"cat") == 1); + assert_eq!(i.intern (@~"cat"), 1); + assert_eq!(i.intern (@~"cat"), 1); // dog is still at zero - fail_unless!(i.intern (@~"dog") == 0); + assert_eq!(i.intern (@~"dog"), 0); // gensym gets 3 - fail_unless!(i.gensym (@~"zebra" ) == 2); + assert_eq!(i.gensym (@~"zebra" ), 2); // gensym of same string gets new number : - fail_unless!(i.gensym (@~"zebra" ) == 3); + assert_eq!(i.gensym (@~"zebra" ), 3); // gensym of *existing* string gets new number: - fail_unless!(i.gensym (@~"dog") == 4); - fail_unless!(i.get(0) == @~"dog"); - fail_unless!(i.get(1) == @~"cat"); - fail_unless!(i.get(2) == @~"zebra"); - fail_unless!(i.get(3) == @~"zebra"); - fail_unless!(i.get(4) == @~"dog"); + assert_eq!(i.gensym (@~"dog"), 4); + assert_eq!(i.get(0), @~"dog"); + assert_eq!(i.get(1), @~"cat"); + assert_eq!(i.get(2), @~"zebra"); + assert_eq!(i.get(3), @~"zebra"); + assert_eq!(i.get(4), @~"dog"); } #[test] pub fn i3 () { let i : Interner<@~str> = Interner::prefill([@~"Alan",@~"Bob",@~"Carol"]); - fail_unless!(i.get(0) == @~"Alan"); - fail_unless!(i.get(1) == @~"Bob"); - fail_unless!(i.get(2) == @~"Carol"); - fail_unless!(i.intern(@~"Bob") == 1); + assert_eq!(i.get(0), @~"Alan"); + assert_eq!(i.get(1), @~"Bob"); + assert_eq!(i.get(2), @~"Carol"); + assert_eq!(i.intern(@~"Bob"), 1); } diff --git a/src/libsyntax/util/testing.rs b/src/libsyntax/util/testing.rs deleted file mode 100644 index 78a175df29f..00000000000 --- a/src/libsyntax/util/testing.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// support for test cases. -use core::cmp; - -pub pure fn check_equal_ptr (given : &T, expected: &T) { - if !((given == expected) && (expected == given )) { - fail!(fmt!("given %?, expected %?",given,expected)); - } -} - -pub pure fn check_equal (given : T, expected: T) { - if !((given == expected) && (expected == given )) { - fail!(fmt!("given %?, expected %?",given,expected)); - } -} diff --git a/src/test/run-fail/assert-eq-macro-fail.rs b/src/test/run-fail/assert-eq-macro-fail.rs new file mode 100644 index 00000000000..a5f438903ce --- /dev/null +++ b/src/test/run-fail/assert-eq-macro-fail.rs @@ -0,0 +1,8 @@ +// error-pattern:expected: 15, given: 14 + +#[deriving_eq] +struct Point { x : int } + +fn main() { + assert_eq!(14,15); +} diff --git a/src/test/run-pass/assert-eq-macro-success.rs b/src/test/run-pass/assert-eq-macro-success.rs new file mode 100644 index 00000000000..c929b5c6246 --- /dev/null +++ b/src/test/run-pass/assert-eq-macro-success.rs @@ -0,0 +1,10 @@ +#[deriving_eq] +struct Point { x : int } + +fn main() { + assert_eq!(14,14); + assert_eq!(~"abc",~"abc"); + assert_eq!(~Point{x:34},~Point{x:34}); + assert_eq!(&Point{x:34},&Point{x:34}); + assert_eq!(@Point{x:34},@Point{x:34}); +}