Skip to content

Commit

Permalink
also match version string which are not quite ok
Browse files Browse the repository at this point in the history
  • Loading branch information
ubamrein committed Jun 24, 2020
1 parent 8fde064 commit 8c07b3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Version implements Comparable<Version> {
private String preReleaseString = "";
private String metaInfo = "";

private final Pattern semVerPattern = Pattern.compile("^(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)\\.(?<patch>0|[1-9]\\d*)(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
private final Pattern semVerPattern = Pattern.compile("(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)\\.(?<patch>0|[1-9]\\d*)(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");

public Version() {
}
Expand All @@ -22,7 +22,7 @@ public Version(String versionString) {
}

var matches = semVerPattern.matcher(versionString.trim());
if(matches.matches()) {
if(matches.find()) {
this.major = Integer.parseInt(matches.group("major"));
this.minor = Integer.parseInt(matches.group("minor"));
this.patch = Integer.parseInt(matches.group("patch"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,35 @@ public void testSecurityHeaders() throws Exception {
@Test
public void testForUpdateNote() throws Exception {
MockHttpServletResponse result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.0").param("buildnr", "ios-2020.0145asdfa34"))
get("/v1/config").param("osversion", "ios12").param("appversion", "ios-1.0.0").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.1").param("buildnr", "ios-2020.0145asdfa34"))
get("/v1/config").param("osversion", "ios12").param("appversion", "android-1.0.1").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.2").param("buildnr", "ios-2020.0145asdfa34"))
get("/v1/config").param("osversion", "ios12").param("appversion", "ios-1.0.2").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0").param("buildnr", "ios-2020.0145asdfa34"))
get("/v1/config").param("osversion", "ios12").param("appversion", "android-1.0").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.3").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.4").param("buildnr", "ios-2020.0145asdfa34"))
get("/v1/config").param("osversion", "ios12").param("appversion", "android-1.0.4").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNormalUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.5").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNoUpdate(result);
result = mockMvc.perform(
get("/v1/config").param("osversion", "ios12").param("appversion", "1.0.6").param("buildnr", "ios-2020.0145asdfa34"))
get("/v1/config").param("osversion", "ios12").param("appversion", "ios-1.0.6").param("buildnr", "ios-2020.0145asdfa34"))
.andExpect(status().is2xxSuccessful()).andReturn().getResponse();
assertTestNoUpdate(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class VersionTest {
@Test
public void testVersionFromString() throws Exception {
var cases = List.of(new Version("0.1.0"),new Version("0.1.1"),new Version("0.2.0"),new Version("1.0.0-prerelease"),new Version("1.0.0"),new Version("1.0.1+ios"));
var cases = List.of(new Version("ios-0.1.0"),new Version("android-0.1.1"),new Version("0.2.0"),new Version("1.0.0-prerelease"),new Version("1.0.0"),new Version("1.0.1+ios"));
for(int i =0; i < cases.size(); i++) {
var currentVersion = cases.get(i);
assertTrue(currentVersion.isSameVersionAs(currentVersion));
Expand All @@ -27,11 +27,11 @@ public void testVersionFromString() throws Exception {
var sameIosVersion = new Version("1.0.0+ios");
assertTrue( metaInfoVersion.equals(sameIosVersion));
}
@Test
public void testInvalidVersion() throws Exception {
var invalid = new Version("ios-1.0.0");
assertFalse(invalid.isValid());
}
// @Test
// public void testInvalidVersion() throws Exception {
// var invalid = new Version("ios-1.0.0");
// assertFalse(invalid.isValid());
// }
@Test
public void testVersionFromExplicit() throws Exception {
var cases = List.of(new Version(0,1,0),new Version(0,1,1),new Version(0,2,0),new Version(1,0,0,"prerelease", ""),new Version(1,0,0),new Version(1,0,1,"", "ios"));
Expand Down

0 comments on commit 8c07b3e

Please sign in to comment.