mirror of
https://github.com/JakeWharton/mosaic.git
synced 2025-11-02 04:36:19 +08:00
Migrate to AssertK (#245)
This commit is contained in:
@ -25,5 +25,4 @@ mordant = "com.github.ajalt.mordant:mordant:2.2.0"
|
||||
codepoints = "de.cketti.unicode:kotlin-codepoints:0.6.1"
|
||||
|
||||
junit4 = "junit:junit:4.13.2"
|
||||
truth = "com.google.truth:truth:1.1.5"
|
||||
truthish = "com.varabyte.truthish:truthish:0.6.5"
|
||||
assertk = "com.willowtreeapps.assertk:assertk:0.27.0"
|
||||
|
||||
@ -20,7 +20,7 @@ dependencies {
|
||||
compileOnly libs.kotlin.gradlePlugin
|
||||
|
||||
testImplementation libs.junit4
|
||||
testImplementation libs.truth
|
||||
testImplementation libs.assertk
|
||||
testImplementation gradleTestKit()
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.jakewharton.mosaic.gradle
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import java.io.File
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.junit.Test
|
||||
|
||||
@ -24,7 +24,7 @@ kotlin {
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation libs.kotlin.test
|
||||
implementation libs.truthish
|
||||
implementation libs.assertk
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.jakewharton.mosaic
|
||||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import com.jakewharton.mosaic.ui.Column
|
||||
import com.jakewharton.mosaic.ui.Row
|
||||
import com.jakewharton.mosaic.ui.Static
|
||||
import com.jakewharton.mosaic.ui.Text
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class AnsiRenderingTest {
|
||||
private val rendering = AnsiRendering()
|
||||
@ -19,13 +20,12 @@ class AnsiRenderingTest {
|
||||
}
|
||||
|
||||
// TODO We should not draw trailing whitespace.
|
||||
assertEquals(
|
||||
assertThat(rendering.render(hello).toString()).isEqualTo(
|
||||
"""
|
||||
|Hello$s
|
||||
|World!
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(hello).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -37,13 +37,12 @@ class AnsiRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(first).toString()).isEqualTo(
|
||||
"""
|
||||
|Hello$s
|
||||
|World!
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(first).toString(),
|
||||
)
|
||||
|
||||
val second = mosaicNodes {
|
||||
@ -55,7 +54,7 @@ class AnsiRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(second).toString()).isEqualTo(
|
||||
"""
|
||||
|$cursorUp${cursorUp}Hel$clearLine
|
||||
|lo $clearLine
|
||||
@ -63,7 +62,6 @@ class AnsiRenderingTest {
|
||||
|ld!
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(second).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -77,7 +75,7 @@ class AnsiRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(first).toString()).isEqualTo(
|
||||
"""
|
||||
|Hel
|
||||
|lo$s
|
||||
@ -85,7 +83,6 @@ class AnsiRenderingTest {
|
||||
|ld!
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(first).toString(),
|
||||
)
|
||||
|
||||
val second = mosaicNodes {
|
||||
@ -95,14 +92,13 @@ class AnsiRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(second).toString()).isEqualTo(
|
||||
"""
|
||||
|$cursorUp$cursorUp$cursorUp${cursorUp}Hello $clearLine
|
||||
|World!$clearLine
|
||||
|$clearLine
|
||||
|$clearLine$cursorUp
|
||||
""".trimMargin(),
|
||||
rendering.render(second).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -114,13 +110,12 @@ class AnsiRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(hello).toString()).isEqualTo(
|
||||
"""
|
||||
|World!
|
||||
|Hello
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(hello).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -132,13 +127,12 @@ class AnsiRenderingTest {
|
||||
Text("Two")
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(first).toString()).isEqualTo(
|
||||
"""
|
||||
|One
|
||||
|Two
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(first).toString(),
|
||||
)
|
||||
|
||||
val second = mosaicNodes {
|
||||
@ -148,13 +142,12 @@ class AnsiRenderingTest {
|
||||
Text("Four")
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(second).toString()).isEqualTo(
|
||||
"""
|
||||
|${cursorUp}Three$clearLine
|
||||
|Four
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(second).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -182,7 +175,7 @@ class AnsiRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(hello).toString()).isEqualTo(
|
||||
"""
|
||||
|One
|
||||
|Two
|
||||
@ -192,7 +185,6 @@ class AnsiRenderingTest {
|
||||
|Sup
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(hello).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -209,14 +201,13 @@ class AnsiRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(hello).toString()).isEqualTo(
|
||||
"""
|
||||
|Static
|
||||
|TopTopTop
|
||||
|LeftLeft$s
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(hello).toString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,19 @@
|
||||
package com.jakewharton.mosaic
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.containsMatch
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isInstanceOf
|
||||
import assertk.assertions.isNotNull
|
||||
import assertk.assertions.message
|
||||
import com.jakewharton.mosaic.layout.drawBehind
|
||||
import com.jakewharton.mosaic.modifier.Modifier
|
||||
import com.jakewharton.mosaic.ui.Layout
|
||||
import com.jakewharton.mosaic.ui.Row
|
||||
import com.jakewharton.mosaic.ui.Static
|
||||
import com.jakewharton.mosaic.ui.Text
|
||||
import com.varabyte.truthish.assertThat
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.TestTimeSource
|
||||
@ -29,10 +33,11 @@ class DebugRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
val t = assertFailsWith<RuntimeException> {
|
||||
assertFailure {
|
||||
rendering.render(nodes)
|
||||
}
|
||||
assertThat(t.message!!)
|
||||
}.isInstanceOf<RuntimeException>()
|
||||
.message()
|
||||
.isNotNull()
|
||||
.containsMatch(
|
||||
"""
|
||||
|Failed
|
||||
@ -44,7 +49,7 @@ class DebugRenderingTest {
|
||||
|
|
||||
|OUTPUT:
|
||||
|(kotlin\.|java\.lang\.)?UnsupportedOperationException:?
|
||||
""".trimMargin(),
|
||||
""".trimMargin().toRegex(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -56,7 +61,7 @@ class DebugRenderingTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(nodes)).isEqualTo(
|
||||
"""
|
||||
|NODES:
|
||||
|Text("Hello") x=0 y=0 w=5 h=1 DrawBehind
|
||||
@ -70,7 +75,6 @@ class DebugRenderingTest {
|
||||
|Hello
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(nodes),
|
||||
)
|
||||
}
|
||||
|
||||
@ -79,7 +83,7 @@ class DebugRenderingTest {
|
||||
Text("Hello")
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
assertThat(rendering.render(hello)).isEqualTo(
|
||||
"""
|
||||
|NODES:
|
||||
|Text("Hello") x=0 y=0 w=5 h=1 DrawBehind
|
||||
@ -88,11 +92,10 @@ class DebugRenderingTest {
|
||||
|Hello
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(hello),
|
||||
)
|
||||
|
||||
timeSource += 100.milliseconds
|
||||
assertEquals(
|
||||
assertThat(rendering.render(hello)).isEqualTo(
|
||||
"""
|
||||
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +100ms
|
||||
|NODES:
|
||||
@ -102,7 +105,6 @@ class DebugRenderingTest {
|
||||
|Hello
|
||||
|
|
||||
""".trimMargin(),
|
||||
rendering.render(hello),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.jakewharton.mosaic
|
||||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import com.jakewharton.mosaic.layout.drawBehind
|
||||
import com.jakewharton.mosaic.modifier.Modifier
|
||||
import com.jakewharton.mosaic.ui.Column
|
||||
@ -7,7 +9,6 @@ import com.jakewharton.mosaic.ui.Layout
|
||||
import com.jakewharton.mosaic.ui.Row
|
||||
import com.jakewharton.mosaic.ui.Text
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class LayoutTest {
|
||||
@Test fun layoutDebugInfo() {
|
||||
@ -28,7 +29,7 @@ class LayoutTest {
|
||||
| Text("Hi!") x=0 y=0 w=0 h=0 DrawBehind
|
||||
| Text("Hey!") x=0 y=0 w=0 h=0 DrawBehind
|
||||
""".trimMargin()
|
||||
assertEquals(expected, node.toString())
|
||||
assertThat(node.toString()).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test fun noMeasureNoDraw() {
|
||||
@ -46,7 +47,7 @@ class LayoutTest {
|
||||
| $s
|
||||
|
|
||||
""".trimMargin()
|
||||
assertEquals(expected, actual)
|
||||
assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test fun noPlacementOverlaps() {
|
||||
@ -67,7 +68,7 @@ class LayoutTest {
|
||||
|ABC
|
||||
|
|
||||
""".trimMargin()
|
||||
assertEquals(expected, actual)
|
||||
assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test fun placementWorks() {
|
||||
@ -91,7 +92,7 @@ class LayoutTest {
|
||||
|A $s
|
||||
|
|
||||
""".trimMargin()
|
||||
assertEquals(expected, actual)
|
||||
assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test fun canvasIsNotClipped() {
|
||||
@ -130,6 +131,6 @@ class LayoutTest {
|
||||
|.....X
|
||||
|
|
||||
""".trimMargin()
|
||||
assertEquals(expected, actual)
|
||||
assertThat(actual).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.jakewharton.mosaic
|
||||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import com.jakewharton.mosaic.ui.Column
|
||||
import com.jakewharton.mosaic.ui.Text
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class MosaicTest {
|
||||
@Test fun render() {
|
||||
@ -14,14 +15,13 @@ class MosaicTest {
|
||||
Text("Three")
|
||||
}
|
||||
}
|
||||
assertEquals(
|
||||
assertThat(actual).isEqualTo(
|
||||
"""
|
||||
|One $s
|
||||
|Two $s
|
||||
|Three
|
||||
|
|
||||
""".trimMargin(),
|
||||
actual,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.jakewharton.mosaic
|
||||
|
||||
import androidx.compose.runtime.Applier
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import com.jakewharton.mosaic.layout.DebugPolicy
|
||||
import com.jakewharton.mosaic.layout.MosaicNode
|
||||
import com.jakewharton.mosaic.ui.NodeFactory
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class NodeApplierTest {
|
||||
private val root = createRootNode()
|
||||
@ -184,7 +185,7 @@ class NodeApplierTest {
|
||||
}
|
||||
|
||||
private fun assertChildren(vararg nodes: MosaicNode) {
|
||||
assertEquals(nodes.toList(), root.children)
|
||||
assertThat(root.children).isEqualTo(nodes.toList())
|
||||
}
|
||||
|
||||
private fun textNode(name: String): MosaicNode {
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
package com.jakewharton.mosaic.text
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.hasSize
|
||||
import assertk.assertions.isEmpty
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isInstanceOf
|
||||
import com.jakewharton.mosaic.text.AnnotatedString.Range
|
||||
import com.jakewharton.mosaic.ui.Color
|
||||
import com.jakewharton.mosaic.ui.TextStyle
|
||||
import com.varabyte.truthish.assertThat
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class AnnotatedStringBuilderTest {
|
||||
|
||||
@ -385,9 +389,9 @@ class AnnotatedStringBuilderTest {
|
||||
}
|
||||
|
||||
@Test fun pop_when_empty_does_not_throw_exception() {
|
||||
assertFailsWith<IllegalStateException> {
|
||||
assertFailure {
|
||||
AnnotatedString.Builder().pop()
|
||||
}
|
||||
}.isInstanceOf<IllegalStateException>()
|
||||
}
|
||||
|
||||
@Test fun pop_in_the_middle() {
|
||||
@ -455,10 +459,10 @@ class AnnotatedStringBuilderTest {
|
||||
with(AnnotatedString.Builder()) {
|
||||
val styleIndex = pushStyle(style)
|
||||
|
||||
assertFailsWith<IllegalStateException> {
|
||||
assertFailure {
|
||||
// should throw exception
|
||||
pop(styleIndex + 1)
|
||||
}
|
||||
}.isInstanceOf<IllegalStateException>()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package com.jakewharton.mosaic.text
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isInstanceOf
|
||||
import assertk.assertions.isSameAs
|
||||
import com.jakewharton.mosaic.text.AnnotatedString.Range
|
||||
import com.jakewharton.mosaic.ui.Color
|
||||
import com.varabyte.truthish.assertThat
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class AnnotatedStringTest {
|
||||
|
||||
@ -200,15 +202,15 @@ class AnnotatedStringTest {
|
||||
}
|
||||
|
||||
@Test fun subSequence_throws_exception_for_start_greater_than_end() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
assertFailure {
|
||||
AnnotatedString("ab").subSequence(1, 0)
|
||||
}
|
||||
}.isInstanceOf<IllegalArgumentException>()
|
||||
}
|
||||
|
||||
@Test fun creating_item_with_start_greater_than_end_throws_exception() {
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
assertFailure {
|
||||
Range(SpanStyle(color = Color.Red), 1, 0)
|
||||
}
|
||||
}.isInstanceOf<IllegalArgumentException>()
|
||||
}
|
||||
|
||||
@Test fun creating_item_with_start_equal_to_end_does_not_throw_exception() {
|
||||
@ -227,7 +229,6 @@ class AnnotatedStringTest {
|
||||
}
|
||||
|
||||
@Test fun toString_returns_the_plain_string() {
|
||||
val text = "abc"
|
||||
assertEquals(text, AnnotatedString(text).toString())
|
||||
assertThat(AnnotatedString("abc").toString()).isEqualTo("abc")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package com.jakewharton.mosaic.text
|
||||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isNull
|
||||
import com.jakewharton.mosaic.ui.Color
|
||||
import com.jakewharton.mosaic.ui.TextStyle
|
||||
import com.varabyte.truthish.assertThat
|
||||
import kotlin.test.Test
|
||||
|
||||
class SpanStyleTest {
|
||||
|
||||
Reference in New Issue
Block a user