Skip to content

Commit

Permalink
Move regression tests for tafia#94 and tafia#299 to issues.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Sep 29, 2023
1 parent c639714 commit 78475da
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 50 deletions.
51 changes: 51 additions & 0 deletions tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ use quick_xml::name::QName;
use quick_xml::reader::Reader;
use quick_xml::Error;

/// Regression test for https://github.com/tafia/quick-xml/issues/94
#[test]
fn issue94() {
let data = br#"<Run>
<!B>
</Run>"#;
let mut reader = Reader::from_reader(&data[..]);
reader.trim_text(true);
loop {
match reader.read_event() {
Ok(Event::Eof) | Err(..) => break,
_ => (),
}
}
}

/// Regression test for https://github.com/tafia/quick-xml/issues/115
#[test]
fn issue115() {
Expand All @@ -22,6 +38,41 @@ fn issue115() {
}
}

/// Regression test for https://github.com/tafia/quick-xml/issues/299
#[test]
fn issue299() -> Result<(), Error> {
let xml = r#"
<?xml version="1.0" encoding="utf8"?>
<MICEX_DOC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SECURITY SecurityId="PLZL" ISIN="RU000A0JNAA8" SecShortName="Short Name" PriceType="CASH">
<RECORDS RecNo="1" TradeNo="1111" TradeDate="2021-07-08" TradeTime="15:00:00" BuySell="S" SettleCode="Y1Dt" Decimals="3" Price="13057.034" Quantity="766" Value="10001688.29" AccInt="0" Amount="10001688.29" Balance="766" TrdAccId="X0011" ClientDetails="2222" CPFirmId="3333" CPFirmShortName="Firm Short Name" Price2="13057.034" RepoPart="2" ReportTime="16:53:27" SettleTime="17:47:06" ClientCode="4444" DueDate="2021-07-09" EarlySettleStatus="N" RepoRate="5.45" RateType="FIX"/>
</SECURITY>
</MICEX_DOC>
"#;
let mut reader = Reader::from_str(xml);
loop {
match reader.read_event()? {
Event::Start(e) | Event::Empty(e) => {
let attr_count = match e.name().as_ref() {
b"MICEX_DOC" => 1,
b"SECURITY" => 4,
b"RECORDS" => 26,
_ => unreachable!(),
};
assert_eq!(
attr_count,
e.attributes().filter(Result::is_ok).count(),
"mismatch att count on '{:?}'",
reader.decoder().decode(e.name().as_ref())
);
}
Event::Eof => break,
_ => (),
}
}
Ok(())
}

/// Regression test for https://github.com/tafia/quick-xml/issues/360
#[test]
fn issue360() {
Expand Down
50 changes: 0 additions & 50 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use quick_xml::events::attributes::Attribute;
use quick_xml::events::Event::*;
use quick_xml::name::QName;
use quick_xml::reader::Reader;
use quick_xml::Error;
use std::borrow::Cow;

use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -89,21 +88,6 @@ fn test_comment_starting_with_gt() {
}
}

#[test]
fn test_issue94() {
let data = br#"<Run>
<!B>
</Run>"#;
let mut reader = Reader::from_reader(&data[..]);
reader.trim_text(true);
loop {
match reader.read_event() {
Ok(Eof) | Err(..) => break,
_ => (),
}
}
}

#[test]
fn test_no_trim() {
let mut reader = Reader::from_str(" <tag> text </tag> ");
Expand Down Expand Up @@ -151,37 +135,3 @@ fn test_clone_reader() {
assert!(matches!(cloned.read_event().unwrap(), Text(_)));
assert!(matches!(cloned.read_event().unwrap(), End(_)));
}

#[test]
fn test_issue299() -> Result<(), Error> {
let xml = r#"
<?xml version="1.0" encoding="utf8"?>
<MICEX_DOC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SECURITY SecurityId="PLZL" ISIN="RU000A0JNAA8" SecShortName="Short Name" PriceType="CASH">
<RECORDS RecNo="1" TradeNo="1111" TradeDate="2021-07-08" TradeTime="15:00:00" BuySell="S" SettleCode="Y1Dt" Decimals="3" Price="13057.034" Quantity="766" Value="10001688.29" AccInt="0" Amount="10001688.29" Balance="766" TrdAccId="X0011" ClientDetails="2222" CPFirmId="3333" CPFirmShortName="Firm Short Name" Price2="13057.034" RepoPart="2" ReportTime="16:53:27" SettleTime="17:47:06" ClientCode="4444" DueDate="2021-07-09" EarlySettleStatus="N" RepoRate="5.45" RateType="FIX"/>
</SECURITY>
</MICEX_DOC>
"#;
let mut reader = Reader::from_str(xml);
loop {
match reader.read_event()? {
Start(e) | Empty(e) => {
let attr_count = match e.name().as_ref() {
b"MICEX_DOC" => 1,
b"SECURITY" => 4,
b"RECORDS" => 26,
_ => unreachable!(),
};
assert_eq!(
attr_count,
e.attributes().filter(Result::is_ok).count(),
"mismatch att count on '{:?}'",
reader.decoder().decode(e.name().as_ref())
);
}
Eof => break,
_ => (),
}
}
Ok(())
}

0 comments on commit 78475da

Please sign in to comment.