1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
use next_version::{NextVersion, VersionUpdater};
use semver::Version;
#[test]
fn commit_without_semver_prefix_increments_patch_version() {
let commits = ["my change"];
let version = Version::new(1, 2, 3);
assert_eq!(version.next(commits), Version::new(1, 2, 4));
}
#[test]
fn commit_with_fix_semver_prefix_increments_patch_version() {
let commits = ["my change", "fix: serious bug"];
let version = Version::new(1, 2, 3);
assert_eq!(version.next(commits), Version::new(1, 2, 4));
}
#[test]
fn commit_with_feat_semver_prefix_increments_patch_version() {
let commits = ["feat: make coffe"];
let version = Version::new(1, 3, 3);
assert_eq!(version.next(commits), Version::new(1, 4, 0));
}
#[test]
fn commit_with_feat_semver_prefix_increments_patch_version_when_major_is_zero() {
let commits = ["feat: make coffee"];
let version = Version::new(0, 2, 3);
assert_eq!(version.next(commits), Version::new(0, 2, 4));
}
#[test]
fn commit_with_feat_semver_prefix_increments_minor_version_when_major_is_zero() {
let commits = ["feat: make coffee"];
let version = Version::new(0, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_features_always_increment_minor(true)
.with_breaking_always_increment_major(false)
.increment(&version, commits),
Version::new(0, 3, 0)
);
}
#[test]
fn commit_with_breaking_change_increments_major_version() {
let commits = ["feat!: break user"];
let version = Version::new(1, 2, 3);
assert_eq!(version.next(commits), Version::new(2, 0, 0));
}
#[test]
fn commit_with_breaking_change_increments_minor_version_when_major_is_zero() {
let commits = ["feat!: break user"];
let version = Version::new(0, 2, 3);
assert_eq!(version.next(commits), Version::new(0, 3, 0));
}
#[test]
fn commit_with_breaking_change_increments_major_version_when_major_is_zero() {
let commits = ["feat!: break user"];
let version = Version::new(0, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_features_always_increment_minor(false)
.with_breaking_always_increment_major(true)
.increment(&version, commits),
Version::new(1, 0, 0)
);
}
#[test]
fn commit_with_custom_major_increment_regex_increments_major_version() {
let commits = ["major: some changes"];
let version = Version::new(1, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_custom_major_increment_regex("another|major")
.unwrap()
.increment(&version, commits),
Version::new(2, 0, 0)
);
}
#[test]
fn commit_with_custom_minor_increment_regex_increments_minor_version() {
let commits = ["minor: some changes"];
let version = Version::new(1, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_custom_minor_increment_regex("minor")
.unwrap()
.increment(&version, commits),
Version::new(1, 3, 0)
);
}
#[test]
fn commit_with_scope() {
let commits = ["feat(my_scope)!: this is a test commit"];
let version = Version::new(1, 0, 0);
assert_eq!(version.next(commits), Version::new(2, 0, 0));
}
#[test]
fn commit_with_scope_whitespace() {
let commits = ["feat(my scope)!: this is a test commit"];
let version = Version::new(1, 0, 0);
assert_eq!(version.next(commits), Version::new(2, 0, 0));
}
#[test]
fn commit_with_scope_minor() {
let commits = ["feat(my scope): this is a test commit"];
let version = Version::new(1, 0, 0);
assert_eq!(version.next(commits), Version::new(1, 1, 0));
}
|