Cotton code
48 lines · 2.8 KB · KotlinRaw
package com.cottondb.moneyimport com.cottondb.shell.faces.*import com.cottondb.shell.faces.CardPlacesimport com.cottondb.money.faces.GroupLineimport com.cottondb.money.faces.PhrasedFactimport com.cottondb.money.faces.wantsTheWidthimport com.cottondb.specimen.cardimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalseimport org.junit.Assert.assertNullimport org.junit.Assert.assertTrueimport org.junit.Test/** How the document, group and subscription faces read a card the core dealt: synthetic cards only. */class MoneyCardReadingTest {    private val received = cardLines.line("cards", "field.received", mapOf("said" to PhrasedFact.mark))    /** RULE: a phrased fact parts into its line's words and what was said; words the line did not phrase have no label. */    @Test fun aPhrasedFactIsItsLinesWordsAndWhatWasSaid() {        assertEquals("Received" to "18 Oct", PhrasedFact.part("Received 18 Oct", received))        assertEquals("From" to "Invented Power", PhrasedFact.part("From Invented Power", cardLines.line("cards", "field.issuer", mapOf("said" to PhrasedFact.mark))))        assertNull(PhrasedFact.part("18 Oct", received))        assertNull(PhrasedFact.part(received.replace(PhrasedFact.mark, ""), received))    }    /** RULE: a title past 44 letters, or with a word past 11, takes the card's width. */    @Test fun aLongTitleWantsTheWidth() {        assertFalse(wantsTheWidth("Electricity bill"))        assertTrue(wantsTheWidth("Invoice INV-20260914-0042"))        assertTrue(wantsTheWidth("A very long title of many short words to be set wide"))    }    /** RULE: a group's lines are the core's in its order, an empty one left out, a price standing for an amount. */    @Test fun aGroupReadsItsLinesInTheCoresOrder() {        val group = card("""{"slots":{"title":"Invented Asha","net":["₹1,800 between you"],"lines":[{"title":"Dinner","amount":"₹800","date":"Thu 22 Oct"},{},{"title":"Cab","price":"₹400"}],"more":"+1"}}""")        assertEquals(listOf(GroupLine("Dinner", "₹800", "Thu 22 Oct"), GroupLine("Cab", "₹400", null)), GroupLine.of(group))        assertEquals(listOf("₹1,800 between you"), GroupLine.net(group))        assertEquals(emptyList<GroupLine>(), GroupLine.of(card("""{"slots":{"title":"Invented Ravi"}}""")))    }    /** RULE: a place's label is the card's own, else the face's line, else the slot's; none when no line says one. */    @Test fun aLabelIsTheCardsElseTheFacesElseTheSlots() {        assertEquals("Due", CardPlaces.label(card("""{"face":"subscription","slots":{"labels":{"next_charge":"Due"}}}"""), cardLines, "next_charge"))        assertEquals("Next charge", CardPlaces.label(card("""{"face":"subscription","slots":{}}"""), cardLines, "next_charge"))        assertNull(CardPlaces.label(card("""{"face":"subscription","slots":{}}"""), cardLines, "price"))    }}