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

Validate panel grid arrangement in layout editor #351

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions src/commonMain/kotlin/baaahs/show/LayoutValidator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package baaahs.show

class LayoutValidator {
fun findInvalidRegions(tab: Tab): Set<String> = TODO("not implemented")
}
63 changes: 63 additions & 0 deletions src/commonTest/kotlin/baaahs/show/LayoutValidatorSpec.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package baaahs.show

import baaahs.describe
import baaahs.gl.override
import baaahs.toBeSpecified
import ch.tutteli.atrium.api.fluent.en_GB.containsExactly
import ch.tutteli.atrium.api.fluent.en_GB.isEmpty
import ch.tutteli.atrium.api.verbs.expect
import org.spekframework.spek2.Spek

object LayoutValidatorSpec : Spek({
describe<LayoutValidator> {
val layoutValidator by value { LayoutValidator() }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This by value thing creates a new instance for every spec — for each it block.

val tab by value<Tab> { toBeSpecified() }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also useoverride to change the value in nested contexts, see below.

val invalidRegions by value { layoutValidator.findInvalidRegions(tab) }

context("when all regions are single cells") {
override(tab) { tab(3, 3, "ABC DEF GHI") }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it behave as though line 14 had this value the whole time, within this context.

it("should return no invalid regions") {
expect(invalidRegions).isEmpty()
}
}

context("when all regions are rectangular") {
override(tab) { tab(3, 3, "AAB AAC DDC") }
it("should return no invalid regions") {
expect(invalidRegions).isEmpty()
}
}

context("when a region isn't rectangular") {
override(tab) { tab(3, 3, "AAB AEC DDC") }
it("should return the non-rectangular region") {
expect(invalidRegions).containsExactly("A")
}
}

context("when multiple regions aren't rectangular") {
override(tab) { tab(3, 3, "AAB ADC DDC") }
it("should return the non-rectangular region") {
expect(invalidRegions).containsExactly("A", "D")
}
}

context("when a region is non-contiguous") {
override(tab) { tab(3, 3, "AAB AAC DDA") }
it("should return the non-contiguous region") {
expect(invalidRegions).containsExactly("A")
}
}
}
})

fun tab(columns: Int, rows: Int, areas: String): Tab {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helper method to convert "aa bb" to a Tab with ["a", "a", "b", "b"].

val areaNames = areas.filter { it != ' ' }.map { it.toString() }
if (areaNames.size != columns * rows) error("should be ${columns * rows} areas")
return Tab(
"Main",
Array(columns) { "1fr" }.toList(),
Array(rows) { "1fr" }.toList(),
areaNames.toList()
)
}