Skip to content

Commit

Permalink
Add explicit tests for trim_text_start reader option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Nov 4, 2023
1 parent 75b4028 commit 3875bdb
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions tests/reader-config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,127 @@ mod trim_text {
}
}

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

#[test]
fn false_() {
let mut reader = Reader::from_str(XML);
reader.config_mut().trim_text_start = false;

assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\n"))
);

assert_eq!(
reader.read_event().unwrap(),
Event::DocType(BytesText::new("root \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\n"))
);

assert_eq!(
reader.read_event().unwrap(),
Event::Start(BytesStart::from_content("root \t\r\n", 4))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\n"))
);

assert_eq!(
reader.read_event().unwrap(),
Event::Empty(BytesStart::from_content("empty \t\r\n", 5))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\ntext \t\r\n"))
);

assert_eq!(
reader.read_event().unwrap(),
Event::Comment(BytesText::new(" comment \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\n"))
);

assert_eq!(
reader.read_event().unwrap(),
Event::CData(BytesCData::new(" \t\r\ncdata \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\n"))
);

assert_eq!(
reader.read_event().unwrap(),
Event::PI(BytesText::new("pi \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\n"))
);

assert_eq!(
reader.read_event().unwrap(),
Event::End(BytesEnd::new("root"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new(" \t\r\n"))
);

assert_eq!(reader.read_event().unwrap(), Event::Eof);
}

#[test]
fn true_() {
let mut reader = Reader::from_str(XML);
reader.config_mut().trim_text_start = true;

assert_eq!(
reader.read_event().unwrap(),
Event::DocType(BytesText::new("root \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Start(BytesStart::from_content("root \t\r\n", 4))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Empty(BytesStart::from_content("empty \t\r\n", 5))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Text(BytesText::new("text \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::Comment(BytesText::new(" comment \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::CData(BytesCData::new(" \t\r\ncdata \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::PI(BytesText::new("pi \t\r\n"))
);
assert_eq!(
reader.read_event().unwrap(),
Event::End(BytesEnd::new("root"))
);
assert_eq!(reader.read_event().unwrap(), Event::Eof);
}
}

mod trim_text_end {
use super::*;
use pretty_assertions::assert_eq;
Expand Down

0 comments on commit 3875bdb

Please sign in to comment.