mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Update Math interval
This commit is contained in:
parent
1c909ae752
commit
00781c215a
@ -19,9 +19,8 @@ import kotlin.math.min
|
|||||||
internal object SemVersionInternal {
|
internal object SemVersionInternal {
|
||||||
private val directVersion = """^[0-9]+(\.[0-9]+)+(|[\-+].+)$""".toRegex()
|
private val directVersion = """^[0-9]+(\.[0-9]+)+(|[\-+].+)$""".toRegex()
|
||||||
private val versionSelect = """^[0-9]+(\.[0-9]+)*\.x$""".toRegex()
|
private val versionSelect = """^[0-9]+(\.[0-9]+)*\.x$""".toRegex()
|
||||||
private val versionRange = """([0-9]+(\.[0-9]+)+(|[\-+].+))\s*\-\s*([0-9]+(\.[0-9]+)+(|[\-+].+))""".toRegex()
|
|
||||||
private val versionMathRange =
|
private val versionMathRange =
|
||||||
"""\[([0-9]+(\.[0-9]+)+(|[\-+].+))\s*\,\s*([0-9]+(\.[0-9]+)+(|[\-+].+))\]""".toRegex()
|
"""([\[\(])([0-9]+(\.[0-9]+)+(|[\-+].+))\s*\,\s*([0-9]+(\.[0-9]+)+(|[\-+].+))([\]\)])""".toRegex()
|
||||||
private val versionRule = """^((\>\=)|(\<\=)|(\=)|(\>)|(\<))\s*([0-9]+(\.[0-9]+)+(|[\-+].+))$""".toRegex()
|
private val versionRule = """^((\>\=)|(\<\=)|(\=)|(\>)|(\<))\s*([0-9]+(\.[0-9]+)+(|[\-+].+))$""".toRegex()
|
||||||
|
|
||||||
private val SEM_VERSION_REGEX =
|
private val SEM_VERSION_REGEX =
|
||||||
@ -95,17 +94,35 @@ internal object SemVersionInternal {
|
|||||||
override fun test(version: SemVersion): Boolean = regex.matches(version.toString())
|
override fun test(version: SemVersion): Boolean = regex.matches(version.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(versionRange.matchEntire(trimmed) ?: versionMathRange.matchEntire(trimmed))?.let { range ->
|
versionMathRange.matchEntire(trimmed)?.let { range ->
|
||||||
var start = SemVersion.invoke(range.groupValues[1])
|
// 1 mode
|
||||||
var end = SemVersion.invoke(range.groupValues[4])
|
// 2 first
|
||||||
|
// 5 sec
|
||||||
|
// 8 type
|
||||||
|
var typeStart = range.groupValues[1][0]
|
||||||
|
var typeEnd = range.groupValues[8][0]
|
||||||
|
var start = SemVersion.invoke(range.groupValues[2])
|
||||||
|
var end = SemVersion.invoke(range.groupValues[5])
|
||||||
if (start > end) {
|
if (start > end) {
|
||||||
val c = end
|
val c = end
|
||||||
end = start
|
end = start
|
||||||
start = c
|
start = c
|
||||||
|
val x = typeEnd
|
||||||
|
typeEnd = typeStart
|
||||||
|
typeStart = x
|
||||||
|
}
|
||||||
|
val a: (SemVersion) -> Boolean = when (typeStart) {
|
||||||
|
'[', ']' -> ({ start <= it })
|
||||||
|
'(', ')' -> ({ start < it })
|
||||||
|
else -> throw AssertionError()
|
||||||
|
}
|
||||||
|
val b: (SemVersion) -> Boolean = when (typeEnd) {
|
||||||
|
'[', ']' -> ({ it <= end })
|
||||||
|
'(', ')' -> ({ it < end })
|
||||||
|
else -> throw AssertionError()
|
||||||
}
|
}
|
||||||
val compareRange = start..end
|
|
||||||
return object : SemVersion.Requirement {
|
return object : SemVersion.Requirement {
|
||||||
override fun test(version: SemVersion): Boolean = version in compareRange
|
override fun test(version: SemVersion): Boolean = a(version) && b(version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
versionRule.matchEntire(trimmed)?.let { result ->
|
versionRule.matchEntire(trimmed)?.let { result ->
|
||||||
|
@ -72,14 +72,17 @@ internal class TestSemVersion {
|
|||||||
.assertFalse("2.1")
|
.assertFalse("2.1")
|
||||||
.assert("1.2.5").assert("1.2.0").assertFalse("1.2")
|
.assert("1.2.5").assert("1.2.0").assertFalse("1.2")
|
||||||
.assertFalse("1.0.0")
|
.assertFalse("1.0.0")
|
||||||
SemVersion.parseRangeRequirement("1.0.0 - 114.514.1919")
|
|
||||||
.assert("1.0.0")
|
|
||||||
.assert("114.514").assert("114.514.1919")
|
|
||||||
.assertFalse("0.0.1")
|
|
||||||
.assertFalse("4444.4444")
|
|
||||||
SemVersion.parseRangeRequirement("[1.0.0, 19190.0]")
|
SemVersion.parseRangeRequirement("[1.0.0, 19190.0]")
|
||||||
.assert("1.0.0").assertFalse("0.1.0")
|
.assert("1.0.0").assertFalse("0.1.0")
|
||||||
.assert("19190.0").assertFalse("19198.10")
|
.assert("19190.0").assertFalse("19198.10")
|
||||||
|
SemVersion.parseRangeRequirement("[1.0.0, 2.0.0)")
|
||||||
|
.assert("1.0.0").assert("1.2.3").assertFalse("2.0.0")
|
||||||
|
SemVersion.parseRangeRequirement("(2.0.0, 1.0.0]")
|
||||||
|
.assert("1.0.0").assert("1.2.3").assertFalse("2.0.0")
|
||||||
|
SemVersion.parseRangeRequirement("(2.0.0, 1.0.0)")
|
||||||
|
.assertFalse("1.0.0").assert("1.2.3").assertFalse("2.0.0")
|
||||||
|
SemVersion.parseRangeRequirement("(1.0.0, 2.0.0)")
|
||||||
|
.assertFalse("1.0.0").assert("1.2.3").assertFalse("2.0.0")
|
||||||
SemVersion.parseRangeRequirement(" >= 1.0.0")
|
SemVersion.parseRangeRequirement(" >= 1.0.0")
|
||||||
.assert("1.0.0")
|
.assert("1.0.0")
|
||||||
.assert("114.514.1919")
|
.assert("114.514.1919")
|
||||||
@ -103,6 +106,7 @@ internal class TestSemVersion {
|
|||||||
assertInvalid("{")
|
assertInvalid("{")
|
||||||
assertInvalid("}")
|
assertInvalid("}")
|
||||||
assertInvalid("")
|
assertInvalid("")
|
||||||
|
assertInvalid("1.2.3 - 3.2.1")
|
||||||
assertInvalid("1.5.78 &&")
|
assertInvalid("1.5.78 &&")
|
||||||
assertInvalid("|| 1.0.0")
|
assertInvalid("|| 1.0.0")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user