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

Handle try catch in Evaluation #20

Closed
wants to merge 4 commits into from
Closed
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
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
implementation("com.squareup.okhttp3:okhttp:4.11.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.yaml:snakeyaml:2.2")
}

// Apply a specific Java toolchain to ease working on different environments.
Expand All @@ -83,3 +84,15 @@ tasks.named<Test>("test") {
showStandardStreams = true
}
}

tasks.register<JavaExec>("run-test") {
classpath = sourceSets.main.get().runtimeClasspath
mainClass = "com.featurevisor.cli.TestExecuter"

if (project.hasProperty("args")) {
val argsList = project.property("args") as String
val argsArray = argsList.split("\\s+".toRegex()).toTypedArray()
args(*argsArray)
}
}

34 changes: 17 additions & 17 deletions src/main/kotlin/com/featurevisor/sdk/Conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,45 @@ object Conditions {

fun conditionIsMatched(condition: Plain, context: Context): Boolean {
val (attributeKey, operator, conditionValue) = condition
val attributeValue = context.getOrDefault(attributeKey, null) ?: return false
val attributeValue = context.getOrDefault(attributeKey, null)

return when {
attributeValue is AttributeValue.StringValue && conditionValue is ConditionValue.StringValue -> {
when (operator) {
EQUALS -> attributeValue.value == conditionValue.value
NOT_EQUALS -> attributeValue.value != conditionValue.value
CONTAINS -> attributeValue.value.contains(conditionValue.value)
NOT_CONTAINS -> attributeValue.value.contains(conditionValue.value).not()
STARTS_WITH -> attributeValue.value.startsWith(conditionValue.value)
ENDS_WITH -> attributeValue.value.endsWith(conditionValue.value)
CONTAINS -> attributeValue.value?.contains(conditionValue.value.orEmpty()) ?: false
NOT_CONTAINS -> attributeValue.value?.contains(conditionValue.value.orEmpty())?.not() ?: false
STARTS_WITH -> attributeValue.value?.startsWith(conditionValue.value.orEmpty()) ?: false
ENDS_WITH -> attributeValue.value?.endsWith(conditionValue.value.orEmpty()) ?: false
SEMVER_EQUALS -> compareVersions(
attributeValue.value,
conditionValue.value,
attributeValue.value.orEmpty(),
conditionValue.value.orEmpty(),
) == 0

SEMVER_NOT_EQUALS -> compareVersions(
attributeValue.value,
conditionValue.value,
attributeValue.value.orEmpty(),
conditionValue.value.orEmpty(),
) != 0

SEMVER_GREATER_THAN -> compareVersions(
attributeValue.value,
conditionValue.value
attributeValue.value.orEmpty(),
conditionValue.value.orEmpty()
) == 1

SEMVER_GREATER_THAN_OR_EQUALS -> compareVersions(
attributeValue.value,
conditionValue.value
attributeValue.value.orEmpty(),
conditionValue.value.orEmpty()
) >= 0

SEMVER_LESS_THAN -> compareVersions(
attributeValue.value,
conditionValue.value
attributeValue.value.orEmpty(),
conditionValue.value.orEmpty()
) == -1

SEMVER_LESS_THAN_OR_EQUALS -> compareVersions(
attributeValue.value,
conditionValue.value
attributeValue.value.orEmpty(),
conditionValue.value.orEmpty()
) <= 0

else -> false
Expand Down
Loading
Loading