1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::fmt;
use nom::{combinator::map, IResult};
use crate::{util, Parse};
#[derive(Clone, Debug, PartialEq)]
pub struct Information(pub String);
impl fmt::Display for Information {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "i={}\r", self.0)
}
}
impl Parse for Information {
fn parse(input: &str) -> IResult<&str, Self> {
map(util::parse_nonempty_line("i="), |value| {
Self(value.to_owned())
})(input)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_util::assert_parse_display;
#[test]
fn test_valid() {
assert_parse_display(
"i=test info\nrest\n",
"rest\n",
&Information("test info".to_owned()),
"i=test info\r\n",
);
}
}