Skip to content

Commit

Permalink
Remove kotest dependency from compose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt committed Apr 17, 2024
1 parent 3c69f55 commit 1ba9b1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
1 change: 0 additions & 1 deletion extensions/colormath-ext-jetpack-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ kotlin {
}
commonTest.dependencies {
implementation(kotlin("test"))
implementation(libs.kotest)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ fun Color.toComposeColor(): ComposeColor {
}

return if (s == null) {
val (r, g, b, a) = toSRGB()
val (r, g, b, a) = toSRGB().clamp()
ComposeColor(r, g, b, a)
} else {
val (r, g, b, a) = toArray()
val (r, g, b, a) = clamp().toArray()
ComposeColor(r, g, b, a, s)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import com.github.ajalt.colormath.convertTo
import com.github.ajalt.colormath.extensions.android.composecolor.toColormathColor
import com.github.ajalt.colormath.extensions.android.composecolor.toColormathSRGB
import com.github.ajalt.colormath.extensions.android.composecolor.toComposeColor
import com.github.ajalt.colormath.model.*
import com.github.ajalt.colormath.model.JzAzBz
import com.github.ajalt.colormath.model.LABColorSpaces.LAB50
import com.github.ajalt.colormath.model.Oklab
import com.github.ajalt.colormath.model.RGB
import com.github.ajalt.colormath.model.RGBColorSpaces.ACES
import com.github.ajalt.colormath.model.RGBColorSpaces.ACEScg
import com.github.ajalt.colormath.model.RGBColorSpaces.AdobeRGB
Expand All @@ -18,58 +20,60 @@ import com.github.ajalt.colormath.model.RGBColorSpaces.DisplayP3
import com.github.ajalt.colormath.model.RGBColorSpaces.LinearSRGB
import com.github.ajalt.colormath.model.RGBColorSpaces.ROMM_RGB
import com.github.ajalt.colormath.model.RGBColorSpaces.SRGB
import com.github.ajalt.colormath.model.XYZ
import com.github.ajalt.colormath.model.XYZColorSpaces.XYZ50
import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.data.blocking.forAll
import io.kotest.data.row
import io.kotest.matchers.shouldBe
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.fail

class ComposeColorExtensionsTest {
private val colormathBlue = RGB(0, 0, 2, 1)
private val colormathBlue = RGB(0, 0, 1, 1)

// TODO(kotest): once kotest is released, go back to using it
@Test
fun toColormathColor() {
colormathBlue shouldBe Color.Blue.toColormathColor()
assertEquals(colormathBlue, Color.Blue.toColormathColor())
}

@Test
fun toColormathSRGB() {
colormathBlue shouldBe Color.Blue.toColormathSRGB()
assertEquals(colormathBlue, Color.Blue.toColormathSRGB())
}

@Test
fun toComposeColor() {
Color.Blue shouldBe colormathBlue.toComposeColor()
assertEquals(Color.Blue, colormathBlue.toComposeColor())
}

@Test
fun outOfGamut() = forAll(
row(SRGB),
row(ACES),
row(ACEScg),
row(AdobeRGB),
row(BT2020),
row(BT709),
row(LAB50),
row(XYZ50),
row(DCI_P3),
row(DisplayP3),
row(LinearSRGB),
row(ROMM_RGB),
row(XYZ),
row(Oklab),
row(JzAzBz),
) { space: ColorSpace<*> ->
fun outOfGamut() = listOf<ColorSpace<*>>(
SRGB,
ACES,
ACEScg,
AdobeRGB,
BT2020,
BT709,
LAB50,
XYZ50,
DCI_P3,
DisplayP3,
LinearSRGB,
ROMM_RGB,
XYZ,
Oklab,
JzAzBz,
).forEach { space: ColorSpace<*> ->
val color = RGB(9, 9, 9, 9).convertTo(space)
shouldNotThrow<IllegalArgumentException> { color.clamp().toComposeColor() }
shouldThrow<IllegalArgumentException> { color.toComposeColor() }
}
}

interface F {
operator fun component1(): String
}
// shouldNotThrow

data class G(val a: String, val b: Int) : F
color.clamp().toComposeColor()

// shouldThrow
try {
color.toComposeColor()
} catch (e: IllegalArgumentException) {
// expected
}
}
}

0 comments on commit 1ba9b1b

Please sign in to comment.