1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#[macro_use]
extern crate ego_tree;
#[test]
fn value() {
let tree = tree!('a');
assert_eq!(&'a', tree.root().value());
}
#[test]
fn parent() {
let tree = tree!('a' => { 'b' });
let b = tree.root().first_child().unwrap();
assert_eq!(tree.root(), b.parent().unwrap());
}
#[test]
fn prev_sibling() {
let tree = tree!('a' => { 'b', 'c' });
let c = tree.root().last_child().unwrap();
assert_eq!(tree.root().first_child(), c.prev_sibling());
}
#[test]
fn next_sibling() {
let tree = tree!('a' => { 'b', 'c' });
let b = tree.root().first_child().unwrap();
assert_eq!(tree.root().last_child(), b.next_sibling());
}
#[test]
fn first_child() {
let tree = tree!('a' => { 'b', 'c' });
assert_eq!(&'b', tree.root().first_child().unwrap().value());
}
#[test]
fn last_child() {
let tree = tree!('a' => { 'b', 'c' });
assert_eq!(&'c', tree.root().last_child().unwrap().value());
}
#[test]
fn has_siblings() {
let tree = tree!('a' => { 'b', 'c' });
assert_eq!(false, tree.root().has_siblings());
assert_eq!(true, tree.root().first_child().unwrap().has_siblings());
}
#[test]
fn has_children() {
let tree = tree!('a' => { 'b', 'c' });
assert_eq!(true, tree.root().has_children());
assert_eq!(false, tree.root().first_child().unwrap().has_children());
}
#[test]
fn clone() {
let tree = tree!('a');
let one = tree.root();
let two = one.clone();
assert_eq!(one, two);
}
#[test]
fn eq() {
let tree = tree!('a');
assert_eq!(tree.root(), tree.root());
}
#[test]
#[should_panic]
fn neq() {
let tree = tree!('a' => { 'b', 'c' });
assert_eq!(tree.root(), tree.root().first_child().unwrap());
}
#[test]
#[should_panic]
fn neq_tree() {
let one = tree!('a');
let two = one.clone();
assert_eq!(one.root(), two.root());
}
|