mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix SemVersion.Requirement
This commit is contained in:
parent
0b23d3a46f
commit
3b27a26b0a
@ -94,16 +94,13 @@ internal constructor(
|
|||||||
*/
|
*/
|
||||||
val rule: String,
|
val rule: String,
|
||||||
) {
|
) {
|
||||||
init {
|
|
||||||
kotlin.runCatching {
|
|
||||||
parseRangeRequirement(rule)
|
|
||||||
}.onFailure {
|
|
||||||
throw java.lang.IllegalArgumentException("Syntax error: $rule", it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private val impl = SemVersionInternal.parseRangeRequirement(rule)
|
internal val impl = kotlin.runCatching {
|
||||||
|
SemVersionInternal.parseRangeRequirement(rule)
|
||||||
|
}.getOrElse {
|
||||||
|
throw java.lang.IllegalArgumentException("Syntax error: $rule", it)
|
||||||
|
}
|
||||||
|
|
||||||
/** 在 [version] 满足此要求时返回 true */
|
/** 在 [version] 满足此要求时返回 true */
|
||||||
public fun test(version: SemVersion): Boolean = impl.test(version)
|
public fun test(version: SemVersion): Boolean = impl.test(version)
|
||||||
|
@ -43,6 +43,16 @@ internal class TestSemVersion {
|
|||||||
assert("1.0.0-rc.1".sem() < "1.0.0".sem())
|
assert("1.0.0-rc.1".sem() < "1.0.0".sem())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
internal fun testRequirementCopy() {
|
||||||
|
fun SemVersion.Requirement.check(a: SemVersion.Requirement.() -> SemVersion.Requirement) {
|
||||||
|
assert(a().impl !== this.impl)
|
||||||
|
}
|
||||||
|
SemVersion.parseRangeRequirement("1.0").check { copy() }
|
||||||
|
SemVersion.parseRangeRequirement("1.0").check { copy("2.0") }
|
||||||
|
SemVersion.parseRangeRequirement("1.0").check { copy("1.0") }
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
internal fun testRequirement() {
|
internal fun testRequirement() {
|
||||||
fun SemVersion.Requirement.assert(version: String): SemVersion.Requirement {
|
fun SemVersion.Requirement.assert(version: String): SemVersion.Requirement {
|
||||||
|
Loading…
Reference in New Issue
Block a user