xml-sec 0.1.23

Pure Rust XML Security: XMLDSig, XMLEnc, C14N. Drop-in replacement for libxmlsec1.
Documentation
// Generated by scripts/xml-kernel-examples.pl; edit the source examples.
#![allow(unused_imports, unused_variables, unused_mut)]

// lib.rs:117; original runnable example.
#[test]
fn lib_rs_example_1() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e/>").unwrap();
    assert!(doc.root().is_root());
    assert!(doc.root().first_child().unwrap().has_tag_name("e"));
}

// lib.rs:137; original runnable example.
#[test]
fn lib_rs_example_2() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse(
        "\
<p>
    text
</p>
",
    )
    .unwrap();

    use roxmltree::NodeId;
    assert_eq!(doc.get_node(NodeId::new(0)).unwrap(), doc.root());
    assert_eq!(
        doc.get_node(NodeId::new(1)),
        doc.descendants().find(|n| n.has_tag_name("p"))
    );
    assert_eq!(
        doc.get_node(NodeId::new(2)),
        doc.descendants().find(|n| n.is_text())
    );
    assert_eq!(doc.get_node(NodeId::new(3)), None);
}

// lib.rs:167; original runnable example.
#[test]
fn lib_rs_example_3() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<!-- comment --><e/>").unwrap();
    assert!(doc.root_element().has_tag_name("e"));
}

// lib.rs:193; original runnable example.
#[test]
fn lib_rs_example_4() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    use roxmltree::*;

    let doc = Document::parse(
        "\
<!-- comment -->
<e/>",
    )
    .unwrap();

    assert_eq!(doc.text_pos_at(10), TextPos::new(1, 11));
    assert_eq!(doc.text_pos_at(9999), TextPos::new(2, 5));
}

// lib.rs:213; original runnable example.
#[test]
fn lib_rs_example_5() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    use roxmltree::*;

    let doc = Document::parse("<e/>").unwrap();

    assert_eq!(doc.input_text(), "<e/>");
}

// lib.rs:661; original runnable example.
#[test]
fn lib_rs_example_6() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>").unwrap();

    assert_eq!(
        doc.root_element().attributes().next().unwrap().namespace(),
        None
    );
    assert_eq!(
        doc.root_element().attributes().nth(1).unwrap().namespace(),
        Some("http://www.w3.org")
    );
}

// lib.rs:678; original runnable example.
#[test]
fn lib_rs_example_7() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>").unwrap();

    assert_eq!(doc.root_element().attributes().next().unwrap().name(), "a");
    assert_eq!(doc.root_element().attributes().nth(1).unwrap().name(), "a");
}

// lib.rs:695; original runnable example.
#[test]
fn lib_rs_example_8() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>").unwrap();

    assert_eq!(doc.root_element().attributes().next().unwrap().value(), "b");
    assert_eq!(doc.root_element().attributes().nth(1).unwrap().value(), "c");
}

// lib.rs:822; original runnable example.
#[test]
fn lib_rs_example_9() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().namespaces().next().unwrap().name(),
        Some("n")
    );
}

// lib.rs:830; original runnable example.
#[test]
fn lib_rs_example_10() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

    assert_eq!(doc.root_element().namespaces().next().unwrap().name(), None);
}

// lib.rs:846; original runnable example.
#[test]
fn lib_rs_example_11() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().namespaces().next().unwrap().uri(),
        "http://www.w3.org"
    );
}

// lib.rs:1008; original runnable example.
#[test]
fn lib_rs_example_12() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().tag_name().namespace(),
        Some("http://www.w3.org")
    );
}

// lib.rs:1022; original runnable example.
#[test]
fn lib_rs_example_13() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e/>").unwrap();

    assert_eq!(doc.root_element().tag_name().name(), "e");
}

// lib.rs:1038; original runnable example.
#[test]
fn lib_rs_example_14() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    use roxmltree::ExpandedName;
    const DAV_HREF: ExpandedName =
        ExpandedName::from_static("urn:ietf:params:xml:ns:caldav:", "calendar-data");
}

// lib.rs:1196; original runnable example.
#[test]
fn lib_rs_example_15() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().tag_name().namespace(),
        Some("http://www.w3.org")
    );
    assert_eq!(doc.root_element().tag_name().name(), "e");
}

// lib.rs:1214; original runnable example.
#[test]
fn lib_rs_example_16() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

    assert!(doc.root_element().has_tag_name("e"));
    assert!(doc.root_element().has_tag_name(("http://www.w3.org", "e")));

    assert!(!doc.root_element().has_tag_name("b"));
    assert!(!doc.root_element().has_tag_name(("http://www.w4.org", "e")));
}

// lib.rs:1242; original runnable example.
#[test]
fn lib_rs_example_17() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().default_namespace(),
        Some("http://www.w3.org")
    );
}

// lib.rs:1248; original runnable example.
#[test]
fn lib_rs_example_18() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

    assert_eq!(doc.root_element().default_namespace(), None);
}

// lib.rs:1263; original runnable example.
#[test]
fn lib_rs_example_19() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().lookup_prefix("http://www.w3.org"),
        Some("n")
    );
}

// lib.rs:1269; original runnable example.
#[test]
fn lib_rs_example_20() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    // Namespaces in XML 1.0 §5 forbids undeclaring a non-default prefix.
    // https://www.w3.org/TR/2009/REC-xml-names-20091208/#nsc-NoPrefixUndecl
    assert!(roxmltree::Document::parse("<e xmlns:n=''/>").is_err());
    // Default namespace undeclaration is permitted by §6.2.
    let doc = roxmltree::Document::parse("<e xmlns=''/>").unwrap();

    assert_eq!(doc.root_element().lookup_prefix(""), None);
}

// lib.rs:1293; original runnable example.
#[test]
fn lib_rs_example_21() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().lookup_namespace_uri(Some("n")),
        Some("http://www.w3.org")
    );
}

// lib.rs:1299; original runnable example.
#[test]
fn lib_rs_example_22() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap();

    assert_eq!(
        doc.root_element().lookup_namespace_uri(None),
        Some("http://www.w3.org")
    );
}

// lib.rs:1314; original runnable example.
#[test]
fn lib_rs_example_23() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e a='b'/>").unwrap();

    assert_eq!(doc.root_element().attribute("a"), Some("b"));
}

// lib.rs:1320; original runnable example.
#[test]
fn lib_rs_example_24() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>").unwrap();

    assert_eq!(doc.root_element().attribute("a"), Some("b"));
    assert_eq!(
        doc.root_element().attribute(("http://www.w3.org", "a")),
        Some("c")
    );
}

// lib.rs:1360; original runnable example.
#[test]
fn lib_rs_example_25() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>").unwrap();

    assert!(doc.root_element().has_attribute("a"));
    assert!(doc.root_element().has_attribute(("http://www.w3.org", "a")));

    assert!(!doc.root_element().has_attribute("b"));
    assert!(!doc.root_element().has_attribute(("http://www.w4.org", "a")));
}

// lib.rs:1382; original runnable example.
#[test]
fn lib_rs_example_26() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>").unwrap();

    assert_eq!(doc.root_element().attributes().len(), 2);
}

// lib.rs:1398; original runnable example.
#[test]
fn lib_rs_example_27() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap();

    assert_eq!(doc.root_element().namespaces().len(), 1);
}

// lib.rs:1428; original runnable example.
#[test]
fn lib_rs_example_28() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse(
        "\
<p>
    text
</p>
",
    )
    .unwrap();

    assert_eq!(doc.root_element().text(), Some("\n    text\n"));
    assert_eq!(
        doc.root_element().first_child().unwrap().text(),
        Some("\n    text\n")
    );
}

// lib.rs:1441; original runnable example.
#[test]
fn lib_rs_example_29() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<!-- comment --><e/>").unwrap();

    assert_eq!(doc.root().first_child().unwrap().text(), Some(" comment "));
}

// lib.rs:1473; original runnable example.
#[test]
fn lib_rs_example_30() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse(
        "\
<root>
    text1
    <p/>
    text2
</root>
",
    )
    .unwrap();

    let p = doc.descendants().find(|n| n.has_tag_name("p")).unwrap();
    assert_eq!(p.tail(), Some("\n    text2\n"));
}

// parse.rs:508; original runnable example.
#[test]
fn parse_rs_example_1() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let doc = roxmltree::Document::parse("<e/>").unwrap();
    assert_eq!(doc.descendants().count(), 2); // root node + `e` element node
}

// parse.rs:524; original runnable example.
#[test]
fn parse_rs_example_2() -> impl std::process::Termination {
    use crate::parser_roxmltree as roxmltree;
    let opt = roxmltree::ParsingOptions::default();
    let doc = roxmltree::Document::parse_with_options("<e/>", opt).unwrap();
    assert_eq!(doc.descendants().count(), 2); // root node + `e` element node
}