mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Implement a nicer Debug for NamespaceSet
The existing one was quite hard to parse visually, this makes it a lot easier to understand what is what.
This commit is contained in:
parent
f68826057b
commit
1496819546
1 changed files with 22 additions and 2 deletions
|
@ -1,9 +1,10 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct NamespaceSet {
|
pub struct NamespaceSet {
|
||||||
parent: RefCell<Option<Rc<NamespaceSet>>>,
|
parent: RefCell<Option<Rc<NamespaceSet>>>,
|
||||||
namespaces: BTreeMap<Option<String>, String>,
|
namespaces: BTreeMap<Option<String>, String>,
|
||||||
|
@ -18,6 +19,19 @@ impl Default for NamespaceSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for NamespaceSet {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "NamespaceSet(")?;
|
||||||
|
for (prefix, namespace) in &self.namespaces {
|
||||||
|
write!(f, "xmlns{}={:?}, ", match prefix {
|
||||||
|
None => String::new(),
|
||||||
|
Some(prefix) => format!(":{}", prefix),
|
||||||
|
}, namespace)?;
|
||||||
|
}
|
||||||
|
write!(f, "parent: {:?})", *self.parent.borrow())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl NamespaceSet {
|
impl NamespaceSet {
|
||||||
pub fn declared_ns(&self) -> &BTreeMap<Option<String>, String> {
|
pub fn declared_ns(&self) -> &BTreeMap<Option<String>, String> {
|
||||||
&self.namespaces
|
&self.namespaces
|
||||||
|
@ -107,7 +121,6 @@ impl From<(String, String)> for NamespaceSet {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_has() {
|
fn get_has() {
|
||||||
|
@ -147,4 +160,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn debug_looks_correct() {
|
||||||
|
let parent = NamespaceSet::from("http://www.w3.org/2000/svg".to_owned());
|
||||||
|
let namespaces = NamespaceSet::from(("xhtml".to_owned(), "http://www.w3.org/1999/xhtml".to_owned()));
|
||||||
|
namespaces.set_parent(Rc::new(parent));
|
||||||
|
assert_eq!(format!("{:?}", namespaces), "NamespaceSet(xmlns:xhtml=\"http://www.w3.org/1999/xhtml\", parent: Some(NamespaceSet(xmlns=\"http://www.w3.org/2000/svg\", parent: None)))");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue