git-url-parse 0.3.1

A parser for git repo urls based on url crate
Documentation
use git_url_parse::*;

// Url Normalization
#[test]
fn git() {
    let test_url = "git://host.tld/user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(normalized.as_str(), "git://host.tld/user/project-name.git");
}

#[test]
fn http() {
    let test_url = "http://host.tld/user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(normalized.as_str(), "http://host.tld/user/project-name.git");
}

#[test]
fn https() {
    let test_url = "https://host.tld/user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(
        normalized.as_str(),
        "https://host.tld/user/project-name.git"
    );
}

#[test]
fn ssh_scheme() {
    let test_url = "ssh://git@host.tld/user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(
        normalized.as_str(),
        "ssh://git@host.tld/user/project-name.git"
    );
}

#[test]
fn ssh_no_scheme() {
    let test_url = "git@host.tld:user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(
        normalized.as_str(),
        "ssh://git@host.tld/user/project-name.git"
    );
}

#[test]
fn ssh_no_scheme_no_user() {
    let test_url = "host.tld:user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(normalized.as_str(), "ssh://host.tld/user/project-name.git");
}

#[test]
fn unix_file_scheme_abs_path() {
    let test_url = "file:///user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(normalized.as_str(), "file:///user/project-name.git");
}

#[test]
fn unix_file_no_scheme_abs_path() {
    let test_url = "/user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(normalized.as_str(), "file:///user/project-name.git");
}

#[test]
fn unix_file_scheme_rel_path() {
    let test_url = "file://../user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(normalized.as_str(), "file://../user/project-name.git");
}

#[test]
fn unix_file_no_scheme_rel_path() {
    let test_url = "../user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(normalized.as_str(), "file://../user/project-name.git");
}

#[should_panic(expected = "assertion failed: `(left == right)")]
#[test]
fn win_file_scheme_abs_path() {
    let test_url = "file://c:\\user\\project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    // I actually don't know how this should be normalized.
    assert_eq!(normalized.as_str(), "file://c:\\user\\project-name.git");
}

#[should_panic(expected = "assertion failed: `(left == right)")]
#[test]
fn win_file_no_scheme_abs_path() {
    let test_url = "c:\\user\\project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    // I actually don't know how this should be normalized.
    assert_eq!(normalized.as_str(), "file://c:\\user\\project-name.git");
}

#[test]
fn win_file_scheme_rel_path() {
    let test_url = "file://..\\user\\project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    // I actually don't know how this should be normalized.
    assert_eq!(normalized.as_str(), "file://../user/project-name.git");
}

#[test]
fn win_file_no_scheme_rel_path() {
    let test_url = "..\\user\\project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    // I actually don't know how this should be normalized.
    assert_eq!(normalized.as_str(), "file://../user/project-name.git");
}
#[test]
fn multi_git_ssh() {
    let test_url = "git+ssh://host.tld/user/project-name.git";
    let normalized = normalize_url(test_url).expect("Normalizing url failed");

    assert_eq!(
        normalized.as_str(),
        "git+ssh://host.tld/user/project-name.git"
    );
}