-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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") | ||
} |
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() } | ||
val tab by value<Tab> { toBeSpecified() } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also use |
||
val invalidRegions by value { layoutValidator.findInvalidRegions(tab) } | ||
|
||
context("when all regions are single cells") { | ||
override(tab) { tab(3, 3, "ABC DEF GHI") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper method to convert "aa bb" to a |
||
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() | ||
) | ||
} |
There was a problem hiding this comment.
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 eachit
block.