Skip to content

Commit 022441f

Browse files
Mingundralley
authored andcommitted
Add regression tests for #774
failures (2): async-tokio (1): issue774 issues (1): issue774
1 parent 9a72c7b commit 022441f

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

tests/async-tokio.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::iter;
22

33
use pretty_assertions::assert_eq;
4-
use quick_xml::events::{BytesStart, Event::*};
4+
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event::*};
55
use quick_xml::name::QName;
66
use quick_xml::reader::Reader;
7+
use tokio::io::BufReader;
78

89
// Import `small_buffers_tests!`
910
#[macro_use]
@@ -148,3 +149,29 @@ async fn issue751() {
148149
}
149150
}
150151
}
152+
153+
/// Regression test for https://github.com/tafia/quick-xml/issues/774
154+
///
155+
/// Capacity of the buffer selected in that way, that "text" will be read into
156+
/// one internal buffer of `BufReader` in one `fill_buf()` call and `<` of the
157+
/// closing tag in the next call.
158+
#[tokio::test]
159+
async fn issue774() {
160+
let xml = BufReader::with_capacity(9, b"<tag>text</tag>" as &[u8]);
161+
// ^0 ^9
162+
let mut reader = Reader::from_reader(xml);
163+
let mut buf = Vec::new();
164+
165+
assert_eq!(
166+
reader.read_event_into_async(&mut buf).await.unwrap(),
167+
Start(BytesStart::new("tag"))
168+
);
169+
assert_eq!(
170+
reader.read_event_into_async(&mut buf).await.unwrap(),
171+
Text(BytesText::new("text"))
172+
);
173+
assert_eq!(
174+
reader.read_event_into_async(&mut buf).await.unwrap(),
175+
End(BytesEnd::new("tag"))
176+
);
177+
}

tests/issues.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
//!
33
//! Name each module / test as `issue<GH number>` and keep sorted by issue number
44
5+
use std::io::BufReader;
56
use std::iter;
67
use std::sync::mpsc;
78

89
use quick_xml::errors::{Error, IllFormedError, SyntaxError};
9-
use quick_xml::events::{BytesDecl, BytesStart, BytesText, Event};
10+
use quick_xml::events::{BytesDecl, BytesEnd, BytesStart, BytesText, Event};
1011
use quick_xml::name::QName;
1112
use quick_xml::reader::Reader;
1213

@@ -337,3 +338,29 @@ fn issue751() {
337338
}
338339
}
339340
}
341+
342+
/// Regression test for https://github.com/tafia/quick-xml/issues/774
343+
///
344+
/// Capacity of the buffer selected in that way, that "text" will be read into
345+
/// one internal buffer of `BufReader` in one `fill_buf()` call and `<` of the
346+
/// closing tag in the next call.
347+
#[test]
348+
fn issue774() {
349+
let xml = BufReader::with_capacity(9, b"<tag>text</tag>" as &[u8]);
350+
// ^0 ^9
351+
let mut reader = Reader::from_reader(xml);
352+
let mut buf = Vec::new();
353+
354+
assert_eq!(
355+
reader.read_event_into(&mut buf).unwrap(),
356+
Event::Start(BytesStart::new("tag"))
357+
);
358+
assert_eq!(
359+
reader.read_event_into(&mut buf).unwrap(),
360+
Event::Text(BytesText::new("text"))
361+
);
362+
assert_eq!(
363+
reader.read_event_into(&mut buf).unwrap(),
364+
Event::End(BytesEnd::new("tag"))
365+
);
366+
}

0 commit comments

Comments
 (0)