Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement non-strict-alternative to valueOf factory method #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/com/github/zafarkhaja/semver/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ public static Version valueOf(String version) {
return VersionParser.parseValidSemVer(version);
}

/**
* Creates a new instance of {@code Version} leniently parsing the version-core only.
*
* @param version the version string to parse
* @return a new instance of the {@code Version} class
*/
public static Version valueOfLenient(String version) {
return new Version(VersionParser.parseVersionCore(version));
}

/**
* Creates a new instance of {@code Version}
* for the specified version numbers.
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/github/zafarkhaja/semver/VersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ public void shouldIgnoreBuildMetadataWhenCheckingForEquality() {
Version v2 = Version.valueOf("2.3.7-beta");
assertTrue(v1.equals(v2));
}

@Test
public void shouldIgnoreMoreThanFourDigitsInLenientVersion() {
Version fourDigitVersion = Version.valueOfLenient("2.3.7.123");
Version semverValidVersion = Version.valueOf("2.3.7");
assertTrue(fourDigitVersion.equals(semverValidVersion));
}

}

public static class HashCodeMethodTest {
Expand Down