From f31231228296f433da304da3ab228c1957cc7ed5 Mon Sep 17 00:00:00 2001 From: Giorgio Garofalo Date: Wed, 26 Jun 2024 17:22:39 +0200 Subject: [PATCH] Use relative paths in DataTest --- .../eu/iamgio/quarkdown/stdlib/DataTest.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/stdlib/src/test/kotlin/eu/iamgio/quarkdown/stdlib/DataTest.kt b/stdlib/src/test/kotlin/eu/iamgio/quarkdown/stdlib/DataTest.kt index 2fefb562..2f50372c 100644 --- a/stdlib/src/test/kotlin/eu/iamgio/quarkdown/stdlib/DataTest.kt +++ b/stdlib/src/test/kotlin/eu/iamgio/quarkdown/stdlib/DataTest.kt @@ -1,11 +1,14 @@ package eu.iamgio.quarkdown.stdlib -import eu.iamgio.quarkdown.ast.MutableAstAttributes import eu.iamgio.quarkdown.ast.Table import eu.iamgio.quarkdown.ast.Text -import eu.iamgio.quarkdown.context.BaseContext +import eu.iamgio.quarkdown.context.MutableContext import eu.iamgio.quarkdown.flavor.quarkdown.QuarkdownFlavor import eu.iamgio.quarkdown.function.value.data.Range +import eu.iamgio.quarkdown.pipeline.Pipeline +import eu.iamgio.quarkdown.pipeline.PipelineOptions +import java.io.File +import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs @@ -18,11 +21,18 @@ private val LINE_SEPARATOR = System.lineSeparator() * [Data] module tests. */ class DataTest { - private val context = BaseContext(MutableAstAttributes(), QuarkdownFlavor, emptySet()) + private val context = MutableContext(QuarkdownFlavor) + + @BeforeTest + fun setup() { + // Attach a mock pipeline to the context, in order to set a working directory for the function calls to use. + val options = PipelineOptions(workingDirectory = File(DATA_FOLDER)) + Pipeline(context, options, emptySet(), { _, _ -> throw UnsupportedOperationException() }) + } @Test fun `file contents`() { - val path = "$DATA_FOLDER/test.txt" + val path = "test.txt" assertEquals( "Line 1${LINE_SEPARATOR}Line 2${LINE_SEPARATOR}${LINE_SEPARATOR}Line 4${LINE_SEPARATOR}Line 5", @@ -47,7 +57,7 @@ class DataTest { @Test fun `csv table`() { - val path = "$DATA_FOLDER/people.csv" + val path = "people.csv" val table = csv(context, path) assertIs(table.unwrappedValue)