diff --git a/parser/src/scanner.rs b/parser/src/scanner.rs index 5610cf9..ba9a1cc 100644 --- a/parser/src/scanner.rs +++ b/parser/src/scanner.rs @@ -1709,11 +1709,11 @@ impl Scanner { self.scan_block_scalar_content_line(&mut string, &mut line_buffer); // break on EOF + self.input.lookahead(2); if self.input.next_is_z() { break; } - self.input.lookahead(2); self.read_break(&mut leading_break); // Eat the following indentation spaces and line breaks. diff --git a/parser/tests/issues.rs b/parser/tests/issues.rs index 8197a56..fdda546 100644 --- a/parser/tests/issues.rs +++ b/parser/tests/issues.rs @@ -1,9 +1,9 @@ -use saphyr_parser::{Event, Parser, ScanError, TScalarStyle}; +use saphyr_parser::{BufferedInput, Event, Parser, ScanError, TScalarStyle}; /// Run the parser through the string. /// /// # Returns -/// This functions returns the events if parsing succeeds, the error the parser returned otherwise. +/// This function returns the events if parsing succeeds, the error the parser returned otherwise. fn run_parser(input: &str) -> Result, ScanError> { let mut events = vec![]; for x in Parser::new_from_str(input) { @@ -12,6 +12,18 @@ fn run_parser(input: &str) -> Result, ScanError> { Ok(events) } +/// Run the parser through the string, using a `BufferedInput` +/// +/// # Returns +/// This function returns the events if parsing succeeds, the error the parser returned otherwise. +fn run_parser_buffered(input: &str) -> Result, ScanError> { + let mut events = vec![]; + for x in Parser::new(BufferedInput::new(input.chars())) { + events.push(x?.0); + } + Ok(events) +} + #[test] #[allow(clippy::too_many_lines)] fn test_issue1() { @@ -166,3 +178,19 @@ fn test_issue1() { ] ); } + +#[test] +fn test_pr12() { + assert_eq!( + run_parser_buffered("---\n- |\n a").unwrap(), + [ + Event::StreamStart, + Event::DocumentStart(true), + Event::SequenceStart(0, None), + Event::Scalar("a\n".to_string(), TScalarStyle::Literal, 0, None), + Event::SequenceEnd, + Event::DocumentEnd, + Event::StreamEnd, + ] + ); +} diff --git a/parser/tests/spec_test.rs b/parser/tests/spec_test.rs index 4d2876e..90c6012 100644 --- a/parser/tests/spec_test.rs +++ b/parser/tests/spec_test.rs @@ -67,3 +67,19 @@ macro_rules! assert_next { // auto generated from handler_spec_test.cpp include!("specexamples.rs.inc"); include!("spec_test.rs.inc"); + +mod with_buffered_input { + use super::{Parser, TestEvent, YamlChecker}; + + fn str_to_test_events(docs: &str) -> Vec { + use saphyr_parser::BufferedInput; + + let mut p = YamlChecker { evs: Vec::new() }; + let input = BufferedInput::new(docs.chars()); + let mut parser = Parser::new(input); + parser.load(&mut p, true).unwrap(); + p.evs + } + include!("specexamples.rs.inc"); + include!("spec_test.rs.inc"); +}