Skip to content

Commit 60761e8

Browse files
Merge pull request #1862 from Kotlin/texts_samples
Added texts samples saving
2 parents fd1f582 + e5f353b commit 60761e8

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

docs/StardustDocs/topics/schemas/DataSchemaGenerationMethods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Use [`cast`](cast.md) to apply the generated schema to a `DataFrame`:
192192
<!---FUN notebook_test_generate_docs_3-->
193193

194194
```kotlin
195-
df.cast<_DataFrameType1>().filter { orders.all { orderId >= 102 } }
195+
df.filter { orders.all { orderId >= 102 } }
196196
```
197197

198198
<!---END-->

samples/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ korro {
9595
include("toHTML.md")
9696
include("guides/*.md")
9797
include("concepts/*.md")
98+
include("schemas/*.md")
9899
include("operations/utils/*.md")
99100
include("operations/multiple/*.md")
100101
include("operations/column/*.md")
@@ -126,6 +127,12 @@ korro {
126127
include("src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/io/*.kt")
127128
},
128129
)
130+
131+
outputs.from(
132+
fileTree(project.layout.buildDirectory) {
133+
include("korroOutputLines/*")
134+
},
135+
)
129136
}
130137

131138
groupSamples {

samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/DataFrameSampleHelper.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.jetbrains.kotlinx.dataframe.samples
22

33
import org.jetbrains.kotlinx.dataframe.DataColumn
4+
import org.jetbrains.kotlinx.dataframe.api.CodeString
45
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
56
import org.jetbrains.kotlinx.dataframe.samples.api.TestBase
67
import org.jetbrains.kotlinx.kandy.letsplot.samples.SampleHelper
8+
import java.io.File
79

810
abstract class DataFrameSampleHelper(sampleName: String, subFolder: String = "samples") :
911
SampleHelper(
@@ -14,6 +16,31 @@ abstract class DataFrameSampleHelper(sampleName: String, subFolder: String = "sa
1416
),
1517
TestBase {
1618

19+
fun fqnTestName(): String = "${this::class.java.name}.${testName.methodName}"
20+
21+
private val korroOutputLinesDir: File = File("build/korroOutputLines")
22+
23+
fun String.saveSample(addOutputLine: Boolean = true) {
24+
val fqnName = fqnTestName().replace("_dataframe", "")
25+
val text = if (addOutputLine) {
26+
"\nOutput:\n\n$this\n"
27+
} else {
28+
"\n$this\n"
29+
}
30+
31+
korroOutputLinesDir.mkdirs()
32+
File(korroOutputLinesDir, fqnName).writeText(text)
33+
}
34+
35+
fun CodeString.saveSample(addOutputLine: Boolean = true, addCodeBlock: Boolean = true) {
36+
val text = if (addCodeBlock) {
37+
"```kotlin\n$value\n```"
38+
} else {
39+
value
40+
}
41+
text.saveSample(addOutputLine)
42+
}
43+
1744
fun DataColumn<*>.saveDfHtmlSample() {
1845
toDataFrame().saveDfHtmlSample()
1946
}

0 commit comments

Comments
 (0)