From 4173451dbaa974156051fada6c1997d78c509327 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Sun, 17 Sep 2023 14:59:19 +0200 Subject: [PATCH] fix CLEAR directive clearing test lines, with test --- build.gradle.kts | 2 +- src/Knit.kt | 1 + test/TestDataTest.kt | 11 +++++++++ testdata/test-clear.in.md | 31 +++++++++++++++++++++++++ testdata/test-clear.properties | 5 ++++ testdata/test-clear/example-clear-01.kt | 6 +++++ testdata/test-clear/test/BasicTest.kt | 14 +++++++++++ 7 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 testdata/test-clear.in.md create mode 100644 testdata/test-clear.properties create mode 100644 testdata/test-clear/example-clear-01.kt create mode 100644 testdata/test-clear/test/BasicTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index 3f8f15b..e02e0a9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,7 +36,7 @@ allprojects { implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1") testImplementation(kotlin("test-junit")) } - + tasks.withType { kotlinOptions.apply { languageVersion = "1.4" diff --git a/src/Knit.kt b/src/Knit.kt index 8f07f7b..50c0024 100644 --- a/src/Knit.kt +++ b/src/Knit.kt @@ -294,6 +294,7 @@ fun KnitContext.knit(inputFile: File): Boolean { requireSingleLine(directive) require(directive.param.isEmpty()) { "$CLEAR_DIRECTIVE directive must not have parameters" } codeLines.clear() + testLines.clear() continue@mainLoop } KNIT_DIRECTIVE -> { diff --git a/test/TestDataTest.kt b/test/TestDataTest.kt index ba1f321..6dc4a12 100644 --- a/test/TestDataTest.kt +++ b/test/TestDataTest.kt @@ -247,6 +247,17 @@ class TestDataTest { ) } + // !!! AUTOMATICALLY GENERATED BY TestDataGen. DO NOT EDIT !!! + @Test + fun testTestClear() { + verifyTestData( + "TestClear", + "testdata/test-clear.in.md", + "testdata/test-clear.in.md", + "testdata/test-clear.properties" + ) + } + // !!! AUTOMATICALLY GENERATED BY TestDataGen. DO NOT EDIT !!! @Test fun testTestHidden() { diff --git a/testdata/test-clear.in.md b/testdata/test-clear.in.md new file mode 100644 index 0000000..f2d7fe4 --- /dev/null +++ b/testdata/test-clear.in.md @@ -0,0 +1,31 @@ + +```kotlin +fun main() { + // this code should be cleared +} +``` + +```text +this text should be cleared +``` + + + + +Here is some explanatory text + +```kotlin +fun main() { + println("Hello, world!") +} +``` + +> You can get the full code [here](test-clear/example-clear-01.kt). + +This code prints: + +```text +Hello, world! +``` + + diff --git a/testdata/test-clear.properties b/testdata/test-clear.properties new file mode 100644 index 0000000..e2a5360 --- /dev/null +++ b/testdata/test-clear.properties @@ -0,0 +1,5 @@ +knit.dir=test-clear/ +knit.package=com.example + +test.dir=test-clear/test/ +test.package=com.example.test diff --git a/testdata/test-clear/example-clear-01.kt b/testdata/test-clear/example-clear-01.kt new file mode 100644 index 0000000..5747100 --- /dev/null +++ b/testdata/test-clear/example-clear-01.kt @@ -0,0 +1,6 @@ +// This file was automatically generated from test-basic.in.md by Knit tool. Do not edit. +package com.example.exampleBasic01 + +fun main() { + println("Hello, world!") +} diff --git a/testdata/test-clear/test/BasicTest.kt b/testdata/test-clear/test/BasicTest.kt new file mode 100644 index 0000000..91304d8 --- /dev/null +++ b/testdata/test-clear/test/BasicTest.kt @@ -0,0 +1,14 @@ +// This file was automatically generated from test-basic.in.md by Knit tool. Do not edit. +package com.example.test + +import org.junit.Test +import kotlinx.knit.test.* + +class ClearTest { + @Test + fun testExampleBasic01() { + captureOutput("ExampleClear01") { com.example.exampleClear01.main() }.verifyOutputLines( + "Hello, world!" + ) + } +}