Yokan / rebuild
Course 1 8624561

EpubManifestTest.kt

composeApp/src/commonTest/kotlin/eu/friedcutlet/yokan/services/files/EpubManifestTest.kt

test / fixture49 lines
1package eu.friedcutlet.yokan.services.files23import kotlin.test.Test4import kotlin.test.assertEquals56class EpubManifestTest {7    @Test fun asynchronousManifestPreservesSpinePositionsAndRelativePaths() = kotlinx.coroutines.test.runTest {8        val entries = mapOf(9            "META-INF/container.xml" to """<rootfile full-path="OPS/book.opf"/>""",10            "OPS/book.opf" to """<manifest><item id="one" href="Text/a%20b.xhtml"/></manifest><spine><itemref idref="missing"/><itemref idref="one"/></spine>""",11            "OPS/Text/a b.xhtml" to "<html><p>Untitled</p></html>",12        )13        val reads = mutableListOf<String>()14        val actual = readEpubManifestAsync { path -> reads += path; kotlinx.coroutines.yield(); entries[path]?.encodeToByteArray() }15        assertEquals(listOf(LocalEpubChapter("Chapter 2", "OPS/Text/a b.xhtml")), actual)16        assertEquals(readEpubManifest { entries[it]?.encodeToByteArray() }, actual)17        assertEquals(listOf("META-INF/container.xml", "OPS/book.opf", "OPS/Text/a b.xhtml"), reads)18    }19    @Test20    fun readsSelfClosingAndExplicitlyClosedItemsWithNormalisedRelativePaths() {21        val entries = mapOf(22            "META-INF/container.xml" to """<container><rootfiles><rootfile full-path="OEBPS/content.opf"/></rootfiles></container>""",23            "OEBPS/content.opf" to """24                <package>25                  <manifest>26                    <item id="one" href="Text/ch1.xhtml" media-type="application/xhtml+xml"/>27                    <item id="two"28                          href="./Text/../Text/chapter%20two.xhtml"29                          media-type="application/xhtml+xml"></item>30                    <item id="missing" href="Text/missing.xhtml"/>31                  </manifest>32                  <spine><itemref idref="one"/><itemref idref="missing"/><itemref idref="two"/></spine>33                </package>34            """.trimIndent(),35            "OEBPS/Text/ch1.xhtml" to "<html><head><title>Opening <b>Night</b></title></head></html>",36            "OEBPS/Text/chapter two.xhtml" to "<html><body>untitled</body></html>",37        )3839        val chapters = readEpubManifest { path -> entries[path]?.encodeToByteArray() }4041        assertEquals(42            listOf(43                LocalEpubChapter(title = "Opening Night", href = "OEBPS/Text/ch1.xhtml"),44                LocalEpubChapter(title = "Chapter 3", href = "OEBPS/Text/chapter two.xhtml"),45            ),46            chapters,47        )48    }49}50

Search chapters, reference and source filenames.