extern crate namespace;
use namespace::{
Namespace,
NSErr,
};
#[test]
fn basic_1() {
let ns = Namespace::new("a::b::c").unwrap();
assert_eq!(ns.to_string(), "a::b::c");
}
#[test]
fn basic_2() {
let ns = Namespace::new("a::b").unwrap();
let mut ns_iter = ns.iter();
assert_eq!(ns_iter.next().unwrap(), "a");
}
#[test]
fn remainder() {
let ns = Namespace::new("a::b::c").unwrap();
let other = Namespace::new("c::d::e").unwrap();
assert_eq!(
ns.remainder(&other).unwrap().to_string(),
"d::e"
)
}
#[test]
fn empty_1() {
match Namespace::new("") {
Err(NSErr::Parse(s, 0)) => assert_eq!(&s, ""),
_ => assert!(false),
};
}
#[test]
fn empty_2() {
match Namespace::new("::") {
Err(NSErr::Parse(s, 0)) => assert_eq!(&s, "::"),
_ => assert!(false),
};
}
#[test]
fn empty_3() {
match Namespace::new("a::::c") {
Err(NSErr::Parse(s, 3)) => assert_eq!(&s, "a::::c"),
_ => assert!(false),
};
}
#[test]
fn append() {
let ns1 = Namespace::new("a::b").unwrap();
let ns2 = Namespace::new("c::d").unwrap();
let out = ns1.append(&ns2);
let mut iter = out.iter();
assert!(&out.to_string() == "a::b::c::d" );
assert!(iter.next() == Some("a") );
assert!(iter.next() == Some("b") );
assert!(iter.next() == Some("c") );
assert!(iter.next() == Some("d") );
assert!(iter.next() == None );
}
#[test]
fn append_at_1() {
let ns1 = Namespace::new("a::b::c").unwrap();
let ns2 = Namespace::new("d").unwrap();
assert_eq!(
ns1.append_at(&ns2, 1)
.unwrap()
.to_string(),
"a::d"
);
}
#[test]
fn append_at_3() {
let ns1 = Namespace::new("hobbit::name").unwrap();
let ns2 = Namespace::new("age").unwrap();
assert_eq!(
ns1.append_at(&ns2, 1)
.unwrap()
.to_string(),
"hobbit::age"
);
}
#[test]
fn append_at_2() {
let ns1 = Namespace::new("a").unwrap();
let ns2 = Namespace::new("b::c").unwrap();
assert_eq!(
ns1.append_at(&ns2, 1)
.unwrap()
.to_string(),
"a::b::c"
);
}
#[test]
fn test_sliding_match() {
let ns = Namespace::new("a::b::c").unwrap();
let other = Namespace::new("c::d::e").unwrap();
assert_eq!(
ns.sliding_match(&other),
vec!(2),
);
}
#[test]
fn test_sliding_join() {
let ns = Namespace::new("a::b").unwrap();
let other = Namespace::new("b::c").unwrap();
assert_eq!(
ns.sliding_join(&other).unwrap().to_string(),
"a::b::c",
);
}
#[test]
fn test_offset_match() {
let ns1 = Namespace::new("a::b::c").unwrap();
let other = Namespace::new("b::c::d").unwrap();
assert!(ns1.offset_match(&other, 1));
assert!(!ns1.offset_match(&other, 0));
}
#[test]
fn remove_0() {
assert_eq!(
Namespace::new("a::b::c").unwrap()
.remove(0)
.unwrap()
.to_string(),
"a::b::c"
);
}
#[test]
fn remove_1() {
assert_eq!(
Namespace::new("a::b::c").unwrap()
.remove(1)
.unwrap()
.to_string(),
"a::b"
);
}
#[test]
fn remove_2() {
assert_eq!(
Namespace::new("a::b::c").unwrap()
.remove(2)
.unwrap()
.to_string(),
"a"
);
}
#[test]
fn test_truncate_1() {
assert_eq!(
Namespace::new("a::b::c").unwrap()
.truncate(2)
.unwrap()
.to_string(),
"a::b"
);
}
#[test]
fn test_truncate_2() {
assert_eq!(
Namespace::new("a::b").unwrap()
.truncate(2)
.unwrap()
.to_string(),
"a::b"
);
}