Skip to content

Commit

Permalink
Add regression tests for #774
Browse files Browse the repository at this point in the history
failures (2):
  async-tokio (1):
    issue774
  issues (1):
    issue774
  • Loading branch information
Mingun authored and dralley committed Jun 29, 2024
1 parent 9a72c7b commit 022441f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
29 changes: 28 additions & 1 deletion tests/async-tokio.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::iter;

use pretty_assertions::assert_eq;
use quick_xml::events::{BytesStart, Event::*};
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event::*};
use quick_xml::name::QName;
use quick_xml::reader::Reader;
use tokio::io::BufReader;

// Import `small_buffers_tests!`
#[macro_use]
Expand Down Expand Up @@ -148,3 +149,29 @@ async fn issue751() {
}
}
}

/// Regression test for https://github.com/tafia/quick-xml/issues/774
///
/// Capacity of the buffer selected in that way, that "text" will be read into
/// one internal buffer of `BufReader` in one `fill_buf()` call and `<` of the
/// closing tag in the next call.
#[tokio::test]
async fn issue774() {
let xml = BufReader::with_capacity(9, b"<tag>text</tag>" as &[u8]);
// ^0 ^9
let mut reader = Reader::from_reader(xml);
let mut buf = Vec::new();

assert_eq!(
reader.read_event_into_async(&mut buf).await.unwrap(),
Start(BytesStart::new("tag"))
);
assert_eq!(
reader.read_event_into_async(&mut buf).await.unwrap(),
Text(BytesText::new("text"))
);
assert_eq!(
reader.read_event_into_async(&mut buf).await.unwrap(),
End(BytesEnd::new("tag"))
);
}
29 changes: 28 additions & 1 deletion tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
//!
//! Name each module / test as `issue<GH number>` and keep sorted by issue number
use std::io::BufReader;
use std::iter;
use std::sync::mpsc;

use quick_xml::errors::{Error, IllFormedError, SyntaxError};
use quick_xml::events::{BytesDecl, BytesStart, BytesText, Event};
use quick_xml::events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event};
use quick_xml::name::QName;
use quick_xml::reader::Reader;

Expand Down Expand Up @@ -337,3 +338,29 @@ fn issue751() {
}
}
}

/// Regression test for https://github.com/tafia/quick-xml/issues/774
///
/// Capacity of the buffer selected in that way, that "text" will be read into
/// one internal buffer of `BufReader` in one `fill_buf()` call and `<` of the
/// closing tag in the next call.
#[test]
fn issue774() {
let xml = BufReader::with_capacity(9, b"<tag>text</tag>" as &[u8]);
// ^0 ^9
let mut reader = Reader::from_reader(xml);
let mut buf = Vec::new();

assert_eq!(
reader.read_event_into(&mut buf).unwrap(),
Event::Start(BytesStart::new("tag"))
);
assert_eq!(
reader.read_event_into(&mut buf).unwrap(),
Event::Text(BytesText::new("text"))
);
assert_eq!(
reader.read_event_into(&mut buf).unwrap(),
Event::End(BytesEnd::new("tag"))
);
}

0 comments on commit 022441f

Please sign in to comment.