use oxml::parse;
fn value(source: &str) -> String {
let doc = parse(source).expect("well-formed");
let root = doc.root_element().expect("a root element");
doc.attribute(root, "b").expect("attribute b").to_owned()
}
#[test]
fn literal_whitespace_becomes_a_space() {
assert_eq!(value("<a b='x\ny'/>"), "x y", "newline");
assert_eq!(value("<a b='x\ty'/>"), "x y", "tab");
assert_eq!(value("<a b='x\r\ny'/>"), "x y", "CR LF is one space");
assert_eq!(value("<a b='x\ry'/>"), "x y", "a lone CR");
}
#[test]
fn a_value_wrapped_across_lines_keeps_its_indentation_as_spaces() {
assert_eq!(value("<a b='one\n two'/>"), "one two");
}
#[test]
fn spaces_are_left_alone() {
assert_eq!(value("<a b='hello world'/>"), "hello world");
assert_eq!(value("<a b=' padded '/>"), " padded ");
assert_eq!(value("<a b=''/>"), "");
}
#[test]
fn a_character_reference_is_exempt() {
assert_eq!(value("<a b='x
y'/>"), "x\ny", "hex");
assert_eq!(value("<a b='x y'/>"), "x\ny", "decimal");
assert_eq!(value("<a b='x	y'/>"), "x\ty", "tab");
assert_eq!(value("<a b='x
y'/>"), "x\ry", "carriage return");
}
#[test]
fn a_general_entitys_replacement_text_is_normalised() {
let source = "<!DOCTYPE a [<!ENTITY e \"p\nq\">]><a b='&e;'/>";
assert_eq!(value(source), "p q");
let escaped = "<!DOCTYPE a [<!ENTITY e \"p
q\">]><a b='&e;'/>";
assert_eq!(value(escaped), "p\nq");
}
#[test]
fn the_predefined_entities_are_unaffected() {
assert_eq!(value("<a b='x&y'/>"), "x&y");
assert_eq!(value("<a b='x<y'/>"), "x<y");
assert_eq!(value("<a b='x"y'/>"), "x\"y");
}
#[test]
fn text_content_is_not_normalised() {
let doc = parse("<a>x\ny</a>").expect("well-formed");
assert_eq!(doc.text(doc.root()), "x\ny");
let doc = parse("<a>x\ty</a>").expect("well-formed");
assert_eq!(doc.text(doc.root()), "x\ty");
}