mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Merge branch 'post-05' into post-06
This commit is contained in:
@@ -46,26 +46,28 @@ fn check_location(info: &PanicInfo) {
|
|||||||
|
|
||||||
fn check_message(info: &PanicInfo) {
|
fn check_message(info: &PanicInfo) {
|
||||||
let message = info.message().unwrap_or_else(|| fail("no message"));
|
let message = info.message().unwrap_or_else(|| fail("no message"));
|
||||||
let mut compare_message = CompareMessage { equals: false };
|
let mut compare_message = CompareMessage { expected: MESSAGE };
|
||||||
write!(&mut compare_message, "{}", message).unwrap_or_else(|_| fail("write failed"));
|
write!(&mut compare_message, "{}", message).unwrap_or_else(|_| fail("write failed"));
|
||||||
if !compare_message.equals {
|
if compare_message.expected.len() != 0 {
|
||||||
fail("message not equal to expected message");
|
fail("message shorter than expected message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compares a `fmt::Arguments` instance with the `MESSAGE` string
|
/// Compares a `fmt::Arguments` instance with the `MESSAGE` string
|
||||||
///
|
///
|
||||||
/// To use this type, write the `fmt::Arguments` instance to it using the
|
/// To use this type, write the `fmt::Arguments` instance to it using the
|
||||||
/// `write` macro. If a message component matches `MESSAGE`, the equals
|
/// `write` macro. If the message component matches `MESSAGE`, the `expected`
|
||||||
/// field is set to true.
|
/// field is the empty string.
|
||||||
struct CompareMessage {
|
struct CompareMessage {
|
||||||
equals: bool,
|
expected: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Write for CompareMessage {
|
impl fmt::Write for CompareMessage {
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||||
if s == MESSAGE {
|
if self.expected.starts_with(s) {
|
||||||
self.equals = true;
|
self.expected = &self.expected[s.len()..];
|
||||||
|
} else {
|
||||||
|
fail("message not equal to expected message");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user