56 lines · 3.1 KB · KotlinRaw
package com.cottondb.developerimport com.cottondb.shell.Groundimport org.json.JSONObjectimport org.junit.Assert.assertEqualsimport org.junit.Testimport java.io.Fileclass DeveloperFlavourTest { 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 desk mat), and its window shows that ground's colour before the first frame. */ @Test fun developer_stands_on_the_desk_mat() { val ground = json("apps/cotton/App/Flavours/developer/flavour.json").getString("ground") assertEquals(Ground.of(ground), DeveloperParts().ground) val window = json("apps/android/app/flavours.json").getJSONObject("developer").getString("windowGround") val colour = Ground.deskMat.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 developer kit, whose memories the fan opens on. */ @Test fun developer_opens_on_its_memories() { val flavour = json("apps/cotton/App/Flavours/developer/flavour.json") assertEquals("developer", flavour.getString("kit")) assertEquals("memories", flavour.getJSONObject("fan").getString("opens")) val tools = json("crates/cotton-core/kits/developer/kit.json").getJSONArray("tools") assert((0 until tools.length()).any { tools.getString(it) == "personal/memories" }) } /** The registry's Android row is the live package and its .dev twin. */ @Test fun the_registry_names_the_developer_packages() { val apps = json("apps/registry.json").getJSONArray("apps") val developer = (0 until apps.length()).map { apps.getJSONObject(it) }.single { it.getString("slug") == "developer" } val android = developer.getJSONObject("android") assertEquals("com.cottondb.developer", android.getString("package")) assertEquals("com.cottondb.developer.dev", android.getString("devPackage")) } /** The desk mat and the faces' paintings are copied into the build (apps/loom/materials.json), each one Loom's catalogue holds. */ @Test fun the_desk_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("developer")) val carried = { name: String -> materials.any { it == name || (it.endsWith("*") && name.startsWith(it.removeSuffix("*"))) } } listOf("developer-mat", "face-art-computer", "face-art-laptop", "face-art-mac-mini", "face-art-pen", "tool-memory", "tool-code").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" } } }}