summaryrefslogtreecommitdiff
path: root/src/test/java/sevenUnits/utils/SemanticVersionTest.java
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2024-03-24 13:25:22 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2024-03-24 13:25:22 -0500
commited53492243ecad8d975401a97f5b634328ad2c71 (patch)
tree8a744f46320710355a02c9b2c371602ce69aefec /src/test/java/sevenUnits/utils/SemanticVersionTest.java
parentc878761f737c90fc3fa1caedd48e2ee01637108f (diff)
parent91d51c3c49c4c0877483220ac0f12db4efab8f60 (diff)
Release version 0.5.0 (merge into stable)
Diffstat (limited to 'src/test/java/sevenUnits/utils/SemanticVersionTest.java')
-rw-r--r--src/test/java/sevenUnits/utils/SemanticVersionTest.java56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/test/java/sevenUnits/utils/SemanticVersionTest.java b/src/test/java/sevenUnits/utils/SemanticVersionTest.java
index 877b258..1e59ae3 100644
--- a/src/test/java/sevenUnits/utils/SemanticVersionTest.java
+++ b/src/test/java/sevenUnits/utils/SemanticVersionTest.java
@@ -48,20 +48,20 @@ public final class SemanticVersionTest {
"1.0.0 not compatible with 1.0.5");
assertTrue(stableVersion(1, 3, 1).compatibleWith(stableVersion(1, 4, 0)),
"1.3.1 not compatible with 1.4.0");
-
+
// 0.y.z should not be compatible with any other version
assertFalse(stableVersion(0, 4, 0).compatibleWith(stableVersion(0, 4, 1)),
"0.4.0 compatible with 0.4.1 (0.y.z versions should be treated as unstable/incompatbile)");
-
+
// upgrading major version should = incompatible
assertFalse(stableVersion(1, 0, 0).compatibleWith(stableVersion(2, 0, 0)),
"1.0.0 compatible with 2.0.0");
-
+
// dowgrade should = incompatible
assertFalse(stableVersion(1, 1, 0).compatibleWith(stableVersion(1, 0, 0)),
"1.1.0 compatible with 1.0.0");
}
-
+
/**
* Tests {@link SemanticVersionNumber#toString} for complex version numbers
*
@@ -79,7 +79,7 @@ public final class SemanticVersionTest {
.preRelease("x-y-z", "--").build();
assertEquals("1.0.0-x-y-z.--", v3.toString());
}
-
+
/**
* Tests that complex version can be created and their parts read
*
@@ -94,7 +94,7 @@ public final class SemanticVersionTest {
assertEquals(3, v1.patchVersion());
assertEquals(List.of("1", "2", "3"), v1.preReleaseIdentifiers());
assertEquals(List.of(), v1.buildMetadata());
-
+
final SemanticVersionNumber v2 = builder(4, 5, 6).preRelease("abc", 123)
.buildMetadata("2022-02-19").build();
assertEquals(4, v2.majorVersion());
@@ -102,7 +102,7 @@ public final class SemanticVersionTest {
assertEquals(6, v2.patchVersion());
assertEquals(List.of("abc", "123"), v2.preReleaseIdentifiers());
assertEquals(List.of("2022-02-19"), v2.buildMetadata());
-
+
final SemanticVersionNumber v3 = builder(1, 0, 0)
.preRelease("x-y-z", "--").build();
assertEquals(1, v3.majorVersion());
@@ -111,7 +111,7 @@ public final class SemanticVersionTest {
assertEquals(List.of("x-y-z", "--"), v3.preReleaseIdentifiers());
assertEquals(List.of(), v3.buildMetadata());
}
-
+
/**
* Test that semantic version strings can be parsed correctly
*
@@ -132,7 +132,7 @@ public final class SemanticVersionTest {
"1.0.0+abc is treated as invalid");
assertTrue(isValidVersionString("1.0.0-abc+def"),
"1.0.0-abc+def is treated as invalid");
-
+
// test that invalid versions don't match
assertFalse(isValidVersionString("1.0"),
"1.0 is treated as valid (patch should be required)");
@@ -142,7 +142,7 @@ public final class SemanticVersionTest {
"1.0.0- is treated as valid (pre-release must not be empty)");
assertFalse(isValidVersionString("1.0.0+"),
"1.0.0+ is treated as valid (build metadata must not be empty)");
-
+
// test that versions can be parsed
assertEquals(stableVersion(1, 0, 0), fromString("1.0.0"),
"Could not parse 1.0.0");
@@ -152,7 +152,7 @@ public final class SemanticVersionTest {
fromString("1.2.3-abc.56.def+2022abc99"),
"Could not parse 1.2.3-abc.56.def+2022abc99");
}
-
+
/**
* Ensures it is impossible to create invalid version numbers
*/
@@ -168,7 +168,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> stableVersion(-3, 0, 7),
"Negative major version number tolerated by stableVersion");
-
+
// preRelease()
assertThrows(IllegalArgumentException.class,
() -> preRelease(1, 0, -1, "test", 2),
@@ -190,7 +190,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> preRelease(1, 0, 0, "abc+cde", 1),
"Invalid string tolerated by preRelease");
-
+
// builder()
assertThrows(IllegalArgumentException.class, () -> builder(1, 0, -1),
"Negative patch tolerated by builder");
@@ -198,7 +198,7 @@ public final class SemanticVersionTest {
"Negative minor version number tolerated by builder");
assertThrows(IllegalArgumentException.class, () -> builder(-3, 0, 7),
"Negative major version number tolerated by builder");
-
+
final SemanticVersionNumber.Builder testBuilder = builder(1, 2, 3);
// note: builder.buildMetadata(null) doesn't even compile lol
// builder.buildMetadata
@@ -220,7 +220,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> testBuilder.buildMetadata(List.of("")),
"Invalid string tolerated by builder.buildMetadata(List<String>)");
-
+
// builder.preRelease
assertThrows(NullPointerException.class,
() -> testBuilder.preRelease(null, "abc"),
@@ -240,7 +240,7 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> testBuilder.preRelease(List.of("")),
"Invalid string tolerated by builder.preRelease(List<String>)");
-
+
// the overloadings that accept numeric arguments
assertThrows(IllegalArgumentException.class,
() -> testBuilder.preRelease(-1),
@@ -257,12 +257,12 @@ public final class SemanticVersionTest {
assertThrows(IllegalArgumentException.class,
() -> testBuilder.preRelease("#$#c", 1),
"Invalid string tolerated by builder.preRelease(String, int)");
-
+
// ensure all these attempts didn't change the builder
assertEquals(builder(1, 2, 3), testBuilder,
"Attempts at making invalid version number succeeded despite throwing errors");
}
-
+
/**
* Test for {@link SemanticVersionNumber#isStable}
*
@@ -282,7 +282,7 @@ public final class SemanticVersionTest {
.isStable(),
"9.9.99+lots-of-metadata.abc123.2022 should be stable but is not");
}
-
+
/**
* Tests that the versions are ordered by
* {@link SemanticVersionNumber#compareTo} according to official rules. Tests
@@ -311,7 +311,7 @@ public final class SemanticVersionTest {
final SemanticVersionNumber v210 = stableVersion(2, 1, 0);
final SemanticVersionNumber v211 = stableVersion(2, 1, 1);
final SemanticVersionNumber v300 = stableVersion(3, 0, 0);
-
+
// test order of version numbers
assertTrue(v100a.compareTo(v100a1) < 0, "1.0.0-alpha >= 1.0.0-alpha.1");
assertTrue(v100a1.compareTo(v100ab) < 0,
@@ -327,25 +327,25 @@ public final class SemanticVersionTest {
assertTrue(v201.compareTo(v210) < 0, "2.0.1 >= 2.1.0");
assertTrue(v210.compareTo(v211) < 0, "2.1.0 >= 2.1.1");
assertTrue(v211.compareTo(v300) < 0, "2.1.1 >= 3.0.0");
-
+
// test symmetry - assume previous tests passed
assertTrue(v100a1.compareTo(v100a) > 0, "1.0.0-alpha.1 <= 1.0.0-alpha");
assertTrue(v100.compareTo(v100rc1) > 0, "1.0.0 <= 1.0.0-rc.1");
assertTrue(v300.compareTo(v211) > 0, "3.0.0 <= 2.1.1");
-
+
// test transitivity
assertTrue(v100a.compareTo(v100b11) < 0, "1.0.0-alpha >= 1.0.0-beta.11");
assertTrue(v100b.compareTo(v200) < 0, "1.0.0-beta >= 2.0.0");
assertTrue(v100.compareTo(v300) < 0, "1.0.0 >= 3.0.0");
assertTrue(v100a.compareTo(v300) < 0, "1.0.0-alpha >= 3.0.0");
-
+
// test metadata is ignored
assertEquals(0, v100.compareTo(v100plus), "Build metadata not ignored");
// test metadata is NOT ignored by alternative comparator
assertTrue(BUILD_METADATA_COMPARATOR.compare(v100, v100plus) > 0,
"Build metadata ignored by BUILD_METADATA_COMPARATOR");
}
-
+
/**
* Tests that simple stable versions can be created and their parts read
*
@@ -357,13 +357,13 @@ public final class SemanticVersionTest {
assertEquals(1, v100.majorVersion());
assertEquals(0, v100.minorVersion());
assertEquals(0, v100.patchVersion());
-
+
final SemanticVersionNumber v925 = stableVersion(9, 2, 5);
assertEquals(9, v925.majorVersion());
assertEquals(2, v925.minorVersion());
assertEquals(5, v925.patchVersion());
}
-
+
/**
* Tests that {@link SemanticVersionNumber#toString} works for simple version
* numbers
@@ -374,11 +374,11 @@ public final class SemanticVersionTest {
public void testSimpleToString() {
final SemanticVersionNumber v100 = stableVersion(1, 0, 0);
assertEquals("1.0.0", v100.toString());
-
+
final SemanticVersionNumber v845a1 = preRelease(8, 4, 5, "alpha", 1);
assertEquals("8.4.5-alpha.1", v845a1.toString());
}
-
+
/**
* Tests that simple unstable versions can be created and their parts read
*