Compare commits
No commits in common. "83c4757e3679c094bb5312aee59b61026640f2c7" and "17ba2929346b4b4c3809a9408ef5e6131cc4596e" have entirely different histories.
83c4757e36
...
17ba292934
1 changed files with 6 additions and 38 deletions
|
@ -214,12 +214,12 @@ impl Display 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)]
|
||||
enum ParserNode {
|
||||
SectionHeader,
|
||||
ConfigName,
|
||||
ConfigValue,
|
||||
Comment,
|
||||
}
|
||||
|
||||
impl Display for ParserNode {
|
||||
|
@ -227,6 +227,8 @@ impl Display for ParserNode {
|
|||
match self {
|
||||
Self::SectionHeader => write!(f, "section header"),
|
||||
Self::ConfigName => write!(f, "config name"),
|
||||
Self::ConfigValue => write!(f, "config value"),
|
||||
Self::Comment => write!(f, "comment"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -657,6 +659,7 @@ fn section<'a, 'b>(
|
|||
if let Ok((new_i, _)) = section_body(i, node, &mut items) {
|
||||
if old_i != new_i {
|
||||
i = new_i;
|
||||
// items.push(Event::Key(Cow::Borrowed(key.into())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,6 +755,7 @@ fn section_body<'a, 'b, 'c>(
|
|||
items.push(Event::Whitespace(Cow::Borrowed(whitespace.into())));
|
||||
}
|
||||
|
||||
*node = ParserNode::ConfigValue;
|
||||
let (i, _) = config_value(i, items)?;
|
||||
Ok((i, ()))
|
||||
}
|
||||
|
@ -1161,16 +1165,6 @@ mod value_no_continuation {
|
|||
fn garbage_after_continution_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)]
|
||||
|
@ -1449,29 +1443,3 @@ 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)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue