Skip to content

Commit

Permalink
Replace test bom_removed_from_initial_text with more formal test in t…
Browse files Browse the repository at this point in the history
…ests/encodings.rs

Also add more checks to test for buffered reader related to BOM
  • Loading branch information
Mingun committed Jun 20, 2024
1 parent e1e3489 commit 625c74e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
15 changes: 12 additions & 3 deletions src/reader/buffered_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@ mod test {
let mut buf = Vec::new();

assert_eq!(reader.decoder().encoding(), UTF_8);
reader.read_event_into(&mut buf).unwrap();
assert!(matches!(
reader.read_event_into(&mut buf).unwrap(),
Event::Decl(_)
));
assert_eq!(reader.decoder().encoding(), WINDOWS_1251);

assert_eq!(reader.read_event_into(&mut buf).unwrap(), Event::Eof);
Expand All @@ -497,10 +500,16 @@ mod test {
let mut buf = Vec::new();

assert_eq!(reader.decoder().encoding(), UTF_8);
reader.read_event_into(&mut buf).unwrap();
assert!(matches!(
reader.read_event_into(&mut buf).unwrap(),
Event::Decl(_)
));
assert_eq!(reader.decoder().encoding(), UTF_16LE);

reader.read_event_into(&mut buf).unwrap();
assert!(matches!(
reader.read_event_into(&mut buf).unwrap(),
Event::Decl(_)
));
assert_eq!(reader.decoder().encoding(), UTF_16LE);

assert_eq!(reader.read_event_into(&mut buf).unwrap(), Event::Eof);
Expand Down
20 changes: 19 additions & 1 deletion tests/encodings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use quick_xml::events::Event::*;
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event::*};
use quick_xml::Reader;

mod decode {
Expand Down Expand Up @@ -207,3 +207,21 @@ mod detect {
check_detection!(x_mac_cyrillic, X_MAC_CYRILLIC, "x-mac-cyrillic");
check_detection!(x_user_defined, X_USER_DEFINED, "x-user-defined");
}

#[test]
fn bom_removed_from_initial_text() {
let mut r =
Reader::from_str("\u{FEFF}asdf<paired attr1=\"value1\" attr2=\"value2\">text</paired>");

assert_eq!(r.read_event().unwrap(), Text(BytesText::new("asdf")));
assert_eq!(
r.read_event().unwrap(),
Start(BytesStart::from_content(
"paired attr1=\"value1\" attr2=\"value2\"",
6
))
);
assert_eq!(r.read_event().unwrap(), Text(BytesText::new("text")));
assert_eq!(r.read_event().unwrap(), End(BytesEnd::new("paired")));
assert_eq!(r.read_event().unwrap(), Eof);
}
18 changes: 0 additions & 18 deletions tests/xmlrs_reader_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ fn html5() {
);
}

#[test]
fn bom_removed_from_initial_text() {
let expected = r#"
|Characters(asdf)
|StartElement(paired [attr1="value1", attr2="value2"])
|Characters(text)
|EndElement(paired)
|EndDocument
"#;

// BOM right up against the text
test(
"\u{FEFF}asdf<paired attr1=\"value1\" attr2=\"value2\">text</paired>",
expected,
true,
);
}

#[test]
fn escaped_characters() {
test(
Expand Down

0 comments on commit 625c74e

Please sign in to comment.