Skip to content

Commit

Permalink
Fix formatting continued
Browse files Browse the repository at this point in the history
  • Loading branch information
uniumuniu committed Oct 6, 2023
1 parent 676bac9 commit 8f6870d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 29 deletions.
5 changes: 2 additions & 3 deletions src/main/kotlin/com/featurevisor/sdk/Conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ object Conditions {
}
}

fun allConditionsAreMatched(condition: Condition, context: Context): Boolean {
return when (condition) {
fun allConditionsAreMatched(condition: Condition, context: Context): Boolean =
when (condition) {
is Plain -> conditionIsMatched(condition, context)

is And -> condition.and.all {
Expand All @@ -123,7 +123,6 @@ object Conditions {
allConditionsAreMatched(it, context)
}.not()
}
}

private fun compareVersions(actual: String, condition: String): Int =
SemVer.parse(actual).compareTo(SemVer.parse(condition))
Expand Down
70 changes: 44 additions & 26 deletions src/test/kotlin/com/featurevisor/sdk/ConditionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@ package com.featurevisor.sdk
import com.featurevisor.types.AttributeValue
import com.featurevisor.types.Condition
import com.featurevisor.types.ConditionValue
import com.featurevisor.types.Operator
import com.featurevisor.types.Operator.AFTER
import com.featurevisor.types.Operator.BEFORE
import com.featurevisor.types.Operator.CONTAINS
import com.featurevisor.types.Operator.ENDS_WITH
import com.featurevisor.types.Operator.EQUALS
import com.featurevisor.types.Operator.GREATER_THAN
import com.featurevisor.types.Operator.GREATER_THAN_OR_EQUAL
import com.featurevisor.types.Operator.IN_ARRAY
import com.featurevisor.types.Operator.LESS_THAN
import com.featurevisor.types.Operator.LESS_THAN_OR_EQUAL
import com.featurevisor.types.Operator.NOT_EQUALS
import com.featurevisor.types.Operator.NOT_IN_ARRAY
import com.featurevisor.types.Operator.SEMVER_EQUALS
import com.featurevisor.types.Operator.SEMVER_GREATER_THAN
import com.featurevisor.types.Operator.SEMVER_GREATER_THAN_OR_EQUAL
import com.featurevisor.types.Operator.SEMVER_LESS_THAN
import com.featurevisor.types.Operator.SEMVER_LESS_THAN_OR_EQUAL
import com.featurevisor.types.Operator.SEMVER_NOT_EQUALS
import com.featurevisor.types.Operator.STARTS_WITH
import io.kotest.matchers.shouldBe
import java.time.LocalDate
import kotlin.test.Test
Expand All @@ -14,7 +32,7 @@ class ConditionsTest {
val condition =
Condition.Plain(
attributeKey = "browser_type",
operator = Operator.EQUALS,
operator = EQUALS,
value = ConditionValue.StringValue("chrome")
)

Expand All @@ -34,7 +52,7 @@ class ConditionsTest {
val condition =
Condition.Plain(
attributeKey = "browser_type",
operator = Operator.NOT_EQUALS,
operator = NOT_EQUALS,
value = ConditionValue.StringValue("chrome")
)

Expand All @@ -54,7 +72,7 @@ class ConditionsTest {
val condition =
Condition.Plain(
attributeKey = "age",
operator = Operator.GREATER_THAN,
operator = GREATER_THAN,
value = ConditionValue.IntValue(18)
)

Expand All @@ -74,7 +92,7 @@ class ConditionsTest {
val condition =
Condition.Plain(
attributeKey = "age",
operator = Operator.LESS_THAN,
operator = LESS_THAN,
value = ConditionValue.IntValue(18)
)

Expand All @@ -94,7 +112,7 @@ class ConditionsTest {
val condition =
Condition.Plain(
attributeKey = "age",
operator = Operator.GREATER_THAN_OR_EQUAL,
operator = GREATER_THAN_OR_EQUAL,
value = ConditionValue.IntValue(18)
)

Expand All @@ -119,7 +137,7 @@ class ConditionsTest {
val condition =
Condition.Plain(
attributeKey = "age",
operator = Operator.LESS_THAN_OR_EQUAL,
operator = LESS_THAN_OR_EQUAL,
value = ConditionValue.IntValue(18)
)

Expand All @@ -143,7 +161,7 @@ class ConditionsTest {
fun `CONTAINS operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "browser_type",
operator = Operator.CONTAINS,
operator = CONTAINS,
value = ConditionValue.StringValue("hro"),
)

Expand All @@ -162,7 +180,7 @@ class ConditionsTest {
fun `NOT_CONTAINS operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "browser_type",
operator = Operator.CONTAINS,
operator = CONTAINS,
value = ConditionValue.StringValue("hro"),
)

Expand All @@ -181,7 +199,7 @@ class ConditionsTest {
fun `STARTS_WITH operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "browser_type",
operator = Operator.STARTS_WITH,
operator = STARTS_WITH,
value = ConditionValue.StringValue("chr"),
)

Expand All @@ -200,7 +218,7 @@ class ConditionsTest {
fun `ENDS_WITH operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "browser_type",
operator = Operator.ENDS_WITH,
operator = ENDS_WITH,
value = ConditionValue.StringValue("ome"),
)

Expand All @@ -219,7 +237,7 @@ class ConditionsTest {
fun `SEMVER_EQUALS operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "version",
operator = Operator.SEMVER_EQUALS,
operator = SEMVER_EQUALS,
value = ConditionValue.StringValue("1.2.3")
)

Expand All @@ -238,7 +256,7 @@ class ConditionsTest {
fun `SEMVER_NOT_EQUALS operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "version",
operator = Operator.SEMVER_NOT_EQUALS,
operator = SEMVER_NOT_EQUALS,
value = ConditionValue.StringValue("1.2.3")
)

Expand All @@ -257,7 +275,7 @@ class ConditionsTest {
fun `SEMVER_GREATER_THAN operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "version",
operator = Operator.SEMVER_GREATER_THAN,
operator = SEMVER_GREATER_THAN,
value = ConditionValue.StringValue("1.2.3")
)

Expand All @@ -281,7 +299,7 @@ class ConditionsTest {
fun `SEMVER_GREATER_THAN_OR_EQUAL operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "version",
operator = Operator.SEMVER_GREATER_THAN_OR_EQUAL,
operator = SEMVER_GREATER_THAN_OR_EQUAL,
value = ConditionValue.StringValue("1.2.3")
)

Expand All @@ -305,7 +323,7 @@ class ConditionsTest {
fun `SEMVER_LESS_THAN operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "version",
operator = Operator.SEMVER_LESS_THAN,
operator = SEMVER_LESS_THAN,
value = ConditionValue.StringValue("1.2.3")
)

Expand All @@ -329,7 +347,7 @@ class ConditionsTest {
fun `SEMVER_LESS_THAN_OR_EQUAL operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "version",
operator = Operator.SEMVER_LESS_THAN_OR_EQUAL,
operator = SEMVER_LESS_THAN_OR_EQUAL,
value = ConditionValue.StringValue("1.2.3")
)

Expand All @@ -353,7 +371,7 @@ class ConditionsTest {
fun `BEFORE operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "date",
operator = Operator.BEFORE,
operator = BEFORE,
value = ConditionValue.DateTimeValue(LocalDate.of(2023, 10, 5)),
)

Expand All @@ -377,7 +395,7 @@ class ConditionsTest {
fun `AFTER operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "date",
operator = Operator.AFTER,
operator = AFTER,
value = ConditionValue.DateTimeValue(LocalDate.of(2023, 10, 5)),
)

Expand All @@ -401,7 +419,7 @@ class ConditionsTest {
fun `IN_ARRAY operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "letter",
operator = Operator.IN_ARRAY,
operator = IN_ARRAY,
value = ConditionValue.ArrayValue(listOf("a", "b", "c")),
)

Expand All @@ -420,7 +438,7 @@ class ConditionsTest {
fun `NOT_IN_ARRAY operator works for strings`() {
val condition = Condition.Plain(
attributeKey = "letter",
operator = Operator.NOT_IN_ARRAY,
operator = NOT_IN_ARRAY,
value = ConditionValue.ArrayValue(listOf("a", "b", "c")),
)

Expand All @@ -439,32 +457,32 @@ class ConditionsTest {
fun `multiple conditions work`() {
val startsWithCondition = Condition.Plain(
attributeKey = "browser_type",
operator = Operator.STARTS_WITH,
operator = STARTS_WITH,
value = ConditionValue.StringValue("chr"),
)

val semVerCondition = Condition.Plain(
attributeKey = "version",
operator = Operator.SEMVER_GREATER_THAN,
operator = SEMVER_GREATER_THAN,
value = ConditionValue.StringValue("1.2.3")
)

val ageCondition =
Condition.Plain(
attributeKey = "age",
operator = Operator.GREATER_THAN,
operator = GREATER_THAN,
value = ConditionValue.IntValue(18)
)

val beforeCondition = Condition.Plain(
attributeKey = "date",
operator = Operator.BEFORE,
operator = BEFORE,
value = ConditionValue.DateTimeValue(LocalDate.of(2023, 10, 5)),
)

val inArrayCondition = Condition.Plain(
attributeKey = "letter",
operator = Operator.IN_ARRAY,
operator = IN_ARRAY,
value = ConditionValue.ArrayValue(listOf("a", "b", "c")),
)

Expand Down

0 comments on commit 8f6870d

Please sign in to comment.