on master help sign in
test: Kotlin syntax test file
commit3aabed44cec6c0fc3c1e32a26e24e856c0f3a935 authorFilip Czaplicki <filipczaplicki@gmail.com> dateSun 4 Oct 2020, 22:14 (6 years ago) parent3af7a6b
2 files changed+170
tests/syntax-tests/highlighted/Kotlin/test.kt+85 tests/syntax-tests/source/Kotlin/test.kt+85
tests/syntax-tests/highlighted/Kotlin/test.ktnew file+85
@@ -0,0 +1,85 @@
1+import kotlin.math.*
2+
3+data class Example(
4+ val name: String,
5+ val numbers: List<Int?>
6+)
7+
8+fun interface JokeInterface {
9+ fun isFunny(): Boolean
10+}
11+
12+abstract class AbstractJoke : JokeInterface {
13+ override fun isFunny() = false
14+ abstract fun content(): String
15+}
16+
17+class Joke : AbstractJoke() {
18+ override fun isFunny(): Boolean {
19+ return true
20+ }
21+ override fun content(): String = "content of joke here, haha"
22+}
23+
24+class DelegatedJoke(val joke: Joke) : JokeInterface by joke {
25+ val number: Long = 123L
26+
27+ companion object {
28+ const val someConstant = "some constant text"
29+ }
30+}
31+
32+object SomeSingleton
33+
34+sealed class Shape {
35+ abstract fun area(): Double
36+}
37+
38+data class Square(val sideLength: Double) : Shape() {
39+ override fun area(): Double = sideLength.pow(2)
40+}
41+
42+object Point : Shape() {
43+ override fun area() = .0
44+}
45+
46+class Circle(val radius: Double) : Shape() {
47+ override fun area(): Double {
48+ return PI * radius * radius
49+ }
50+}
51+
52+fun String.extensionMethod() = "test"
53+
54+fun main() {
55+ val name = """
56+ multiline
57+ string
58+ 
59+ some numbers: 123123 42
60+ """.trimIndent()
61+ val example = Example(name = name, numbers = listOf(512, 42, null, -1))
62+
63+ example.numbers
64+ .filterNotNull()
65+ .forEach { println(it) }
66+
67+ setOf(Joke(), DelegatedJoke(Joke()).joke)
68+ .filter(JokeInterface::isFunny)
69+ .map(AbstractJoke::content)
70+ .forEachIndexed { index: Int, joke ->
71+ println("I heard a funny joke(#${index + 1}): $joke")
72+ }
73+
74+ listOf(Square(12.3), Point, Circle(5.2))
75+ .associateWith(Shape::area)
76+ .toList()
77+ .sortedBy { it.second }
78+ .forEach {
79+ println("${it.first}: ${it.second}")
80+ }
81+
82+ println("some string".extensionMethod())
83+
84+ require(SomeSingleton::class.simpleName == "SomeSingletonName") { "something does not seem right..." }
85+}
tests/syntax-tests/source/Kotlin/test.ktnew file+85
@@ -0,0 +1,85 @@
1+import kotlin.math.*
2+
3+data class Example(
4+ val name: String,
5+ val numbers: List<Int?>
6+)
7+
8+fun interface JokeInterface {
9+ fun isFunny(): Boolean
10+}
11+
12+abstract class AbstractJoke : JokeInterface {
13+ override fun isFunny() = false
14+ abstract fun content(): String
15+}
16+
17+class Joke : AbstractJoke() {
18+ override fun isFunny(): Boolean {
19+ return true
20+ }
21+ override fun content(): String = "content of joke here, haha"
22+}
23+
24+class DelegatedJoke(val joke: Joke) : JokeInterface by joke {
25+ val number: Long = 123L
26+
27+ companion object {
28+ const val someConstant = "some constant text"
29+ }
30+}
31+
32+object SomeSingleton
33+
34+sealed class Shape {
35+ abstract fun area(): Double
36+}
37+
38+data class Square(val sideLength: Double) : Shape() {
39+ override fun area(): Double = sideLength.pow(2)
40+}
41+
42+object Point : Shape() {
43+ override fun area() = .0
44+}
45+
46+class Circle(val radius: Double) : Shape() {
47+ override fun area(): Double {
48+ return PI * radius * radius
49+ }
50+}
51+
52+fun String.extensionMethod() = "test"
53+
54+fun main() {
55+ val name = """
56+ multiline
57+ string
58+
59+ some numbers: 123123 42
60+ """.trimIndent()
61+ val example = Example(name = name, numbers = listOf(512, 42, null, -1))
62+
63+ example.numbers
64+ .filterNotNull()
65+ .forEach { println(it) }
66+
67+ setOf(Joke(), DelegatedJoke(Joke()).joke)
68+ .filter(JokeInterface::isFunny)
69+ .map(AbstractJoke::content)
70+ .forEachIndexed { index: Int, joke ->
71+ println("I heard a funny joke(#${index + 1}): $joke")
72+ }
73+
74+ listOf(Square(12.3), Point, Circle(5.2))
75+ .associateWith(Shape::area)
76+ .toList()
77+ .sortedBy { it.second }
78+ .forEach {
79+ println("${it.first}: ${it.second}")
80+ }
81+
82+ println("some string".extensionMethod())
83+
84+ require(SomeSingleton::class.simpleName == "SomeSingletonName") { "something does not seem right..." }
85+}