Skip to content
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

chore: make macro tests external #78

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
225 changes: 0 additions & 225 deletions pretty_assertions/src/lib.rs
Expand Up @@ -238,228 +238,3 @@ macro_rules! assert_ne {
}
});
}

#[cfg(test)]
#[allow(clippy::eq_op)]
#[no_implicit_prelude]
mod test {
mod assert_eq {
use ::std::string::{String, ToString};

#[test]
fn passes() {
let a = "some value";
crate::assert_eq!(a, a);
}

#[test]
fn passes_unsized() {
let a: &[u8] = b"e";
crate::assert_eq!(*a, *a);
}

#[test]
fn passes_comparable_types() {
let s0: &'static str = "foo";
let s1: String = "foo".to_string();
crate::assert_eq!(s0, s1);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`

Diff < left / right > :
<666
>999

"#)]
fn fails() {
crate::assert_eq!(666, 999);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`

Diff < left / right > :
<666
>999

"#)]
fn fails_trailing_comma() {
crate::assert_eq!(666, 999,);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`

Diff < left / right > :
[
101,
> 101,
]

"#)]
fn fails_unsized() {
let a: &[u8] = b"e";
let b: &[u8] = b"ee";
crate::assert_eq!(*a, *b);
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left == right)`: custom panic message

Diff < left / right > :
<666
>999

"#
)]
fn fails_custom() {
crate::assert_eq!(666, 999, "custom panic message");
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left == right)`: custom panic message

Diff < left / right > :
<666
>999

"#
)]
fn fails_custom_trailing_comma() {
crate::assert_eq!(666, 999, "custom panic message",);
}
}

mod assert_ne {
use ::std::string::{String, ToString};

#[test]
fn passes() {
let a = "a";
let b = "b";
crate::assert_ne!(a, b);
}

#[test]
fn passes_unsized() {
let a: &[u8] = b"e";
let b: &[u8] = b"ee";
crate::assert_ne!(*a, *b);
}

#[test]
fn passes_comparable_types() {
let s0: &'static str = "foo";
let s1: String = "bar".to_string();
crate::assert_ne!(s0, s1);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`

Both sides:
666
"#)]
fn fails() {
crate::assert_ne!(666, 666);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`

Both sides:
666
"#)]
fn fails_trailing_comma() {
crate::assert_ne!(666, 666,);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`

Both sides:
[
101,
]

"#)]
fn fails_unsized() {
let a: &[u8] = b"e";
crate::assert_ne!(*a, *a);
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message

Both sides:
666
"#
)]
fn fails_custom() {
crate::assert_ne!(666, 666, "custom panic message");
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message

Both sides:
666
"#
)]
fn fails_custom_trailing_comma() {
crate::assert_ne!(666, 666, "custom panic message",);
}

// If the values are equal but their debug outputs are not
// show a specific warning

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`

Diff < left / right > :
<-0.0
>0.0

Note: According to the `PartialEq` implementation, both of the values are partially equivalent, even if the `Debug` outputs differ.

"#)]
fn assert_ne_partial() {
// Workaround for https://github.com/rust-lang/rust/issues/47619
// can be removed, when we require rust 1.25 or higher
struct Foo(f32);

use ::std::fmt;
impl fmt::Debug for Foo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
::std::write!(f, "{:.1?}", self.0)
}
}

impl ::std::cmp::PartialEq for Foo {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}

crate::assert_ne!(Foo(-0.0), Foo(0.0));
}

// Regression tests

#[test]
#[should_panic]
fn assert_ne_non_empty_return() {
fn not_zero(x: u32) -> u32 {
crate::assert_ne!(x, 0);
x
}
not_zero(0);
}
}
}