|
| 1 | +use std::fmt; |
| 2 | + |
1 | 3 | use crate::{
|
2 | 4 | event::ExpectedEvent,
|
3 | 5 | field::{ExpectedField, ExpectedFields, ExpectedValue},
|
@@ -41,3 +43,51 @@ pub fn span() -> ExpectedSpan {
|
41 | 43 | ..Default::default()
|
42 | 44 | }
|
43 | 45 | }
|
| 46 | + |
| 47 | +impl Expect { |
| 48 | + pub(crate) fn bad(&self, name: impl AsRef<str>, what: fmt::Arguments<'_>) { |
| 49 | + let name = name.as_ref(); |
| 50 | + match self { |
| 51 | + Expect::Event(e) => panic!( |
| 52 | + "\n[{}] expected event {}\n[{}] but instead {}", |
| 53 | + name, e, name, what, |
| 54 | + ), |
| 55 | + Expect::FollowsFrom { consequence, cause } => panic!( |
| 56 | + "\n[{}] expected consequence {} to follow cause {} but instead {}", |
| 57 | + name, consequence, cause, what, |
| 58 | + ), |
| 59 | + Expect::Enter(e) => panic!( |
| 60 | + "\n[{}] expected to enter {}\n[{}] but instead {}", |
| 61 | + name, e, name, what, |
| 62 | + ), |
| 63 | + Expect::Exit(e) => panic!( |
| 64 | + "\n[{}] expected to exit {}\n[{}] but instead {}", |
| 65 | + name, e, name, what, |
| 66 | + ), |
| 67 | + Expect::CloneSpan(e) => { |
| 68 | + panic!( |
| 69 | + "\n[{}] expected to clone {}\n[{}] but instead {}", |
| 70 | + name, e, name, what, |
| 71 | + ) |
| 72 | + } |
| 73 | + Expect::DropSpan(e) => { |
| 74 | + panic!( |
| 75 | + "\n[{}] expected to drop {}\n[{}] but instead {}", |
| 76 | + name, e, name, what, |
| 77 | + ) |
| 78 | + } |
| 79 | + Expect::Visit(e, fields) => panic!( |
| 80 | + "\n[{}] expected {} to record {}\n[{}] but instead {}", |
| 81 | + name, e, fields, name, what, |
| 82 | + ), |
| 83 | + Expect::NewSpan(e) => panic!( |
| 84 | + "\n[{}] expected {}\n[{}] but instead {}", |
| 85 | + name, e, name, what |
| 86 | + ), |
| 87 | + Expect::Nothing => panic!( |
| 88 | + "\n[{}] expected nothing else to happen\n[{}] but {} instead", |
| 89 | + name, name, what, |
| 90 | + ), |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments