Lines
99.23 %
Functions
100 %
Branches
use super::*;
fn drain(decoder: &mut FrameDecoder) -> Vec<String> {
let mut frames = Vec::new();
while let Some(result) = decoder.next_frame() {
match result {
Ok(f) => frames.push(f),
Err(e) => panic!("unexpected frame error: {e}"),
}
frames
#[test]
fn returns_none_when_buffer_empty() {
let mut d = FrameDecoder::new();
assert!(d.next_frame().is_none());
fn returns_none_when_buffer_only_whitespace() {
d.feed(b" \n\t ").unwrap();
fn yields_atom_frame() {
d.feed(b"42 ").unwrap();
let frames = drain(&mut d);
assert_eq!(frames, vec!["42".to_string()]);
fn yields_simple_list_frame() {
d.feed(b"(foo bar)").unwrap();
assert_eq!(frames, vec!["(foo bar)".to_string()]);
fn yields_multiple_frames_streamed() {
d.feed(b"(a)\n(b)\n(c)\n").unwrap();
assert_eq!(
frames,
vec!["(a)".to_string(), "(b)".to_string(), "(c)".to_string()]
);
fn defers_when_form_incomplete() {
d.feed(b"(foo ").unwrap();
d.feed(b"bar)").unwrap();
fn handles_nested_lists() {
d.feed(b"(a (b (c d) e) f)").unwrap();
assert_eq!(frames, vec!["(a (b (c d) e) f)".to_string()]);
fn parens_inside_string_do_not_affect_depth() {
d.feed(b"(foo \"a)b(c\" bar)").unwrap();
assert_eq!(frames, vec!["(foo \"a)b(c\" bar)".to_string()]);
fn handles_escaped_quote_in_string() {
d.feed(b"(say \"he\\\"llo\")").unwrap();
assert_eq!(frames, vec!["(say \"he\\\"llo\")".to_string()]);
fn handles_triple_quoted_string_across_lines() {
d.feed(b"(doc \"\"\"line one\n).\nline two\"\"\")").unwrap();
vec!["(doc \"\"\"line one\n).\nline two\"\"\")".to_string()]
fn handles_base64_literal_with_parens_inside() {
d.feed(b"(blob #\"abc())def\")").unwrap();
assert_eq!(frames, vec!["(blob #\"abc())def\")".to_string()]);
fn handles_byte_vector_literal_with_inner_parens_handled_by_balance() {
d.feed(b"(blob #u8(1 2 3))").unwrap();
assert_eq!(frames, vec!["(blob #u8(1 2 3))".to_string()]);
fn handles_quote_prefix() {
d.feed(b"'(a b)").unwrap();
assert_eq!(frames, vec!["'(a b)".to_string()]);
fn handles_quasiquote_with_unquote_inside() {
d.feed(b"`(a ,b ,@c)").unwrap();
assert_eq!(frames, vec!["`(a ,b ,@c)".to_string()]);
fn skips_top_level_comments_between_frames() {
d.feed(b"; comment\n(foo)\n; another\n(bar)\n").unwrap();
assert_eq!(frames, vec!["(foo)".to_string(), "(bar)".to_string()]);
fn comment_inside_list_does_not_split_frame() {
d.feed(b"(foo ; comment with )\n bar)").unwrap();
assert_eq!(frames, vec!["(foo ; comment with )\n bar)".to_string()]);
fn invalid_utf8_returns_error() {
let err = d.feed(&[0xFF, 0xFE, 0xFD]).unwrap_err();
assert_eq!(err, FrameError::InvalidUtf8);
fn standalone_string_is_a_frame() {
d.feed(b"\"hello\"").unwrap();
assert_eq!(frames, vec!["\"hello\"".to_string()]);
fn standalone_byte_vector_is_a_frame() {
d.feed(b"#u8(1 2 3)").unwrap();
assert_eq!(frames, vec!["#u8(1 2 3)".to_string()]);
fn standalone_base64_is_a_frame() {
d.feed(b"#\"abcd\"").unwrap();
assert_eq!(frames, vec!["#\"abcd\"".to_string()]);