From 4778dc126c2bcbbb62921aeb32b8bbb1adddd1a7 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 9 Oct 2019 08:47:55 -0700 Subject: [PATCH] Add basic Display test --- tests/test_display.rs | 39 ++++++++++++++++++++++++++++++++ tests/{test.rs => test_error.rs} | 0 2 files changed, 39 insertions(+) create mode 100644 tests/test_display.rs rename tests/{test.rs => test_error.rs} (100%) diff --git a/tests/test_display.rs b/tests/test_display.rs new file mode 100644 index 0000000..8e114aa --- /dev/null +++ b/tests/test_display.rs @@ -0,0 +1,39 @@ +use std::fmt::Display; +use thiserror::Error; + +#[derive(Error, Debug)] +#[error("braced error: {}", msg)] +struct BracedError { + msg: String, +} + +#[derive(Error, Debug)] +#[error("braced error")] +struct BracedUnused { + extra: usize, +} + +#[derive(Error, Debug)] +#[error("tuple error: {}", .0)] +struct TupleError(usize); + +#[derive(Error, Debug)] +#[error("unit error")] +struct UnitError; + +fn assert(expected: &str, value: T) { + assert_eq!(expected, value.to_string()); +} + +#[test] +fn test_display() { + assert( + "braced error: T", + BracedError { + msg: "T".to_owned(), + }, + ); + assert("braced error", BracedUnused { extra: 0 }); + assert("tuple error: 0", TupleError(0)); + assert("unit error", UnitError); +} diff --git a/tests/test.rs b/tests/test_error.rs similarity index 100% rename from tests/test.rs rename to tests/test_error.rs