Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore prerelease in getSupportedEntries #12

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package it.vercruysse.lemmyapi.dto

import io.github.z4kn4fein.semver.Version
import io.github.z4kn4fein.semver.toVersion
import io.github.z4kn4fein.semver.withoutSuffixes
import it.vercruysse.lemmyapi.MINIMUM_API_VERSION
import it.vercruysse.lemmyapi.V0_18_0
import it.vercruysse.lemmyapi.V0_19_0
Expand Down Expand Up @@ -176,21 +177,13 @@ inline fun <reified T> getSupportedEntries(instanceVersion: String): List<T> whe
* @return A list of supported entries
*/
inline fun <reified T> getSupportedEntries(instanceVersion: Version): List<T> where T : Enum<T>, T : VersionTracker {
val ignorePreReleaseVersion = instanceVersion.withoutSuffixes()
return enumValues<T>().filter {
val max = it.maximumVersion
if (max == null) {
instanceVersion >= it.minimumVersion
ignorePreReleaseVersion >= it.minimumVersion
} else {
isBetweenVersions(instanceVersion, it.minimumVersion, max)
isBetweenVersions(ignorePreReleaseVersion, it.minimumVersion, max)
}
}
}

fun main() {
val siteVersion = "0.18.0"

val supportedEntries = getSupportedEntries<RegistrationMode>(siteVersion)
println(supportedEntries)
}

// TODO check order of enums
10 changes: 10 additions & 0 deletions app/src/commonTest/kotlin/utils/UtilTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package utils

import it.vercruysse.lemmyapi.dto.SortType
import it.vercruysse.lemmyapi.dto.getSupportedEntries
import it.vercruysse.lemmyapi.utils.constructBaseUrl
import it.vercruysse.lemmyapi.utils.isBetweenVersions
import kotlin.test.Test
Expand Down Expand Up @@ -34,4 +36,12 @@ class UtilTest {
assertEquals("https://211.80.65.20", constructBaseUrl("211.80.65.20"))
assertEquals("https://211.80.65.20:8888", constructBaseUrl("211.80.65.20:8888"))
}

@Test
fun shouldIgnorePreReleaseTags() {
val supportedEntries = getSupportedEntries<SortType>("0.19.0-rc.1")
assertTrue { supportedEntries.contains(SortType.Scaled) }

assertFalse { getSupportedEntries<SortType>("0.18.5").contains(SortType.Scaled) }
}
}