diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-11-14 16:33:41 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-11-14 16:33:41 +0300 |
commit | ec40a94e76d33fb77c58e2b4fe8b9aa150885f0a (patch) | |
tree | 681be7e085be713aea5a2a944eb664bed905f69d | |
parent | a3ea8698452c132ae4a756d617775f40f036b907 (diff) | |
download | dokka-ec40a94e76d33fb77c58e2b4fe8b9aa150885f0a.tar.gz dokka-ec40a94e76d33fb77c58e2b4fe8b9aa150885f0a.tar.bz2 dokka-ec40a94e76d33fb77c58e2b4fe8b9aa150885f0a.zip |
Handle indent correctly, Add tests for assertTrue/False samples
3 files changed, 17 insertions, 2 deletions
diff --git a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt index 665a687f..b0988c35 100644 --- a/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt +++ b/core/src/main/kotlin/Samples/KotlinWebsiteSampleProcessingService.kt @@ -2,11 +2,13 @@ package org.jetbrains.dokka.Samples import com.google.inject.Inject import com.intellij.psi.PsiElement +import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.dokka.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.allChildren +import org.jetbrains.kotlin.psi.psiUtil.prevLeaf import org.jetbrains.kotlin.resolve.ImportPath open class KotlinWebsiteSampleProcessingService @@ -39,8 +41,9 @@ open class KotlinWebsiteSampleProcessingService val (argument) = expression.valueArguments builder.apply { expression.valueArguments.getOrNull(1)?.let { - appendln("// ${it.extractStringArgumentValue()}") - // TODO: append same amount of whitespace indentation + append("// ${it.extractStringArgumentValue()}") + val ws = expression.prevLeaf { it is PsiWhiteSpace } + append(ws?.text ?: "\n") } append("println(\"") append(argument.text) diff --git a/core/testdata/format/website-html/sampleWithAsserts.html b/core/testdata/format/website-html/sampleWithAsserts.html index e70d37c9..11a3a626 100644 --- a/core/testdata/format/website-html/sampleWithAsserts.html +++ b/core/testdata/format/website-html/sampleWithAsserts.html @@ -9,7 +9,14 @@ fun main(args: Array<String>) { //sampleStart println(a()) // Hello, Work println("a() == b() is ${a() == b()}") // true +// A eq B +println("a() == b() is ${a() == b()}") // true // readSomeFile(File("some.txt")) // reading file now will fail // readSomeFile(File("some.txt")) // will fail with FileNotFoundException + +fun indented() { + // A neq B + println("a() != b() is ${a() != b()}") // false +} //sampleEnd }</code></pre></div> diff --git a/core/testdata/format/website-html/sampleWithAsserts.kt b/core/testdata/format/website-html/sampleWithAsserts.kt index f5b03eb8..b3bce11d 100644 --- a/core/testdata/format/website-html/sampleWithAsserts.kt +++ b/core/testdata/format/website-html/sampleWithAsserts.kt @@ -22,6 +22,11 @@ fun readSomeFile(f: File) { fun sample() { assertPrints(a(), "Hello, Work") assertTrue(a() == b()) + assertTrue(a() == b(), "A eq B") assertFails("reading file now") { readSomeFile(File("some.txt")) } assertFailsWith<FileNotFoundException> { readSomeFile(File("some.txt")) } + + fun indented() { + assertFalse(a() != b(), "A neq B") + } }
\ No newline at end of file |