lib/scanner: add unit tests for flow_collection_* methods

though only for the naive cases, e.g '{}' and '[]'.
More to come...
This commit is contained in:
Paul Stemmet 2021-07-25 21:10:25 +00:00 committed by Paul Stemmet
parent a84f64e2b7
commit e24fe38a7e
1 changed files with 36 additions and 0 deletions

View File

@ -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()
{