|
1 | 1 | package org.jetbrains.dokka.uitest.markdown
|
2 | 2 |
|
3 | 3 | /**
|
| 4 | + * Contains examples of Markdown code showcasing Kotlin syntax highlighting. |
4 | 5 | *
|
5 |
| - * Contains examples of Markdown code. |
6 |
| - * |
7 |
| - * Here's a code block: |
| 6 | + * Here's a code block with various Kotlin features to test syntax highlighting: |
8 | 7 | *
|
9 | 8 | * ```
|
10 |
| - * class MyUIClass { |
11 |
| - * val scope = MainScope() // the scope of MyUIClass, uses Dispatchers.Main |
| 9 | + * // Single-line comment token |
| 10 | + * /* Multi-line comment token */ |
| 11 | + * /** Documentation comment token */ |
| 12 | + * |
| 13 | + * // Package declaration to test namespace token |
| 14 | + * package com.example.highlighting |
| 15 | + * |
| 16 | + * // Imports to test namespace tokens |
| 17 | + * import kotlin.random.Random |
| 18 | + * import kotlin.collections.List |
| 19 | + * |
| 20 | + * // Type alias to test symbol token |
| 21 | + * typealias Handler<T> = (T) -> Unit |
| 22 | + * typealias AsyncOperation = suspend () -> Unit |
| 23 | + * |
| 24 | + * // Sealed interface to test class-name and keyword tokens |
| 25 | + * sealed interface State { |
| 26 | + * object Loading : State |
| 27 | + * data class Success(val data: String) : State |
| 28 | + * data class Error(val message: String) : State |
| 29 | + * } |
| 30 | + * |
| 31 | + * // Class with various token types |
| 32 | + * class SyntaxDemo { |
| 33 | + * // Properties to test property and symbol tokens |
| 34 | + * private val number: Int = 42 // number token |
| 35 | + * protected var text: String = "Hello" // string token |
| 36 | + * internal const val PI = 3.14159 // number token |
12 | 37 | *
|
13 |
| - * fun destroy() { // destroys an instance of MyUIClass |
14 |
| - * scope.cancel() // cancels all coroutines launched in this scope |
15 |
| - * // ... do the rest of cleanup here ... |
16 |
| - * } |
| 38 | + * protected var url: String = "https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/min.html" |
17 | 39 | *
|
18 |
| - * /* |
19 |
| - * * Note: if this instance is destroyed or any of the launched coroutines |
20 |
| - * * in this method throws an exception, then all nested coroutines are cancelled. |
21 |
| - * */ |
22 |
| - * fun showSomeData() = scope.launch { // launched in the main thread |
23 |
| - * // ... here we can use suspending functions or coroutine builders with other dispatchers |
24 |
| - * draw(data) // draw in the main thread |
| 40 | + * var pattern = Regex("""\b\d{3}-\d{3}-\d{4}\b""") |
| 41 | + * |
| 42 | + * // Companion with property tokens |
| 43 | + * companion object { |
| 44 | + * const val DEBUG = true // boolean token |
| 45 | + * const val CHAR_SAMPLE = 'A' // char token |
| 46 | + * @JvmField val EMPTY = "" // string token |
| 47 | + * } |
| 48 | + * |
| 49 | + * // Function to test various tokens |
| 50 | + * fun calculate(x: Double): Double { |
| 51 | + * val multiplier = 2.5 // number token |
| 52 | + * val enabled: Boolean = false // boolean token |
| 53 | + * |
| 54 | + * // Operators test |
| 55 | + * val result = when { |
| 56 | + * x <= 0 -> x * multiplier |
| 57 | + * x >= 100 -> x / multiplier |
| 58 | + * else -> x + multiplier |
| 59 | + * } |
| 60 | + * |
| 61 | + * // Built-in types and functions test |
| 62 | + * val numbers: List<Int> = listOf(1, 2, 3) |
| 63 | + * val filtered = numbers |
| 64 | + * .filter { it > 0 } // lambda and operator tokens |
| 65 | + * .map { it.toString() } // function token |
| 66 | + * .joinToString(separator = ", ") |
| 67 | + * |
| 68 | + * // String template and escape sequence tokens |
| 69 | + * println("Result: $result\nFiltered: $filtered") |
| 70 | + * |
| 71 | + * return result |
| 72 | + * } |
| 73 | + * |
| 74 | + * // Extension function with operator and symbol tokens |
| 75 | + * infix fun Int.power(exponent: Int): Int { |
| 76 | + * require(exponent >= 0) { "Exponent must be non-negative" } |
| 77 | + * return when (exponent) { |
| 78 | + * 0 -> 1 |
| 79 | + * 1 -> this |
| 80 | + * else -> this * (this power (exponent - 1)) |
| 81 | + * } |
25 | 82 | * }
|
26 | 83 | * }
|
27 | 84 | * ```
|
28 | 85 | *
|
29 |
| - * Here's inline code: `this` and `that` and `fun foo()` and `class Omg : MyInterface` |
| 86 | + * Here's inline code with various token types: |
| 87 | + * `val x: Int = 0`, `fun interface EventHandler`, `object : Runnable`, |
| 88 | + * `class Sample<T : Any>`, `@Deprecated fun old()`, `var name: String?` |
30 | 89 | */
|
31 | 90 | class MarkdownCode {}
|
0 commit comments