Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Add tests for #344
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Mar 8, 2022
1 parent 206e57f commit 9582fe5
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion src/reader.rs
Expand Up @@ -255,7 +255,8 @@ impl<R: BufRead> Reader<R> {
}
}

/// private function to read until '>' is found
/// Private function to read until `>` is found. This function expects that
/// it was called just after encounter a `<` symbol.
fn read_until_close<'i, 'r, B>(&mut self, buf: B) -> Result<Event<'i>>
where
R: BufferedInput<'i, 'r, B>,
Expand Down Expand Up @@ -2085,6 +2086,70 @@ mod test {
}
}
}

mod issue_344 {
use crate::errors::Error;

#[test]
fn cdata() {
let doc = "![]]>";
let mut reader = crate::Reader::from_str(doc);

match reader.read_until_close($buf) {
Err(Error::UnexpectedEof(s)) if s == "CData" => {}
x => assert!(
false,
r#"Expected `UnexpectedEof("CData")`, but result is: {:?}"#,
x
),
}
}

#[test]
fn comment() {
let doc = "!- -->";
let mut reader = crate::Reader::from_str(doc);

match reader.read_until_close($buf) {
Err(Error::UnexpectedEof(s)) if s == "Comment" => {}
x => assert!(
false,
r#"Expected `UnexpectedEof("Comment")`, but result is: {:?}"#,
x
),
}
}

#[test]
fn doctype_uppercase() {
let doc = "!D>";
let mut reader = crate::Reader::from_str(doc);

match reader.read_until_close($buf) {
Err(Error::UnexpectedEof(s)) if s == "DOCTYPE" => {}
x => assert!(
false,
r#"Expected `UnexpectedEof("DOCTYPE")`, but result is: {:?}"#,
x
),
}
}

#[test]
fn doctype_lowercase() {
let doc = "!d>";
let mut reader = crate::Reader::from_str(doc);

match reader.read_until_close($buf) {
Err(Error::UnexpectedEof(s)) if s == "DOCTYPE" => {}
x => assert!(
false,
r#"Expected `UnexpectedEof("DOCTYPE")`, but result is: {:?}"#,
x
),
}
}
}
};
}

Expand Down

0 comments on commit 9582fe5

Please sign in to comment.