use unixstring::UnixString;
#[test]
fn push_empty_str() {
let mut unx = UnixString::new();
unx.push("").unwrap();
assert_eq!(unx.as_bytes(), &[]);
assert_eq!(unx.as_bytes_with_nul(), &[0]);
assert_eq!(unx.to_str().unwrap(), "");
unx.push("\0").unwrap();
assert_eq!(unx.as_bytes(), &[]);
assert_eq!(unx.as_bytes_with_nul(), &[0]);
assert_eq!(unx.to_str().unwrap(), "");
unx.push("abc").unwrap();
assert_eq!(unx.as_bytes(), b"abc".to_vec());
assert_eq!(unx.as_bytes_with_nul(), b"abc\0".to_vec());
assert_eq!(unx.to_str().unwrap(), "abc");
unx.push("\0").unwrap();
assert_eq!(unx.as_bytes(), b"abc".to_vec());
assert_eq!(unx.as_bytes_with_nul(), b"abc\0".to_vec());
assert_eq!(unx.to_str().unwrap(), "abc");
unx.push("").unwrap();
assert_eq!(unx.as_bytes(), b"abc".to_vec());
assert_eq!(unx.as_bytes_with_nul(), b"abc\0".to_vec());
assert_eq!(unx.to_str().unwrap(), "abc");
}
#[test]
fn push_str() {
let mut unx = UnixString::new();
unx.push("abc").unwrap();
assert_eq!(unx.as_bytes(), b"abc".to_vec());
assert_eq!(unx.as_bytes_with_nul(), b"abc\0".to_vec());
assert_eq!(unx.to_str().unwrap(), "abc");
unx.push("d\0").unwrap();
assert_eq!(unx.as_bytes(), b"abcd".to_vec());
assert_eq!(unx.as_bytes_with_nul(), b"abcd\0".to_vec());
assert_eq!(unx.to_str().unwrap(), "abcd");
unx.push("\0d\0").unwrap_err();
assert_eq!(unx.as_bytes(), b"abcd".to_vec());
assert_eq!(unx.as_bytes_with_nul(), b"abcd\0".to_vec());
assert_eq!(unx.to_str().unwrap(), "abcd");
}