Use strict version

This commit is contained in:
Him188 2020-09-12 23:00:47 +08:00
parent b173b9ad30
commit 712ecb5a80

View File

@ -7,26 +7,28 @@ public sealed class VersionRequirement {
public abstract operator fun contains(version: Semver): Boolean public abstract operator fun contains(version: Semver): Boolean
public fun contains(version: String): Boolean = contains(Semver(version, Semver.SemverType.LOOSE)) public fun contains(version: String): Boolean = contains(Semver(version, Semver.SemverType.LOOSE))
public data class Exact( public class Exact(
val version: Semver, version: Semver,
) : VersionRequirement() { ) : VersionRequirement() {
public val version: Semver = version.toStrict()
public constructor(version: String) : this(Semver(version, Semver.SemverType.LOOSE)) public constructor(version: String) : this(Semver(version, Semver.SemverType.LOOSE))
override fun contains(version: Semver): Boolean = this.version.isEqualTo(version) override fun contains(version: Semver): Boolean = this.version.isEquivalentTo(version.toStrict())
} }
public data class MatchesNpmPattern( public data class MatchesNpmPattern(
val pattern: String, val pattern: String,
) : VersionRequirement() { ) : VersionRequirement() {
private val requirement = Requirement.buildNPM(pattern) private val requirement = Requirement.buildNPM(pattern)
override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version) override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version.toStrict())
} }
public data class MatchesIvyPattern( public data class MatchesIvyPattern(
val pattern: String, val pattern: String,
) : VersionRequirement() { ) : VersionRequirement() {
private val requirement = Requirement.buildIvy(pattern) private val requirement = Requirement.buildIvy(pattern)
override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version) override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version.toStrict())
} }
@ -34,17 +36,21 @@ public sealed class VersionRequirement {
val pattern: String, val pattern: String,
) : VersionRequirement() { ) : VersionRequirement() {
private val requirement = Requirement.buildCocoapods(pattern) private val requirement = Requirement.buildCocoapods(pattern)
override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version) override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version.toStrict())
} }
public abstract class Custom : VersionRequirement() public abstract class Custom : VersionRequirement()
public data class InRange( @Suppress("MemberVisibilityCanBePrivate")
val begin: Semver, public class InRange(
val beginInclusive: Boolean, begin: Semver,
val end: Semver, public val beginInclusive: Boolean,
val endInclusive: Boolean, end: Semver,
public val endInclusive: Boolean,
) : VersionRequirement() { ) : VersionRequirement() {
public val end: Semver = end.toStrict()
public val begin: Semver = begin.toStrict()
public constructor( public constructor(
begin: String, begin: String,
beginInclusive: Boolean, beginInclusive: Boolean,
@ -70,14 +76,25 @@ public sealed class VersionRequirement {
) : this(begin, beginInclusive, Semver(end, Semver.SemverType.LOOSE), endInclusive) ) : this(begin, beginInclusive, Semver(end, Semver.SemverType.LOOSE), endInclusive)
override fun contains(version: Semver): Boolean { override fun contains(version: Semver): Boolean {
val strict = version.toStrict()
return if (beginInclusive) { return if (beginInclusive) {
version.isGreaterThanOrEqualTo(begin) strict.isGreaterThanOrEqualTo(begin)
} else { } else {
version.isGreaterThan(begin) strict.isGreaterThan(begin)
} && if (endInclusive) { } && if (endInclusive) {
version.isLowerThanOrEqualTo(begin) strict.isLowerThanOrEqualTo(end)
} else { } else {
version.isLowerThan(begin) strict.isLowerThan(end)
}
}
override fun toString(): String {
return buildString {
append(if (beginInclusive) "[" else "(")
append(begin)
append(",")
append(end)
append(if (endInclusive) "]" else ")")
} }
} }
} }