From e24fe38a7ef56371f7abe2cc7f579d3a96686260 Mon Sep 17 00:00:00 2001 From: Bazaah Date: Sun, 25 Jul 2021 21:10:25 +0000 Subject: [PATCH] lib/scanner: add unit tests for flow_collection_* methods though only for the naive cases, e.g '{}' and '[]'. More to come... --- src/scanner/mod.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/scanner/mod.rs b/src/scanner/mod.rs index 8e87c63..be776a4 100644 --- a/src/scanner/mod.rs +++ b/src/scanner/mod.rs @@ -878,6 +878,42 @@ mod tests assert_eq!(s.scan.stats, stats_of(data)); } + #[test] + fn flow_collection_mapping_indicators() + { + let data = "{}"; + let mut s = ScanIter::new(data); + + // Note that the doubled braces here are because of Rust's + // fmtstr escaping rules. + tokens!(s => + | Token::StreamStart(StreamEncoding::UTF8) => "expected start of stream", + | Token::FlowMappingStart => "expected a flow mapping start '{{'", + | Token::FlowMappingEnd => "expected a flow mapping end '}}'", + | Token::StreamEnd => "expected end of stream", + @ None => "expected stream to be finished" + ); + + assert_eq!(s.scan.stats, stats_of(data)); + } + + #[test] + fn flow_collection_sequence_indicators() + { + let data = "[]"; + let mut s = ScanIter::new(data); + + tokens!(s => + | Token::StreamStart(StreamEncoding::UTF8) => "expected start of stream", + | Token::FlowSequenceStart => "expected a flow sequence start '['", + | Token::FlowSequenceEnd => "expected a flow sequence end ']'", + | Token::StreamEnd => "expected end of stream", + @ None => "expected stream to be finished" + ); + + assert_eq!(s.scan.stats, stats_of(data)); + } + #[test] fn chomp_comments() {