Skip to content

Commit

Permalink
Add tests for comments and processing instructions in XML prolog
Browse files Browse the repository at this point in the history
See <https://www.w3.org/TR/xml11/#NT-prolog>

failures (2):
    xml_prolog::comments
    xml_prolog::pi
  • Loading branch information
Dan Griffin authored and Mingun committed Jun 9, 2023
1 parent 5fc695e commit c8332d9
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/serde-de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6496,3 +6496,77 @@ mod resolve {
);
}
}

/// Tests for https://github.com/tafia/quick-xml/pull/603.
///
/// According to <https://www.w3.org/TR/xml11/#NT-prolog> comments,
/// processing instructions and spaces are possible after XML declaration or DTD.
/// Their existence should not break deserializing
///
/// ```text
/// [22] prolog ::= XMLDecl Misc* (doctypedecl Misc*)?
/// [27] Misc ::= Comment | PI | S
/// ```
mod xml_prolog {
use super::*;
use pretty_assertions::assert_eq;
use std::collections::HashMap;

#[test]
fn spaces() {
assert_eq!(
from_str::<HashMap<(), ()>>(
r#"
<?xml version="1.1"?>
<!DOCTYPE dict>
<doc>
</doc>
"#
)
.unwrap(),
HashMap::new()
);
}

#[test]
fn comments() {
assert_eq!(
from_str::<HashMap<(), ()>>(
r#"
<?xml version="1.1"?>
<!-- comment between xml declaration and doctype -->
<!-- another comment -->
<!DOCTYPE dict>
<!-- comment between doctype and root element -->
<!-- another comment -->
<doc>
</doc>
"#,
)
.unwrap(),
HashMap::new()
);
}

#[test]
fn pi() {
assert_eq!(
from_str::<HashMap<(), ()>>(
r#"
<?xml version="1.1"?>
<?pi?>
<?another pi?>
<!DOCTYPE dict>
<?pi?>
<?another pi?>
<doc>
</doc>
"#,
)
.unwrap(),
HashMap::new()
);
}
}

0 comments on commit c8332d9

Please sign in to comment.