From 3aabed44cec6c0fc3c1e32a26e24e856c0f3a935 Mon Sep 17 00:00:00 2001 From: Filip Czaplicki Date: Sun, 4 Oct 2020 22:14:58 +0200 Subject: [PATCH] test: Kotlin syntax test file --- tests/syntax-tests/highlighted/Kotlin/test.kt | 85 +++++++++++++++++++ tests/syntax-tests/source/Kotlin/test.kt | 85 +++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 tests/syntax-tests/highlighted/Kotlin/test.kt create mode 100644 tests/syntax-tests/source/Kotlin/test.kt diff --git a/tests/syntax-tests/highlighted/Kotlin/test.kt b/tests/syntax-tests/highlighted/Kotlin/test.kt new file mode 100644 index 00000000..dcb1560e --- /dev/null +++ b/tests/syntax-tests/highlighted/Kotlin/test.kt @@ -0,0 +1,85 @@ +import kotlin.math.* + +data class Example( + val name: String, + val numbers: List<Int?> +) + +fun interface JokeInterface { + fun isFunny(): Boolean +} + +abstract class AbstractJoke : JokeInterface { + override fun isFunny() = false + abstract fun content(): String +} + +class Joke : AbstractJoke() { + override fun isFunny(): Boolean { + return true + } + override fun content(): String = "content of joke here, haha" +} + +class DelegatedJoke(val joke: Joke) : JokeInterface by joke { + val number: Long = 123L + + companion object { + const val someConstant = "some constant text" + } +} + +object SomeSingleton + +sealed class Shape { + abstract fun area(): Double +} + +data class Square(val sideLength: Double) : Shape() { + override fun area(): Double = sideLength.pow(2) +} + +object Point : Shape() { + override fun area() = .0 +} + +class Circle(val radius: Double) : Shape() { + override fun area(): Double { + return PI * radius * radius + } +} + +fun String.extensionMethod() = "test" + +fun main() { + val name = """ + multiline + string +  + some numbers: 123123 42 + """.trimIndent() + val example = Example(name = name, numbers = listOf(512, 42, null, -1)) + + example.numbers + .filterNotNull() + .forEach { println(it) } + + setOf(Joke(), DelegatedJoke(Joke()).joke) + .filter(JokeInterface::isFunny) + .map(AbstractJoke::content) + .forEachIndexed { index: Int, joke -> + println("I heard a funny joke(#${index + 1}): $joke") + } + + listOf(Square(12.3), Point, Circle(5.2)) + .associateWith(Shape::area) + .toList() + .sortedBy { it.second } + .forEach { + println("${it.first}: ${it.second}") + } + + println("some string".extensionMethod()) + + require(SomeSingleton::class.simpleName == "SomeSingletonName") { "something does not seem right..." } +} diff --git a/tests/syntax-tests/source/Kotlin/test.kt b/tests/syntax-tests/source/Kotlin/test.kt new file mode 100644 index 00000000..40c76974 --- /dev/null +++ b/tests/syntax-tests/source/Kotlin/test.kt @@ -0,0 +1,85 @@ +import kotlin.math.* + +data class Example( + val name: String, + val numbers: List +) + +fun interface JokeInterface { + fun isFunny(): Boolean +} + +abstract class AbstractJoke : JokeInterface { + override fun isFunny() = false + abstract fun content(): String +} + +class Joke : AbstractJoke() { + override fun isFunny(): Boolean { + return true + } + override fun content(): String = "content of joke here, haha" +} + +class DelegatedJoke(val joke: Joke) : JokeInterface by joke { + val number: Long = 123L + + companion object { + const val someConstant = "some constant text" + } +} + +object SomeSingleton + +sealed class Shape { + abstract fun area(): Double +} + +data class Square(val sideLength: Double) : Shape() { + override fun area(): Double = sideLength.pow(2) +} + +object Point : Shape() { + override fun area() = .0 +} + +class Circle(val radius: Double) : Shape() { + override fun area(): Double { + return PI * radius * radius + } +} + +fun String.extensionMethod() = "test" + +fun main() { + val name = """ + multiline + string + + some numbers: 123123 42 + """.trimIndent() + val example = Example(name = name, numbers = listOf(512, 42, null, -1)) + + example.numbers + .filterNotNull() + .forEach { println(it) } + + setOf(Joke(), DelegatedJoke(Joke()).joke) + .filter(JokeInterface::isFunny) + .map(AbstractJoke::content) + .forEachIndexed { index: Int, joke -> + println("I heard a funny joke(#${index + 1}): $joke") + } + + listOf(Square(12.3), Point, Circle(5.2)) + .associateWith(Shape::area) + .toList() + .sortedBy { it.second } + .forEach { + println("${it.first}: ${it.second}") + } + + println("some string".extensionMethod()) + + require(SomeSingleton::class.simpleName == "SomeSingletonName") { "something does not seem right..." } +}