diff --git a/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt b/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt index 37fcaa83..1c4b17e4 100644 --- a/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt +++ b/app/src/test/java/com/github/braillesystems/learnbraille/data/entities/ToXmlTest.kt @@ -1,10 +1,38 @@ package com.github.braillesystems.learnbraille.data.entities +import com.github.braillesystems.learnbraille.data.dsl.LessonWithSteps +import com.github.braillesystems.learnbraille.data.dsl.lessons import org.junit.Assert.assertEquals import org.junit.Test import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E +import com.github.braillesystems.learnbraille.res.golubinaIntroLessons +import java.io.File + +internal val testLessons by lessons { + lesson(name = "first lesson") { + +FirstInfo("first title") + } +} + +internal fun toXml(lesson: LessonWithSteps): HtmlText { + return object : XmlAble { + override val xmlTag: String = "lesson" + + override val xmlParams: Map + get() = mapOf("name" to lesson.first.name.replace("\"", "'")) + + override val xmlBody: HtmlText + get() = { + var stepBuilder: HtmlText = "" + for(step in lesson.second.dropLast(1)){ + stepBuilder += (step.first.data.toXml() + "\n") // TODO [...
] -> [

...

] + } + stepBuilder + lesson.second.takeLast(1)[0].first.data.toXml() + }() + }.toXml() +} class ToXmlTest { @Test @@ -21,4 +49,22 @@ class ToXmlTest { assertEquals(expectedXml, stepData.toXml().replace("\n", "")) } } + + @Test + fun lessonToXml() { + println(toXml(testLessons.lessons[0])) + + var xmlText = "" + for(lessons in golubinaIntroLessons.lessons) { + xmlText += (toXml(lessons) + "\n") + } + + val xmlLinesList = xmlText.split("\n") + File("course.xml").printWriter().use { out -> + out.println("") + out.println("") + xmlLinesList.forEach { out.println(it) } + out.println("") + } + } }