Commit 996dd2d0 authored by Scott Abbey's avatar Scott Abbey

Add tests

parent fbc9bdf1
......@@ -53,7 +53,70 @@ mod tests {
use super::*;
#[test]
fn parse_version_core() {
fn parse_empty() {
let version = "";
let parsed = parse_version(version);
assert!(parsed.is_err(), "empty string incorrectly considered a valid parse");
}
#[test]
fn parse_blank() {
let version = " ";
let parsed = parse_version(version);
assert!(parsed.is_err(), "blank string incorrectly considered a valid parse");
}
#[test]
fn parse_no_minor_patch() {
let version = "1";
let parsed = parse_version(version);
assert!(parsed.is_err(), format!("'{}' incorrectly considered a valid parse", version));
}
#[test]
fn parse_no_patch() {
let version = "1.2";
let parsed = parse_version(version);
assert!(parsed.is_err(), format!("'{}' incorrectly considered a valid parse", version));
}
#[test]
fn parse_empty_pre() {
let version = "1.2.3-";
let parsed = parse_version(version);
assert!(parsed.is_err(), format!("'{}' incorrectly considered a valid parse", version));
}
#[test]
fn parse_letters() {
let version = "a.b.c";
let parsed = parse_version(version);
assert!(parsed.is_err(), format!("'{}' incorrectly considered a valid parse", version));
}
#[test]
fn parse_version_with_letters() {
let version = "1.2.3 a.b.c";
let parsed = parse_version(version);
assert!(parsed.is_err(), format!("'{}' incorrectly considered a valid parse", version));
}
#[test]
fn parse_basic_version() {
let version = "1.2.3";
let parsed = parse_version(version).unwrap();
......@@ -63,6 +126,17 @@ mod tests {
assert_eq!(3, parsed.patch);
}
#[test]
fn parse_trims_input() {
let version = " 1.2.3 ";
let parsed = parse_version(version).unwrap();
assert_eq!(1, parsed.major);
assert_eq!(2, parsed.minor);
assert_eq!(3, parsed.patch);
}
#[test]
fn parse_version_no_major_leading_zeroes() {
let version = "01.0.0";
......@@ -96,6 +170,76 @@ mod tests {
let parsed = parse_version(version).unwrap();
assert_eq!(Some(String::from("pre")), parsed.pre);
let expected_pre = Some(vec![String::from("pre")]);
assert_eq!(expected_pre, parsed.pre);
}
#[test]
fn parse_version_prerelease_alphanumeric() {
let version = "1.2.3-alpha1";
let parsed = parse_version(version).unwrap();
let expected_pre = Some(vec![String::from("alpha1")]);
assert_eq!(expected_pre, parsed.pre);
}
#[test]
fn parse_version_basic_build() {
let version = "1.2.3+build";
let parsed = parse_version(version).unwrap();
let expected_build = Some(vec![String::from("build")]);
assert_eq!(expected_build, parsed.build);
}
#[test]
fn parse_version_build_alphanumeric() {
let version = "1.2.3+build5";
let parsed = parse_version(version).unwrap();
let expected_build = Some(vec![String::from("build5")]);
assert_eq!(expected_build, parsed.build);
}
#[test]
fn parse_version_pre_and_build() {
let version = "1.2.3-alpha1+build5";
let parsed = parse_version(version).unwrap();
let expected_pre = Some(vec![String::from("alpha1")]);
assert_eq!(expected_pre, parsed.pre);
let expected_build = Some(vec![String::from("build5")]);
assert_eq!(expected_build, parsed.build);
}
#[test]
fn parse_version_complex_metadata_01() {
let version = "1.2.3-1.alpha1.9+build5.7.3aedf ";
let parsed = parse_version(version).unwrap();
let expected_pre = Some(vec![String::from("1.alpha1.9")]);
assert_eq!(expected_pre, parsed.pre);
let expected_build = Some(vec![String::from("build5.7.3aedf")]);
assert_eq!(expected_build, parsed.build);
}
#[test]
fn parse_version_complex_metadata_02() {
let version = "0.4.0-beta.1+0851523";
let parsed = parse_version(version).unwrap();
let expected_pre = Some(vec![String::from("beta.1")]);
assert_eq!(expected_pre, parsed.pre);
let expected_build = Some(vec![String::from("0851523")]);
assert_eq!(expected_build, parsed.build);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment