Merge remote-tracking branch 'origin/master'

This commit is contained in:
Him188 2020-09-20 14:10:03 +08:00
commit 9acaa7882d
3 changed files with 12 additions and 12 deletions

View File

@ -140,8 +140,8 @@ internal object SemVersionInternal {
private fun SemVersion.RangeRequirement.withRule(rule: String): SemVersion.RangeRequirement {
return object : SemVersion.RangeRequirement {
override fun check(version: SemVersion): Boolean {
return this@withRule.check(version)
override fun test(version: SemVersion): Boolean {
return this@withRule.test(version)
}
override fun toString(): String {
@ -161,7 +161,7 @@ internal object SemVersionInternal {
if (checks.size == 1) return checks[0]
SemVersion.RangeRequirement {
checks.forEach { rule ->
if (rule.check(it)) return@RangeRequirement true
if (rule.test(it)) return@RangeRequirement true
}
return@RangeRequirement false
}.withRule(requirement)

View File

@ -59,7 +59,7 @@ public data class SemVersion internal constructor(
*/
public fun interface RangeRequirement {
/** 在 [version] 满足此要求时返回 true */
public fun check(version: SemVersion): Boolean
public fun test(version: SemVersion): Boolean
}
public object SemVersionAsStringSerializer : KSerializer<SemVersion> by String.serializer().map(
@ -118,25 +118,25 @@ public data class SemVersion internal constructor(
@JvmStatic
public fun parseRangeRequirement(requirement: String): RangeRequirement = SemVersionInternal.parseRangeRequirement(requirement)
/** @see [RangeRequirement.check] */
/** @see [RangeRequirement.test] */
@JvmStatic
public fun RangeRequirement.check(version: String): Boolean = check(parse(version))
public fun RangeRequirement.test(version: String): Boolean = test(parse(version))
/**
* 当满足 [requirement] 时返回 true, 否则返回 false
*/
@JvmStatic
public fun SemVersion.satisfies(requirement: RangeRequirement): Boolean = requirement.check(this)
public fun SemVersion.satisfies(requirement: RangeRequirement): Boolean = requirement.test(this)
/** for Kotlin only */
@JvmStatic
@JvmSynthetic
public operator fun RangeRequirement.contains(version: SemVersion): Boolean = check(version)
public operator fun RangeRequirement.contains(version: SemVersion): Boolean = test(version)
/** for Kotlin only */
@JvmStatic
@JvmSynthetic
public operator fun RangeRequirement.contains(version: String): Boolean = check(version)
public operator fun RangeRequirement.contains(version: String): Boolean = test(version)
}
@Transient

View File

@ -14,7 +14,7 @@
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
internal class TestSemVersion {
@ -44,12 +44,12 @@ internal class TestSemVersion {
@Test
internal fun testRequirement() {
fun SemVersion.RangeRequirement.assert(version: String): SemVersion.RangeRequirement {
assert(check(version)) { version }
assert(test(version)) { version }
return this
}
fun SemVersion.RangeRequirement.assertFalse(version: String): SemVersion.RangeRequirement {
assert(!check(version)) { version }
assert(!test(version)) { version }
return this
}
SemVersion.parseRangeRequirement("1.0")