summary refs log tree commit diff stats
path: root/tests/common/errorpanic.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2021-12-04 17:46:00 -0300
committerSoniEx2 <endermoneymod@gmail.com>2021-12-04 17:46:00 -0300
commit36395c7437218b86c832cc041f7a58f325a007bb (patch)
tree83c3e2a5c1fc265583c4b8e560b4ba732742f70d /tests/common/errorpanic.rs
parent6eee8e415fb2361a91cbc1151f37003bb2cd449b (diff)
Add integer and float arguments
Diffstat (limited to 'tests/common/errorpanic.rs')
-rw-r--r--tests/common/errorpanic.rs21
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() {