From 016d1a9e2f101888fb14cf90ea025d33c22fb082 Mon Sep 17 00:00:00 2001 From: Giorgio Garofalo Date: Wed, 21 Aug 2024 16:44:43 +0200 Subject: [PATCH] Add AST iterator tests --- .../kotlin/eu/iamgio/quarkdown/MiscTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/src/test/kotlin/eu/iamgio/quarkdown/MiscTest.kt b/core/src/test/kotlin/eu/iamgio/quarkdown/MiscTest.kt index cd569686..2d85c1c2 100644 --- a/core/src/test/kotlin/eu/iamgio/quarkdown/MiscTest.kt +++ b/core/src/test/kotlin/eu/iamgio/quarkdown/MiscTest.kt @@ -9,6 +9,8 @@ import eu.iamgio.quarkdown.ast.base.inline.Emphasis import eu.iamgio.quarkdown.ast.base.inline.Strong import eu.iamgio.quarkdown.ast.base.inline.Text import eu.iamgio.quarkdown.ast.id.getId +import eu.iamgio.quarkdown.ast.iterator.AstIteratorHook +import eu.iamgio.quarkdown.ast.iterator.ObservableAstIterator import eu.iamgio.quarkdown.context.MutableContext import eu.iamgio.quarkdown.context.toc.TableOfContents import eu.iamgio.quarkdown.document.locale.JVMLocaleLoader @@ -19,6 +21,7 @@ import eu.iamgio.quarkdown.util.flattenedChildren import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import kotlin.test.Test +import kotlin.test.assertIs import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -64,6 +67,32 @@ class MiscTest { this, ) } + + // Iterator + + val blockQuoteHook = + object : AstIteratorHook { + override fun attach(iterator: ObservableAstIterator) { + iterator.on
{ + assertIs(it.children.first()) + } + } + } + + var finished = false + + ObservableAstIterator() + .on { assertEquals(Text("abc"), it.children.first()) } + .on { assertEquals(Text("ghi"), it.children.first()) } + .attach(blockQuoteHook) + .on { + assertEquals("Hello, world!", it.content) + assertEquals("java", it.language) + } + .onFinished { finished = true } + .run(node) + + assertTrue(finished) } @Test