mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9acaa7882d
@ -140,8 +140,8 @@ internal object SemVersionInternal {
|
|||||||
|
|
||||||
private fun SemVersion.RangeRequirement.withRule(rule: String): SemVersion.RangeRequirement {
|
private fun SemVersion.RangeRequirement.withRule(rule: String): SemVersion.RangeRequirement {
|
||||||
return object : SemVersion.RangeRequirement {
|
return object : SemVersion.RangeRequirement {
|
||||||
override fun check(version: SemVersion): Boolean {
|
override fun test(version: SemVersion): Boolean {
|
||||||
return this@withRule.check(version)
|
return this@withRule.test(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
@ -161,7 +161,7 @@ internal object SemVersionInternal {
|
|||||||
if (checks.size == 1) return checks[0]
|
if (checks.size == 1) return checks[0]
|
||||||
SemVersion.RangeRequirement {
|
SemVersion.RangeRequirement {
|
||||||
checks.forEach { rule ->
|
checks.forEach { rule ->
|
||||||
if (rule.check(it)) return@RangeRequirement true
|
if (rule.test(it)) return@RangeRequirement true
|
||||||
}
|
}
|
||||||
return@RangeRequirement false
|
return@RangeRequirement false
|
||||||
}.withRule(requirement)
|
}.withRule(requirement)
|
||||||
|
@ -59,7 +59,7 @@ public data class SemVersion internal constructor(
|
|||||||
*/
|
*/
|
||||||
public fun interface RangeRequirement {
|
public fun interface RangeRequirement {
|
||||||
/** 在 [version] 满足此要求时返回 true */
|
/** 在 [version] 满足此要求时返回 true */
|
||||||
public fun check(version: SemVersion): Boolean
|
public fun test(version: SemVersion): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
public object SemVersionAsStringSerializer : KSerializer<SemVersion> by String.serializer().map(
|
public object SemVersionAsStringSerializer : KSerializer<SemVersion> by String.serializer().map(
|
||||||
@ -118,25 +118,25 @@ public data class SemVersion internal constructor(
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun parseRangeRequirement(requirement: String): RangeRequirement = SemVersionInternal.parseRangeRequirement(requirement)
|
public fun parseRangeRequirement(requirement: String): RangeRequirement = SemVersionInternal.parseRangeRequirement(requirement)
|
||||||
|
|
||||||
/** @see [RangeRequirement.check] */
|
/** @see [RangeRequirement.test] */
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun RangeRequirement.check(version: String): Boolean = check(parse(version))
|
public fun RangeRequirement.test(version: String): Boolean = test(parse(version))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当满足 [requirement] 时返回 true, 否则返回 false
|
* 当满足 [requirement] 时返回 true, 否则返回 false
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun SemVersion.satisfies(requirement: RangeRequirement): Boolean = requirement.check(this)
|
public fun SemVersion.satisfies(requirement: RangeRequirement): Boolean = requirement.test(this)
|
||||||
|
|
||||||
/** for Kotlin only */
|
/** for Kotlin only */
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public operator fun RangeRequirement.contains(version: SemVersion): Boolean = check(version)
|
public operator fun RangeRequirement.contains(version: SemVersion): Boolean = test(version)
|
||||||
|
|
||||||
/** for Kotlin only */
|
/** for Kotlin only */
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public operator fun RangeRequirement.contains(version: String): Boolean = check(version)
|
public operator fun RangeRequirement.contains(version: String): Boolean = test(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.util
|
package net.mamoe.mirai.console.util
|
||||||
|
|
||||||
import net.mamoe.mirai.console.util.SemVersion.Companion.check
|
import net.mamoe.mirai.console.util.SemVersion.Companion.test
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
internal class TestSemVersion {
|
internal class TestSemVersion {
|
||||||
@ -44,12 +44,12 @@ internal class TestSemVersion {
|
|||||||
@Test
|
@Test
|
||||||
internal fun testRequirement() {
|
internal fun testRequirement() {
|
||||||
fun SemVersion.RangeRequirement.assert(version: String): SemVersion.RangeRequirement {
|
fun SemVersion.RangeRequirement.assert(version: String): SemVersion.RangeRequirement {
|
||||||
assert(check(version)) { version }
|
assert(test(version)) { version }
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SemVersion.RangeRequirement.assertFalse(version: String): SemVersion.RangeRequirement {
|
fun SemVersion.RangeRequirement.assertFalse(version: String): SemVersion.RangeRequirement {
|
||||||
assert(!check(version)) { version }
|
assert(!test(version)) { version }
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
SemVersion.parseRangeRequirement("1.0")
|
SemVersion.parseRangeRequirement("1.0")
|
||||||
|
Loading…
Reference in New Issue
Block a user