package eu.friedcutlet.yokan.services.files
import kotlin.test.Test
import kotlin.test.assertEquals
class EpubManifestTest {
@Test fun asynchronousManifestPreservesSpinePositionsAndRelativePaths() = kotlinx.coroutines.test.runTest {
val entries = mapOf(
"META-INF/container.xml" to """""",
"OPS/book.opf" to """ """,
"OPS/Text/a b.xhtml" to "
Untitled
",
)
val reads = mutableListOf()
val actual = readEpubManifestAsync { path -> reads += path; kotlinx.coroutines.yield(); entries[path]?.encodeToByteArray() }
assertEquals(listOf(LocalEpubChapter("Chapter 2", "OPS/Text/a b.xhtml")), actual)
assertEquals(readEpubManifest { entries[it]?.encodeToByteArray() }, actual)
assertEquals(listOf("META-INF/container.xml", "OPS/book.opf", "OPS/Text/a b.xhtml"), reads)
}
@Test
fun readsSelfClosingAndExplicitlyClosedItemsWithNormalisedRelativePaths() {
val entries = mapOf(
"META-INF/container.xml" to """""",
"OEBPS/content.opf" to """
""".trimIndent(),
"OEBPS/Text/ch1.xhtml" to "Opening Night",
"OEBPS/Text/chapter two.xhtml" to "untitled",
)
val chapters = readEpubManifest { path -> entries[path]?.encodeToByteArray() }
assertEquals(
listOf(
LocalEpubChapter(title = "Opening Night", href = "OEBPS/Text/ch1.xhtml"),
LocalEpubChapter(title = "Chapter 3", href = "OEBPS/Text/chapter two.xhtml"),
),
chapters,
)
}
}