use super::*;
use crate::namespace::table::NameTable;
use crate::navigator::RoXmlNavigator;
use crate::types::XmlTypeCode;
use crate::xpath::context::XPathContext;
fn make_element_data(
name: Option<crate::ids::NameId>,
target_namespace: Option<crate::ids::NameId>,
) -> crate::arenas::ElementDeclData {
crate::arenas::ElementDeclData {
name,
target_namespace,
ref_name: None,
type_ref: None,
inline_type: None,
substitution_group: Vec::new(),
default_value: None,
fixed_value: None,
nillable: false,
is_abstract: false,
min_occurs: 1,
max_occurs: Some(1),
block: DerivationSet::empty(),
final_derivation: DerivationSet::empty(),
form: None,
id: None,
alternatives: Vec::new(),
identity_constraints: Vec::new(),
pending_ic_refs: vec![],
annotation: None,
source: None,
resolved_type: None,
resolved_ref: None,
resolved_substitution_groups: Vec::new(),
deferred_type_error: None,
}
}
fn make_attribute_data(
name: Option<crate::ids::NameId>,
target_namespace: Option<crate::ids::NameId>,
) -> crate::arenas::AttributeDeclData {
crate::arenas::AttributeDeclData {
name,
target_namespace,
ref_name: None,
type_ref: None,
inline_type: None,
default_value: None,
fixed_value: None,
use_kind: None,
form: None,
inheritable: false,
id: None,
annotation: None,
source: None,
resolved_type: None,
resolved_ref: None,
}
}
#[test]
fn test_name_test_wildcard() {
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let test = NameTest::Wildcard;
assert!(matches_name_test(&test, &nav, &ctx));
}
#[test]
fn test_name_test_local_wildcard() {
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ns_id = table.add("urn:test");
let ctx = XPathContext::new(&table);
let test = NameTest::LocalWildcard(ns_id);
assert!(matches_name_test(&test, &nav, &ctx));
}
#[test]
fn test_name_test_namespace_wildcard() {
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let local_id = table.add("root");
let ctx = XPathContext::new(&table);
let test = NameTest::NamespaceWildcard(local_id);
assert!(matches_name_test(&test, &nav, &ctx));
}
#[test]
fn test_name_test_qname() {
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ns_id = table.add("urn:test");
let local_id = table.add("root");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(Some(ns_id), local_id, None);
let test = NameTest::QName(qname);
assert!(matches_name_test(&test, &nav, &ctx));
}
#[test]
fn test_sequence_type_element_name() {
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ns_id = table.add("urn:test");
let local_id = table.add("root");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(Some(ns_id), local_id, None);
let name_test = NameTest::QName(qname);
let seq = SequenceType::one(ItemType::Element(Some(name_test), None));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_sequence_type_document_with_element() {
let doc =
roxmltree::Document::parse("<root xmlns=\"urn:test\"><child/></root>").expect("parse xml");
let nav = RoXmlNavigator::new(&doc);
let table = NameTable::new();
let ns_id = table.add("urn:test");
let local_id = table.add("root");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(Some(ns_id), local_id, None);
let name_test = NameTest::QName(qname);
let inner = ItemType::Element(Some(name_test), None);
let seq = SequenceType::one(ItemType::Document(Some(Box::new(inner))));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_sequence_type_processing_instruction_target() {
let doc = roxmltree::Document::parse("<?target data?><root/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let seq = SequenceType::one(ItemType::ProcessingInstruction(Some("target".to_string())));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_sequence_type_text_like() {
let doc = roxmltree::Document::parse("<root>text</root>").expect("parse xml");
let mut text_nav = RoXmlNavigator::new(&doc);
text_nav.move_to_first_child();
text_nav.move_to_first_child();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let seq = SequenceType::one(ItemType::Text);
assert!(matches_sequence_type(&seq, &text_nav, &ctx));
}
#[test]
fn test_sequence_type_atomic_rejected_for_node() {
let doc = roxmltree::Document::parse("<root/>").expect("parse xml");
let nav = RoXmlNavigator::new(&doc);
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let seq = SequenceType::one(ItemType::AtomicType(XmlTypeCode::String));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_without_schema_context() {
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ns_id = table.add("urn:test");
let local_id = table.add("root");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(Some(ns_id), local_id, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_name_mismatch() {
let doc = roxmltree::Document::parse("<other xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ns_id = table.add("urn:test");
let local_id = table.add("root"); let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(Some(ns_id), local_id, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_namespace_mismatch() {
let doc = roxmltree::Document::parse("<root xmlns=\"urn:other\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ns_id = table.add("urn:test"); let local_id = table.add("root");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(Some(ns_id), local_id, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_rejects_attribute() {
let doc = roxmltree::Document::parse("<root attr=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let table = NameTable::new();
let local_id = table.add("attr");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(None, local_id, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_attribute_without_schema_context() {
let doc = roxmltree::Document::parse("<root attr=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let table = NameTable::new();
let local_id = table.add("attr");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(None, local_id, None);
let seq = SequenceType::one(ItemType::SchemaAttribute(qname));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_attribute_name_mismatch() {
let doc = roxmltree::Document::parse("<root other=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let table = NameTable::new();
let local_id = table.add("attr"); let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(None, local_id, None);
let seq = SequenceType::one(ItemType::SchemaAttribute(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_attribute_rejects_element() {
let doc = roxmltree::Document::parse("<root/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let local_id = table.add("root");
let ctx = XPathContext::new(&table);
let qname = QualifiedName::new(None, local_id, None);
let seq = SequenceType::one(ItemType::SchemaAttribute(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_kind_test_schema_element_without_schema() {
let doc = roxmltree::Document::parse("<root/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaElement("root".to_string());
assert!(matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_element_name_mismatch() {
let doc = roxmltree::Document::parse("<other/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaElement("root".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_element_rejects_attribute() {
let doc = roxmltree::Document::parse("<root attr=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaElement("attr".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_attribute_without_schema() {
let doc = roxmltree::Document::parse("<root attr=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaAttribute("attr".to_string());
assert!(matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_attribute_name_mismatch() {
let doc = roxmltree::Document::parse("<root other=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaAttribute("attr".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_attribute_rejects_element() {
let doc = roxmltree::Document::parse("<root/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaAttribute("root".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_schema_element_with_schema_context_declaration_found() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let ns_uri = schema_set.name_table.add("urn:test");
let elem_name = schema_set.name_table.add("root");
schema_set.get_or_create_namespace(Some(ns_uri));
let elem_data = make_element_data(Some(elem_name), Some(ns_uri));
let elem_key = schema_set.arenas.alloc_element(elem_data);
schema_set
.namespaces
.get_mut(&Some(ns_uri))
.unwrap()
.elements
.insert(elem_name, elem_key);
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(Some(ns_uri), elem_name, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_with_schema_context_type_requires_annotation() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let ns_uri = schema_set.name_table.add("urn:test");
let elem_name = schema_set.name_table.add("root");
let string_type = schema_set.builtin_types().string;
schema_set.get_or_create_namespace(Some(ns_uri));
let mut elem_data = make_element_data(Some(elem_name), Some(ns_uri));
elem_data.resolved_type = Some(TypeKey::Simple(string_type));
let elem_key = schema_set.arenas.alloc_element(elem_data);
schema_set
.namespaces
.get_mut(&Some(ns_uri))
.unwrap()
.elements
.insert(elem_name, elem_key);
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(Some(ns_uri), elem_name, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_attribute_with_schema_context_declaration_found() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let attr_name = schema_set.name_table.add("attr");
schema_set.get_or_create_namespace(None);
let attr_data = make_attribute_data(Some(attr_name), None);
let attr_key = schema_set.arenas.alloc_attribute(attr_data);
schema_set
.namespaces
.get_mut(&None)
.unwrap()
.attributes
.insert(attr_name, attr_key);
let doc = roxmltree::Document::parse("<root attr=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(None, attr_name, None);
let seq = SequenceType::one(ItemType::SchemaAttribute(qname));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_attribute_with_schema_context_type_requires_annotation() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let attr_name = schema_set.name_table.add("attr");
let string_type = schema_set.builtin_types().string;
schema_set.get_or_create_namespace(None);
let mut attr_data = make_attribute_data(Some(attr_name), None);
attr_data.resolved_type = Some(TypeKey::Simple(string_type));
let attr_key = schema_set.arenas.alloc_attribute(attr_data);
schema_set
.namespaces
.get_mut(&None)
.unwrap()
.attributes
.insert(attr_name, attr_key);
let doc = roxmltree::Document::parse("<root attr=\"value\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(None, attr_name, None);
let seq = SequenceType::one(ItemType::SchemaAttribute(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_declaration_not_found_rejects() {
use crate::schema::model::SchemaSet;
let schema_set = SchemaSet::new();
let ns_uri = schema_set.name_table.add("urn:test");
let elem_name = schema_set.name_table.add("root");
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(Some(ns_uri), elem_name, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_type_derivation_match() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let ns_uri = schema_set.name_table.add("urn:test");
let elem_name = schema_set.name_table.add("root");
let string_type = schema_set.builtin_types().string;
schema_set.get_or_create_namespace(Some(ns_uri));
let mut elem_data = make_element_data(Some(elem_name), Some(ns_uri));
elem_data.resolved_type = Some(TypeKey::Simple(string_type));
let elem_key = schema_set.arenas.alloc_element(elem_data);
schema_set
.namespaces
.get_mut(&Some(ns_uri))
.unwrap()
.elements
.insert(elem_name, elem_key);
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let nav = {
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.with_schema_type(string_type)
};
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(Some(ns_uri), elem_name, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_type_derivation_derived_type() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let ns_uri = schema_set.name_table.add("urn:test");
let elem_name = schema_set.name_table.add("root");
let string_type = schema_set.builtin_types().string;
let normalized_string_type = schema_set.builtin_types().normalized_string;
schema_set.get_or_create_namespace(Some(ns_uri));
let mut elem_data = make_element_data(Some(elem_name), Some(ns_uri));
elem_data.resolved_type = Some(TypeKey::Simple(string_type));
let elem_key = schema_set.arenas.alloc_element(elem_data);
schema_set
.namespaces
.get_mut(&Some(ns_uri))
.unwrap()
.elements
.insert(elem_name, elem_key);
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let nav = {
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.with_schema_type(normalized_string_type)
};
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(Some(ns_uri), elem_name, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_element_type_derivation_mismatch() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let ns_uri = schema_set.name_table.add("urn:test");
let elem_name = schema_set.name_table.add("root");
let string_type = schema_set.builtin_types().string;
let integer_type = schema_set.builtin_types().integer;
schema_set.get_or_create_namespace(Some(ns_uri));
let mut elem_data = make_element_data(Some(elem_name), Some(ns_uri));
elem_data.resolved_type = Some(TypeKey::Simple(string_type));
let elem_key = schema_set.arenas.alloc_element(elem_data);
schema_set
.namespaces
.get_mut(&Some(ns_uri))
.unwrap()
.elements
.insert(elem_name, elem_key);
let doc = roxmltree::Document::parse("<root xmlns=\"urn:test\"/>").expect("parse xml");
let nav = {
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.with_schema_type(integer_type)
};
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(Some(ns_uri), elem_name, None);
let seq = SequenceType::one(ItemType::SchemaElement(qname));
assert!(!matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_schema_attribute_type_derivation_match() {
use crate::schema::model::SchemaSet;
let mut schema_set = SchemaSet::new();
let attr_name = schema_set.name_table.add("attr");
let string_type = schema_set.builtin_types().string;
schema_set.get_or_create_namespace(None);
let mut attr_data = make_attribute_data(Some(attr_name), None);
attr_data.resolved_type = Some(TypeKey::Simple(string_type));
let attr_key = schema_set.arenas.alloc_attribute(attr_data);
schema_set
.namespaces
.get_mut(&None)
.unwrap()
.attributes
.insert(attr_name, attr_key);
let doc = roxmltree::Document::parse("<root attr=\"value\"/>").expect("parse xml");
let nav = {
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
nav.with_schema_type(string_type)
};
let ctx = XPathContext::new(&schema_set.name_table).with_schema_set(&schema_set);
let qname = QualifiedName::new(None, attr_name, None);
let seq = SequenceType::one(ItemType::SchemaAttribute(qname));
assert!(matches_sequence_type(&seq, &nav, &ctx));
}
#[test]
fn test_kind_test_schema_element_prefixed_qname() {
use crate::namespace::context::NamespaceContextSnapshot;
let doc = roxmltree::Document::parse("<ns:root xmlns:ns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let prefix_id = table.add("ns");
let ns_id = table.add("urn:test");
let ns_ctx = NamespaceContextSnapshot {
default_ns: None,
bindings: vec![(prefix_id, ns_id)],
};
let ctx = XPathContext::new(&table).with_namespaces(ns_ctx);
let kind_test = KindTest::SchemaElement("ns:root".to_string());
assert!(matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_element_prefixed_qname_wrong_ns() {
use crate::namespace::context::NamespaceContextSnapshot;
let doc = roxmltree::Document::parse("<ns:root xmlns:ns=\"urn:other\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let prefix_id = table.add("ns");
let ns_id = table.add("urn:test");
let ns_ctx = NamespaceContextSnapshot {
default_ns: None,
bindings: vec![(prefix_id, ns_id)],
};
let ctx = XPathContext::new(&table).with_namespaces(ns_ctx);
let kind_test = KindTest::SchemaElement("ns:root".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_element_unresolved_prefix() {
let doc = roxmltree::Document::parse("<ns:root xmlns:ns=\"urn:test\"/>").expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaElement("unknown:root".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_attribute_prefixed_qname() {
use crate::namespace::context::NamespaceContextSnapshot;
let doc = roxmltree::Document::parse("<root xmlns:ns=\"urn:test\" ns:attr=\"value\"/>")
.expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
while nav.local_name() != "attr" {
if !nav.move_to_next_attribute() {
panic!("ns:attr attribute not found");
}
}
let table = NameTable::new();
let prefix_id = table.add("ns");
let ns_id = table.add("urn:test");
let ns_ctx = NamespaceContextSnapshot {
default_ns: None,
bindings: vec![(prefix_id, ns_id)],
};
let ctx = XPathContext::new(&table).with_namespaces(ns_ctx);
let kind_test = KindTest::SchemaAttribute("ns:attr".to_string());
assert!(matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_attribute_prefixed_qname_wrong_ns() {
use crate::namespace::context::NamespaceContextSnapshot;
let doc = roxmltree::Document::parse("<root xmlns:ns=\"urn:other\" ns:attr=\"value\"/>")
.expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
while nav.local_name() != "attr" {
if !nav.move_to_next_attribute() {
panic!("ns:attr attribute not found");
}
}
let table = NameTable::new();
let prefix_id = table.add("ns");
let ns_id = table.add("urn:test");
let ns_ctx = NamespaceContextSnapshot {
default_ns: None,
bindings: vec![(prefix_id, ns_id)],
};
let ctx = XPathContext::new(&table).with_namespaces(ns_ctx);
let kind_test = KindTest::SchemaAttribute("ns:attr".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}
#[test]
fn test_kind_test_schema_attribute_unresolved_prefix() {
let doc = roxmltree::Document::parse("<root xmlns:ns=\"urn:test\" ns:attr=\"value\"/>")
.expect("parse xml");
let mut nav = RoXmlNavigator::new(&doc);
nav.move_to_first_child();
nav.move_to_first_attribute();
while nav.local_name() != "attr" {
if !nav.move_to_next_attribute() {
panic!("ns:attr attribute not found");
}
}
let table = NameTable::new();
let ctx = XPathContext::new(&table);
let kind_test = KindTest::SchemaAttribute("unknown:attr".to_string());
assert!(!matches_kind_test(&nav, &kind_test, &ctx));
}