Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CLEAR directive clearing test lines, with test #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Knit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
11 changes: 11 additions & 0 deletions test/TestDataTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
31 changes: 31 additions & 0 deletions testdata/test-clear.in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

```kotlin
fun main() {
// this code should be cleared
}
```

```text
this text should be cleared
```

<!--- CLEAR -->
<!--- TEST_NAME ClearTest -->

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!
```

<!--- TEST -->
5 changes: 5 additions & 0 deletions testdata/test-clear.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
knit.dir=test-clear/
knit.package=com.example

test.dir=test-clear/test/
test.package=com.example.test
6 changes: 6 additions & 0 deletions testdata/test-clear/example-clear-01.kt
Original file line number Diff line number Diff line change
@@ -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!")
}
14 changes: 14 additions & 0 deletions testdata/test-clear/test/BasicTest.kt
Original file line number Diff line number Diff line change
@@ -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!"
)
}
}