Skip to content

Issue 17 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use thiserror::Error;
/*
use xml;

// this is redundant, cargo clippy suggested to remove it
= note: `#[warn(clippy::single_component_path_imports)]` on by default
= help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
*/
#[derive(Debug, Error)]
pub enum TreexmlError {
#[error("Element not found: '{t}'")]
Expand Down
39 changes: 25 additions & 14 deletions tests/read.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
extern crate treexml;

mod read {

mod document {

use treexml::{Document, XmlVersion};

#[test]
Expand Down Expand Up @@ -37,7 +35,6 @@ mod read {
}

mod tags {

use treexml::Document;

#[test]
Expand Down Expand Up @@ -102,7 +99,7 @@ mod read {
let doc = Document::parse(doc_raw.as_bytes()).unwrap();
let root = doc.root.unwrap();

assert_eq!(root.find_child(|t| t.name == "child"), None);
assert_eq!(root.find_child(|t| t.name == "child".to_owned()), None);
}

#[test]
Expand All @@ -119,7 +116,10 @@ mod read {
let mut child = Element::new("child");
child.attributes.insert("attr_a".to_owned(), "1".to_owned());

assert_eq!(root.find_child(|t| t.name == "child"), Some(&child));
assert_eq!(
root.find_child(|t| t.name == "child".to_owned()),
Some(&child)
);
}

#[test]
Expand All @@ -137,7 +137,10 @@ mod read {
let mut child = Element::new("child");
child.attributes.insert("attr_a".to_owned(), "1".to_owned());

assert_eq!(root.find_child(|t| t.name == "child"), Some(&child));
assert_eq!(
root.find_child(|t| t.name == "child".to_owned()),
Some(&child)
);
}

#[test]
Expand All @@ -152,15 +155,20 @@ mod read {
let mut root = doc.root.unwrap();

{
let child = root.find_child_mut(|t| t.name == "child").unwrap();
let child = root
.find_child_mut(|t| t.name == "child".to_owned())
.unwrap();
let attr_a = child.attributes.get_mut(&"attr_a".to_owned()).unwrap();
*attr_a = "2".to_owned();
}

let mut child = Element::new("child");
child.attributes.insert("attr_a".to_owned(), "2".to_owned());

assert_eq!(root.find_child(|t| t.name == "child"), Some(&child));
assert_eq!(
root.find_child(|t| t.name == "child".to_owned()),
Some(&child)
);
}

#[test]
Expand All @@ -180,7 +188,9 @@ mod read {
ch1.text = Some("1".to_owned());
ch2.text = Some("2".to_owned());

let children: Vec<&Element> = root.filter_children(|t| t.name == "child").collect();
let children: Vec<&Element> = root
.filter_children(|t| t.name == "child".to_owned())
.collect();
let children_ref = vec![&ch1, &ch2];

assert_eq!(children, children_ref);
Expand All @@ -199,8 +209,9 @@ mod read {
let mut root = doc.root.unwrap();

{
let mut children: Vec<&mut Element> =
root.filter_children_mut(|t| t.name == "child").collect();
let mut children: Vec<&mut Element> = root
.filter_children_mut(|t| t.name == "child".to_owned())
.collect();
children[0].text = Some("4".to_owned());
children[1].text = Some("5".to_owned());
}
Expand All @@ -210,7 +221,9 @@ mod read {
ch1.text = Some("4".to_owned());
ch2.text = Some("5".to_owned());

let children: Vec<&Element> = root.filter_children(|t| t.name == "child").collect();
let children: Vec<&Element> = root
.filter_children(|t| t.name == "child".to_owned())
.collect();
let children_ref = vec![&ch1, &ch2];

assert_eq!(children, children_ref);
Expand Down Expand Up @@ -271,7 +284,6 @@ mod read {
}

mod cdata {

use treexml::Document;

#[test]
Expand Down Expand Up @@ -320,7 +332,6 @@ mod read {
}

mod complete {

use treexml::{Document, Element, XmlVersion};

#[test]
Expand Down
7 changes: 5 additions & 2 deletions tests/readme.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extern crate treexml;

mod readme {

use treexml::{Document, ElementBuilder as E};

#[test]
fn read() {
let doc_raw = r#"
Expand All @@ -16,7 +16,10 @@ mod readme {
let doc = Document::parse(doc_raw.as_bytes()).unwrap();
let root = doc.root.unwrap();

let fruit = root.find_child(|tag| tag.name == "fruit").unwrap().clone();
let fruit = root
.find_child(|tag| tag.name == "fruit".to_owned())
.unwrap()
.clone();
println!("{} [{:?}] = {:?}", fruit.name, fruit.attributes, fruit.text,);
}

Expand Down
5 changes: 0 additions & 5 deletions tests/write.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
extern crate treexml;

mod write {

mod document {

use treexml::{Document, Element};

#[test]
Expand Down Expand Up @@ -49,7 +47,6 @@ mod write {
}

mod element {

use treexml::{Document, Element};

#[test]
Expand All @@ -71,7 +68,6 @@ mod write {
}

mod contents {

use treexml::{Document, Element};

#[test]
Expand Down Expand Up @@ -112,7 +108,6 @@ mod write {
}

mod cdata {

use treexml::{Document, Element};

#[test]
Expand Down