projd-core 0.3.0

Core project scanning data model and analysis helpers for Projd.
Documentation
use std::fs;

use projd_core::{VcsKind, scan_path};
use tempfile::tempdir;

#[test]
fn no_vcs_marker_yields_none() {
    let tmp = tempdir().expect("tempdir");
    let scan = scan_path(tmp.path()).expect("scan succeeds");
    assert_eq!(scan.vcs.kind, VcsKind::None);
    assert!(!scan.vcs.is_repository);
    assert!(scan.vcs.branch.is_none());
}

#[test]
fn hg_marker_alone_sets_kind() {
    let tmp = tempdir().expect("tempdir");
    fs::create_dir(tmp.path().join(".hg")).expect("create .hg");
    let scan = scan_path(tmp.path()).expect("scan succeeds");
    assert_eq!(scan.vcs.kind, VcsKind::Hg);
    assert!(scan.vcs.is_repository);
    // An empty .hg/ is not a valid repo; if hg ran it would fail. Either way
    // the kind tag must be Hg and is_repository must be true.
}

#[test]
fn svn_marker_alone_sets_kind() {
    let tmp = tempdir().expect("tempdir");
    fs::create_dir(tmp.path().join(".svn")).expect("create .svn");
    let scan = scan_path(tmp.path()).expect("scan succeeds");
    assert_eq!(scan.vcs.kind, VcsKind::Svn);
    assert!(scan.vcs.is_repository);
}

#[test]
fn fossil_marker_alone_sets_kind() {
    let tmp = tempdir().expect("tempdir");
    fs::write(tmp.path().join(".fslckout"), "").expect("create .fslckout");
    let scan = scan_path(tmp.path()).expect("scan succeeds");
    assert_eq!(scan.vcs.kind, VcsKind::Fossil);
    assert!(scan.vcs.is_repository);
}

#[test]
fn bzr_marker_alone_sets_kind() {
    let tmp = tempdir().expect("tempdir");
    fs::create_dir(tmp.path().join(".bzr")).expect("create .bzr");
    let scan = scan_path(tmp.path()).expect("scan succeeds");
    assert_eq!(scan.vcs.kind, VcsKind::Bzr);
    assert!(scan.vcs.is_repository);
}

#[test]
fn git_priority_over_other_markers() {
    let tmp = tempdir().expect("tempdir");
    fs::create_dir(tmp.path().join(".git")).expect("create .git");
    fs::create_dir(tmp.path().join(".hg")).expect("create .hg");
    let scan = scan_path(tmp.path()).expect("scan succeeds");
    assert_eq!(scan.vcs.kind, VcsKind::Git);
}