Skip to content

Commit

Permalink
Add AST iterator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Aug 21, 2024
1 parent e04776d commit 016d1a9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions core/src/test/kotlin/eu/iamgio/quarkdown/MiscTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -64,6 +67,32 @@ class MiscTest {
this,
)
}

// Iterator

val blockQuoteHook =
object : AstIteratorHook {
override fun attach(iterator: ObservableAstIterator) {
iterator.on<BlockQuote> {
assertIs<Paragraph>(it.children.first())
}
}
}

var finished = false

ObservableAstIterator()
.on<Strong> { assertEquals(Text("abc"), it.children.first()) }
.on<Emphasis> { assertEquals(Text("ghi"), it.children.first()) }
.attach(blockQuoteHook)
.on<Code> {
assertEquals("Hello, world!", it.content)
assertEquals("java", it.language)
}
.onFinished { finished = true }
.run(node)

assertTrue(finished)
}

@Test
Expand Down

0 comments on commit 016d1a9

Please sign in to comment.