Skip to content

Commit

Permalink
Add include tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Jun 27, 2024
1 parent 82eab63 commit 4f0b8be
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 2 deletions.
75 changes: 73 additions & 2 deletions test/src/test/kotlin/eu/iamgio/quarkdown/test/FullPipelineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import eu.iamgio.quarkdown.pipeline.PipelineHooks
import eu.iamgio.quarkdown.pipeline.PipelineOptions
import eu.iamgio.quarkdown.pipeline.error.StrictPipelineErrorHandler
import eu.iamgio.quarkdown.stdlib.Stdlib
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
Expand Down Expand Up @@ -35,7 +36,10 @@ class FullPipelineTest {
val pipeline =
Pipeline(
MutableContext(QuarkdownFlavor),
PipelineOptions(errorHandler = StrictPipelineErrorHandler()),
PipelineOptions(
errorHandler = StrictPipelineErrorHandler(),
workingDirectory = File(DATA_FOLDER),
),
libraries = setOf(Stdlib.library),
renderer = { rendererFactory, context -> rendererFactory.html(context) },
hooks,
Expand Down Expand Up @@ -151,7 +155,7 @@ class FullPipelineTest {
assertEquals("<p><em><strong>result</strong></em>: 11</p>", it)
}

execute(".code\n .filecontent {$DATA_FOLDER/code.txt}") {
execute(".code\n .filecontent {code.txt}") {
assertEquals(
"<pre><code>Line 1${System.lineSeparator()}Line 2${System.lineSeparator()}${System.lineSeparator()}Line 3</code></pre>",
it,
Expand Down Expand Up @@ -486,4 +490,71 @@ class FullPipelineTest {
)
}
}

@Test
fun `include source`() {
execute(
"""
.include {include/include-1.md}
""".trimIndent(),
) {
assertEquals(
"<h1>Title</h1><p>Some <em>text</em>.</p>",
it,
)
}

// Import functions from another source.
execute(
"""
.include {include/include-2.md}
.hello {world}
""".trimIndent(),
) {
assertEquals(
"<p>Hello, world!</p>",
it,
)
}

execute(
"""
# Main
.include {include/include-3.md}
""".trimIndent(),
) {
assertEquals(
"<h1>Main</h1><h2>Included</h2><pre><code>code\ncode</code></pre>",
it,
)
}

// Sharing functions with included files.
execute(
"""
.function {hello}
x:
Hello, .x!
.include {include/include-4.md}
""".trimIndent(),
) {
assertEquals(
"<h3>Hello, world!</h3>",
it,
)
}

// Transitive inclusion of files.
execute(
"""
# Main
.include {include/include-5.md}
""".trimIndent(),
) {
assertEquals(
"<h1>Main</h1><h1>Included</h2><p>Hello, Gio!</p><h3>Hello, world!</h3>",
it,
)
}
}
}
3 changes: 3 additions & 0 deletions test/src/test/resources/data/include/include-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Title

Some *text*.
3 changes: 3 additions & 0 deletions test/src/test/resources/data/include/include-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.function {hello}
x:
Hello, .x!
10 changes: 10 additions & 0 deletions test/src/test/resources/data/include/include-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.function {hello}
x:
Hello, .x!

## Included

```
code
code
```
1 change: 1 addition & 0 deletions test/src/test/resources/data/include/include-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### .hello {world}
9 changes: 9 additions & 0 deletions test/src/test/resources/data/include/include-5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.function {hello}
x:
Hello, .x!

# Included

.hello {Gio}

.include {include/include-4.md}

0 comments on commit 4f0b8be

Please sign in to comment.