Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Config struct that holds parser configuration and implement #513 #677

Merged
merged 11 commits into from
Nov 5, 2023
44 changes: 44 additions & 0 deletions tests/reader-config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Contains tests for config options of a parser.
//!
//! Each module has a name of a corresponding option and functions inside performs
//! testing of various option values.
//!
//! Please keep tests sorted (exceptions are allowed if options are tightly related).

use quick_xml::events::{BytesEnd, BytesStart, Event};
use quick_xml::reader::Reader;

mod expand_empty_elements {
use super::*;
use pretty_assertions::assert_eq;

/// Self-closed elements should be reported as one `Empty` event
#[test]
fn false_() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "enabled" and "disabled" would be better names, to avoid keyword clashes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose those words because if we will have other options that are not booleans, tests would be named as a config value

let mut reader = Reader::from_str("<root/>");
reader.expand_empty_elements(false);

assert_eq!(
reader.read_event().unwrap(),
Event::Empty(BytesStart::new("root"))
);
assert_eq!(reader.read_event().unwrap(), Event::Eof);
}

/// Self-closed elements should be reported as two events
#[test]
fn true_() {
let mut reader = Reader::from_str("<root/>");
reader.expand_empty_elements(true);

assert_eq!(
reader.read_event().unwrap(),
Event::Start(BytesStart::new("root"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::End(BytesEnd::new("root"))
);
assert_eq!(reader.read_event().unwrap(), Event::Eof);
}
}
14 changes: 0 additions & 14 deletions tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@ fn test_start_end_attr() {
next_eq!(r, Start, b"a", End, b"a");
}

#[test]
fn test_empty() {
let mut r = Reader::from_str("<a />");
r.trim_text(true);
next_eq!(r, Empty, b"a");
}

#[test]
fn test_empty_can_be_expanded() {
let mut r = Reader::from_str("<a />");
r.trim_text(true).expand_empty_elements(true);
next_eq!(r, Start, b"a", End, b"a");
}

#[test]
fn test_empty_attr() {
let mut r = Reader::from_str("<a b=\"test\" />");
Expand Down