Compare commits

...

2 commits

Author SHA1 Message Date
83c4757e36
more tests 2021-02-26 20:50:52 -05:00
2fadd81287
remove unreachable variants 2021-02-26 20:36:21 -05:00

View file

@ -214,12 +214,12 @@ impl Display for ParserError<'_> {
impl Error for ParserError<'_> {} impl Error for ParserError<'_> {}
/// A list of parsers that parsing can fail on. This is used for pretty-printing
/// errors
#[derive(PartialEq, Debug, Clone, Copy)] #[derive(PartialEq, Debug, Clone, Copy)]
enum ParserNode { enum ParserNode {
SectionHeader, SectionHeader,
ConfigName, ConfigName,
ConfigValue,
Comment,
} }
impl Display for ParserNode { impl Display for ParserNode {
@ -227,8 +227,6 @@ impl Display for ParserNode {
match self { match self {
Self::SectionHeader => write!(f, "section header"), Self::SectionHeader => write!(f, "section header"),
Self::ConfigName => write!(f, "config name"), Self::ConfigName => write!(f, "config name"),
Self::ConfigValue => write!(f, "config value"),
Self::Comment => write!(f, "comment"),
} }
} }
} }
@ -659,7 +657,6 @@ fn section<'a, 'b>(
if let Ok((new_i, _)) = section_body(i, node, &mut items) { if let Ok((new_i, _)) = section_body(i, node, &mut items) {
if old_i != new_i { if old_i != new_i {
i = new_i; i = new_i;
// items.push(Event::Key(Cow::Borrowed(key.into())));
} }
} }
@ -755,7 +752,6 @@ fn section_body<'a, 'b, 'c>(
items.push(Event::Whitespace(Cow::Borrowed(whitespace.into()))); items.push(Event::Whitespace(Cow::Borrowed(whitespace.into())));
} }
*node = ParserNode::ConfigValue;
let (i, _) = config_value(i, items)?; let (i, _) = config_value(i, items)?;
Ok((i, ())) Ok((i, ()))
} }
@ -1165,6 +1161,16 @@ mod value_no_continuation {
fn garbage_after_continution_is_err() { fn garbage_after_continution_is_err() {
assert!(value_impl(b"hello \\afwjdls", &mut vec![]).is_err()); assert!(value_impl(b"hello \\afwjdls", &mut vec![]).is_err());
} }
#[test]
fn incomplete_quote() {
assert!(value_impl(br#"hello "world"#, &mut vec![]).is_err());
}
#[test]
fn incomplete_escape() {
assert!(value_impl(br#"hello world\"#, &mut vec![]).is_err());
}
} }
#[cfg(test)] #[cfg(test)]
@ -1443,3 +1449,29 @@ mod section {
); );
} }
} }
#[cfg(test)]
mod error {
use super::*;
#[test]
fn line_no_is_one_indexed() {
assert_eq!(parse_from_str("[hello").unwrap_err().line_number(), 1);
}
#[test]
fn remaining_data_contains_bad_tokens() {
assert_eq!(
parse_from_str("[hello").unwrap_err().remaining_data(),
b"[hello"
);
}
#[test]
fn to_string_truncates_extra_values() {
assert_eq!(
parse_from_str("[1234567890").unwrap_err().to_string(),
"Got an unexpected token on line 1 while trying to parse a section header: '[123456789' ... (1 characters omitted)"
);
}
}