diff options
Diffstat (limited to 'tests/common/errorpanic.rs')
-rw-r--r-- | tests/common/errorpanic.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/common/errorpanic.rs b/tests/common/errorpanic.rs index faef603..6b4254b 100644 --- a/tests/common/errorpanic.rs +++ b/tests/common/errorpanic.rs @@ -3,11 +3,12 @@ // Licensed under the MIT license. // Documentation and comments licensed under CC BY-SA 4.0. -use ::iosonism::strcursor::ReadError; +use ::iosonism::error::RangeError; +use ::iosonism::error::ReadError; use ::iosonism::strcursor::StringReader; /// An implementation of various Iosonism errors that just panics. -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum ErrorPanic { // uninhabitable! } @@ -22,6 +23,22 @@ impl ::std::fmt::Display for ErrorPanic { impl ::std::error::Error for ErrorPanic { } +impl<'a, C, T, R> RangeError<'a, C, T, R> for ErrorPanic +where C: StringReader<'a>, T: ::std::fmt::Display, R: ::std::fmt::Debug { + fn value_not_in_range(context: &C, from: &T, range: &R) -> Self { + if !context.get_remaining().is_empty() { + panic!( + "value ({}) not in range: {:?} at ...{}", + from, + range, + context.get_remaining(), + ); + } else { + panic!("value ({}) not in range: {:?}", from, range); + } + } +} + impl<'a, C: StringReader<'a>> ReadError<'a, C> for ErrorPanic { fn invalid_integer(context: &C, from: &str) -> Self { if !context.get_remaining().is_empty() { |