rustc/vendor/pretty_assertions/tests/assert_eq.rs
2018-12-16 10:13:16 -08:00

196 lines
4.9 KiB
Rust
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#[macro_use]
extern crate pretty_assertions;
extern crate difference;
#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
Diff < left / right > :
Some(
Foo {
< lorem: "Hello World!",
> lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok(
< "hey"
> "hey ho!"
)
}
)
"#)]
fn assert_eq() {
#[derive(Debug, PartialEq)]
struct Foo {
lorem: &'static str,
ipsum: u32,
dolor: Result<String, String>,
}
let x = Some(Foo {
lorem: "Hello World!",
ipsum: 42,
dolor: Ok("hey".to_string()),
});
let y = Some(Foo {
lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok("hey ho!".to_string()),
});
assert_eq!(x, y);
}
#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`: custom panic message
Diff < left / right > :
Some(
Foo {
< lorem: "Hello World!",
> lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok(
< "hey"
> "hey ho!"
)
}
)
"#)]
fn assert_eq_custom() {
#[derive(Debug, PartialEq)]
struct Foo {
lorem: &'static str,
ipsum: u32,
dolor: Result<String, String>,
}
let x = Some(Foo {
lorem: "Hello World!",
ipsum: 42,
dolor: Ok("hey".to_string()),
});
let y = Some(Foo {
lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok("hey ho!".to_string()),
});
assert_eq!(x, y, "custom panic message");
}
#[test]
fn assert_eq_with_comparable_types() {
let s0: &'static str = "foo";
let s1: String = "foo".to_string();
assert_eq!(s0, s1);
}
#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
Diff < left / right > :
[
< 0,
< 0,
< 0,
< 128,
< 10,
< 191,
< 5,
> 84,
> 248,
> 45,
64
]
"#)]
fn issue12() {
let left = vec![0, 0, 0, 128, 10, 191, 5, 64];
let right = vec![84, 248, 45, 64];
assert_eq!(left, right);
}
#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
Diff < left / right > :
Some(
Foo {
< lorem: "Hello World!",
> lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok(
< "hey"
> "hey ho!"
)
}
)
"#)]
fn assert_eq_trailing_comma() {
#[derive(Debug, PartialEq)]
struct Foo {
lorem: &'static str,
ipsum: u32,
dolor: Result<String, String>,
}
let x = Some(Foo {
lorem: "Hello World!",
ipsum: 42,
dolor: Ok("hey".to_string()),
});
let y = Some(Foo {
lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok("hey ho!".to_string()),
});
assert_eq!(x, y,);
}
#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`: custom panic message
Diff < left / right > :
Some(
Foo {
< lorem: "Hello World!",
> lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok(
< "hey"
> "hey ho!"
)
}
)
"#)]
fn assert_eq_custom_trailing_comma() {
#[derive(Debug, PartialEq)]
struct Foo {
lorem: &'static str,
ipsum: u32,
dolor: Result<String, String>,
}
let x = Some(Foo {
lorem: "Hello World!",
ipsum: 42,
dolor: Ok("hey".to_string()),
});
let y = Some(Foo {
lorem: "Hello Wrold!",
ipsum: 42,
dolor: Ok("hey ho!".to_string()),
});
assert_eq!(x, y, "custom panic message",);
}