-
Notifications
You must be signed in to change notification settings - Fork 6
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
Regex #30
Regex #30
Conversation
Resolves #19 |
else 0 | ||
|
||
private fun comparePreReleases(preRelease: String, other: String): Int { | ||
val qualifiers: Map<String, Int> = mapOf( | ||
Pair("alpha", 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi: you can use "alpha" to 1
syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace
preRelease.startsWith('a') -> "alpha" | ||
preRelease.startsWith('b') -> "beta" | ||
preRelease.startsWith('m') -> "milestone" | ||
else -> qualifiers.keys.firstOrNull { preRelease.contains(it) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it safe to look for it like that? I think that both map and its keys may be unordered so it might not be predictable what results will you get.
Also, shouldn't you first look for the qualifiers in map and then check first letters? (I don't know the specs and it will not change anything now, but if it matters and another qualifier with low priority would be added and it would start with a, b or m it could break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as maps retain order of the value so results are predictable
And I need to check one thing about qualifiers and trimming of 0's as I noticed one bug in this logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bugs was fixed. Creating issue about trimming null values
else 0 | ||
|
||
private fun comparePreReleases(preRelease: String, other: String): Int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preRelease
and other
are names suggesting that we are dealing with 2 completely different things, while we are dealing with two preRelease components. More common names like
a, b
preRelease1, preRelease2
this, that
first, second
would make it easier to follow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
} else it | ||
} | ||
|
||
return compareQualifiers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could inline this variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
else -> qualifiers[firstQualifier]!!.compareTo(qualifiers[otherQualifier]!!) | ||
}.let { | ||
if (it == 0) { | ||
val preReleaseNoQualifier = getPreReleaseNoQualifier(firstQualifier!!, preRelease) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it safe to !!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as it wasn't safe
} | ||
} | ||
|
||
private fun getPreReleaseNoQualifier(qualifier: String, preRelease: String): String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the logic of this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed name to better show logic of a function
values[3].toInt(), | ||
values[4], | ||
values[5] | ||
values["majorRegex"]?.value?.toIntOrNull() ?: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to keep group names with suffix "regex" ? To keep it consistent users in the config will have to do it in the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I missed this part. Please remove the regex suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed suffix "Regex" from groups
Changes in regex of Semantic Version, parsing from string and in comparing two prerelease versions. Added tests