dia-semver 0.2.0

For handling Semantic Versions 2.0.0
Documentation
// License: see LICENSE file at root directory of `master` branch

use std::collections::BTreeSet;
use std::str::FromStr;

extern crate dia_semver;

use dia_semver::Semver;

#[test]
fn ordering() {
    assert!(Semver::from_str("1.0.0").unwrap() == Semver::from_str("1.0.0").unwrap());
    assert!(Semver::from_str("1.0.0").unwrap() < Semver::from_str("1.0.1").unwrap());
    assert!(Semver::from_str("1.1.0").unwrap() > Semver::from_str("1.0.1").unwrap());

    assert!(Semver::from_str("2.0.0-abc").unwrap() == Semver::from_str("2.0.0-abc").unwrap());
    assert!(Semver::from_str("2.0.0-abc").unwrap() < Semver::from_str("2.0.0-xyz").unwrap());

    assert!(Semver::from_str("3.0-abc+2313").unwrap() == Semver::from_str("3.0.0-abc").unwrap());
    assert!(Semver::from_str("3.1.0-abc+2313").unwrap() == Semver::from_str("3.1-abc+xyz-123").unwrap());

    assert!(Semver::from_str("4-abc.123").unwrap() == Semver::from_str("4-abc.123").unwrap());
    assert!(Semver::from_str("4-abc.123").unwrap() > Semver::from_str("4-123.abc").unwrap());
    assert!(Semver::from_str("4-123").unwrap() < Semver::from_str("4-123.abc").unwrap());

    assert!(Semver::from_str("5-123").unwrap() < Semver::from_str("5-321").unwrap());
    assert!(Semver::from_str("5-123.abc").unwrap() < Semver::from_str("5-321").unwrap());
    assert!(Semver::from_str("5-123").unwrap() < Semver::from_str("5-321.xyz").unwrap());

    assert!(Semver::from_str("6").unwrap() > Semver::from_str("6-ABC").unwrap());
    assert!(Semver::from_str("6").unwrap() == Semver::from_str("6+ABC").unwrap());
    assert!(Semver::from_str("6+XYZ").unwrap() == Semver::from_str("6+ABC").unwrap());

    assert!(Semver::from_str("1.0.0-alpha").unwrap() < Semver::from_str("1.0.0-alpha.1").unwrap());
    assert!(Semver::from_str("1.0.0-alpha.1").unwrap() < Semver::from_str("1.0.0-alpha.beta").unwrap());
    assert!(Semver::from_str("1.0.0-alpha.beta").unwrap() < Semver::from_str("1.0.0-beta").unwrap());
    assert!(Semver::from_str("1.0.0-beta").unwrap() < Semver::from_str("1.0.0-beta.2").unwrap());
    assert!(Semver::from_str("1.0.0-beta.2").unwrap() < Semver::from_str("1.0.0-beta.11").unwrap());
    assert!(Semver::from_str("1.0.0-beta.11").unwrap() < Semver::from_str("1.0.0-rc.1").unwrap());
    assert!(Semver::from_str("1.0.0-rc.1").unwrap() < Semver::from_str("1.0.0").unwrap());

    let mut set = BTreeSet::new();
    set.insert(Semver::from_str("1.0.0+a.b.c").unwrap());
    set.insert(Semver::from_str("1.0.0").unwrap());
    assert!(set.len() == 1);
}