45 lines · 2.4 KB · KotlinRaw
package com.cottondb.journalimport com.cottondb.shell.Groundimport org.json.JSONObjectimport org.junit.Assert.assertEqualsimport org.junit.Testimport java.io.Fileclass JournalFlavourTest { private val repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile } private fun json(path: String) = JSONObject(File(repo, path).readText()) /** The app stands on the ground its iOS flavour.json names (the bedside table), and its window shows that ground's colour before the first frame. */ @Test fun journal_stands_on_the_bedside_table() { val ground = json("apps/cotton/App/Flavours/journal/flavour.json").getString("ground") assertEquals(Ground.of(ground), JournalParts().ground) val window = json("apps/android/app/flavours.json").getJSONObject("journal").getString("windowGround") val colour = Ground.bedsideTable.colour fun hex(channel: Float) = "%02X".format((channel * 255).toInt()) assertEquals("#" + hex(colour.red) + hex(colour.green) + hex(colour.blue), window) } /** The flavour's kit is the journal kit, whose journal the fan opens on. */ @Test fun journal_opens_on_its_journal() { val flavour = json("apps/cotton/App/Flavours/journal/flavour.json") assertEquals("journal", flavour.getString("kit")) assertEquals("journal", flavour.getJSONObject("fan").getString("opens")) } /** The painted layers the diary lays are copied into the build (apps/loom/materials.json), each one Loom's catalogue holds. */ @Test fun the_diary_layers_are_carried() { val lists = json("apps/loom/materials.json") fun names(a: org.json.JSONArray) = (0 until a.length()).map { a.getString(it) } val materials = names(lists.getJSONArray("everyApp")) + names(lists.getJSONObject("apps").getJSONArray("journal")) val carried = { name: String -> materials.any { it == name || (it.endsWith("*") && name.startsWith(it.removeSuffix("*"))) } } val seals = listOf("great", "good", "okay", "low", "awful", "bare").map { "diary-seal-$it" } (listOf("journal-bedside", "diary-book", "diary-ribbon-in", "diary-ribbon-out") + seals).forEach { name -> assert(carried(name)) { "$name is not carried" } assert(File(repo, "apps/loom/Sources/CottonPaper/Media.xcassets/$name.imageset").isDirectory) { "$name is no Loom painting" } } }}