Cotton code
56 lines · 3.0 KB · KotlinRaw
package com.cottondb.peopleimport com.cottondb.shell.Groundimport org.json.JSONObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.Fileclass PeopleFlavourTest {    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 amethyst desk), and its window shows that ground's colour before the first frame. */    @Test    fun people_stands_on_the_amethyst_desk() {        val ground = json("apps/cotton/App/Flavours/people/flavour.json").getString("ground")        assertEquals(Ground.of(ground), PeopleParts().ground)        val window = json("apps/android/app/flavours.json").getJSONObject("people").getString("windowGround")        val colour = Ground.amethystDesk.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 people kit, whose People the fan opens on. */    @Test    fun people_opens_on_its_people() {        val flavour = json("apps/cotton/App/Flavours/people/flavour.json")        assertEquals("people", flavour.getString("kit"))        assertEquals("people", flavour.getJSONObject("fan").getString("opens"))    }    /** The route the app draws is the one person.create names: if the kit moves it, this fails rather than Plus going blank. */    @Test    fun import_is_the_route_person_create_names() {        val create = json("crates/cotton-core/kits/personal/tables/person.json").getJSONObject("create")        assertEquals(PeopleParts.IMPORT, create.getString("path"))        val parts = PeopleParts()        assertTrue(parts.raise(PeopleParts.IMPORT))        assertTrue(parts.importing)        assertEquals(false, PeopleParts().raise("/people/elsewhere"))    }    /** The desk, the tool tiles and the birthday's art are carried (apps/loom/materials.json), each one Loom's catalogue holds. */    @Test    fun the_desk_and_tiles_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("people"))        val carried = { name: String -> materials.any { it == name || (it.endsWith("*") && name.startsWith(it.removeSuffix("*"))) } }        listOf("people-amethyst", "tool-people", "tool-people-small", "face-art-sprig", "face-art-cake", "rolodex-frame", "person-file-folder", "passport-booklet").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" }        }    }}