Modern Apps git

← Modern-Apps.git

office: tests for char-level full-formatting round-trip + special-content ineligibility

Commit
5d6bc6b001e6b140f6a1abb8e167e5ea1433a35c
Author
Vayun Mathur <[email protected]>
When
2026-07-06 18:45 UTC (5 months ago)
Parents
c9f4e57

Diff

office/src/test/java/com/vayunmathur/office/util/TextDocCodecTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/util/TextDocCodecTest.kt b/office/src/test/java/com/vayunmathur/office/util/TextDocCodecTest.ktindex df13d2ba71..773cd38e0f 100644--- a/office/src/test/java/com/vayunmathur/office/util/TextDocCodecTest.kt+++ b/office/src/test/java/com/vayunmathur/office/util/TextDocCodecTest.kt@@ -18,6 +18,42 @@ class TextDocCodecTest {     private fun paraTexts(doc: OdfDocument.TextDocument): List<String> =         doc.content.mapNotNull { (it as? OdfContentBlock.Paragraph)?.paragraph?.spans?.joinToString("") { s -> s.text } } +    @Test+    fun roundtrip_preserves_full_formatting() {+        val doc = OdfDocument.TextDocument(+            title = "t",+            content = listOf(+                OdfContentBlock.Paragraph(OdfParagraph(+                    spans = listOf(OdfSpan("styled", italic = true, fontFamily = "Times", backgroundColor = 0xFFFFFF00L, color = 0xFF0000FFL)),+                    alignment = androidx.compose.ui.text.style.TextAlign.Center,+                    marginLeft = 24f, textIndent = 12f,+                    style = com.vayunmathur.library.ui.odf.ParagraphStyle.LIST_ITEM,+                    listLevel = 2, listType = com.vayunmathur.library.ui.odf.ListType.NUMBERED, listChecked = true,+                ))+            )+        )+        val p = (TextDocCodec.fromCells(TextDocCodec.toCells(doc), doc).content[0] as OdfContentBlock.Paragraph).paragraph+        assertEquals(androidx.compose.ui.text.style.TextAlign.Center, p.alignment)+        assertEquals(24f, p.marginLeft)+        assertEquals(12f, p.textIndent)+        assertEquals(2, p.listLevel)+        assertEquals(com.vayunmathur.library.ui.odf.ListType.NUMBERED, p.listType)+        assertTrue(p.listChecked)+        val s = p.spans.first()+        assertTrue(s.italic); assertEquals("Times", s.fontFamily)+        assertEquals(0xFFFFFF00L, s.backgroundColor); assertEquals(0xFF0000FFL, s.color)+    }++    @Test+    fun ineligible_when_special_content_present() {+        // A doc with a footnote must NOT be char-level (would drop the footnote) — use line-level.+        val withFootnote = textDoc("body").copy(+            footnotes = listOf(com.vayunmathur.library.ui.odf.OdfFootnote(citation = "1", body = emptyList()))+        )+        assertTrue(!TextDocCodec.isEligible(withFootnote))+        assertTrue(TextDocCodec.isEligible(textDoc("plain")))+    }+     @Test     fun roundtrip_preserves_paragraphs_and_bold() {         val doc = OdfDocument.TextDocument(