dirbuf 0.1.2

reusable directory buffers
Documentation
use std::path::PathBuf;
use std::ffi::OsString;
use proptest::prelude::*;
use dirbuf::{DirBuf, DirBufEntry};

proptest! {
    #[test]
    fn random_strs(paths: Vec<OsString>) {
        let mut buf = DirBuf::with_capacity(100);
        fn recur(mut entry: DirBufEntry<'_>, paths: &[OsString]) -> Result<(), TestCaseError> {
            if paths.is_empty() {
                return Ok(())
            } else {
                let old_path: PathBuf = entry.as_ref().to_owned();
                let nentry = match entry.try_join(paths[0].clone()) {
                    Ok(x) => x,
                    Err(_err) => return Ok(()),
                };
                recur(nentry, &paths[1..])?;
                prop_assert_eq!(entry, old_path);
            }
            Ok(())
        }
        recur(buf.join("."), &paths[..])?;
    }

    /// make sure these two join functions stay in sync.
    #[test]
    fn compare_lit(path1: String, path2: String) {
        {
            let mut buf = DirBuf::new("");
            prop_assume!(buf.try_join(&path1).is_ok());
            prop_assume!(buf.try_join(&path2).is_ok());
        }
        let mut buf1 = DirBuf::new("../foo");
        let mut buf2 = DirBuf::new("../foo");
        prop_assert_eq!(&buf1, &buf2);
        let mut entry1 = buf1.join(&path1);
        let mut entry2 = buf2.join_lit(&path1);
        prop_assert_eq!(&entry1, &entry2);
        let alt_entry1 = entry1.join(&path2);
        let alt_entry2 = entry2.join_lit(&path2);
        prop_assert_eq!(&alt_entry1, &alt_entry2);
        prop_assert_eq!(&entry1, &entry2);
        prop_assert_eq!(&buf1, &buf2);
    }
}