-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from CryZe/doc-comment-display
Implement Doc Comments as Default Display Implementations
- Loading branch information
Showing
2 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
extern crate snafu; | ||
|
||
use snafu::Snafu; | ||
|
||
#[derive(Debug, Snafu)] | ||
enum Error { | ||
/// No user available. | ||
/// You may need to specify one. | ||
/// | ||
/// Here is a more detailed description. | ||
MissingUser, | ||
/// This is just a doc comment. | ||
#[snafu(display("This is {}", stronger))] | ||
Stronger { stronger: &'static str }, | ||
} | ||
|
||
#[test] | ||
fn implements_error() { | ||
fn check<T: std::error::Error>() {} | ||
check::<Error>(); | ||
} | ||
|
||
#[test] | ||
fn uses_doc_comment() { | ||
assert_eq!( | ||
Error::MissingUser.to_string(), | ||
"No user available. You may need to specify one.", | ||
); | ||
} | ||
|
||
#[test] | ||
fn display_is_stronger_than_doc_comment() { | ||
assert_eq!( | ||
Error::Stronger { | ||
stronger: "always stronger!" | ||
} | ||
.to_string(), | ||
"This is always stronger!", | ||
); | ||
} |