Skip to content

Commit 8b6bb36

Browse files
AlexanderPrendotakotlin-samples-pusher-botdkrasnoff
authored
New samples from kotlin-web-site (#721)
* test(samples): add new samples --------- Co-authored-by: kotlin-samples-pusher-bot <bot@samples.kotlin.com> Co-authored-by: Dmitrii Krasnov <dmitrii.krasnov@jetbrains.com>
1 parent bacec91 commit 8b6bb36

File tree

228 files changed

+1330
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+1330
-438
lines changed

src/test/kotlin/com/compiler/server/ResourceE2ECompileTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class ResourceE2ECompileTest : BaseResourceCompileTest {
6464
""".trimIndent()
6565
}
6666

67+
// TODO(Dmitrii Krasnov): this code ignores some of errors,
68+
// it would be nice to rewrite it.
6769
println("!!! file: ${file.path} not equals but it's random code")
6870
}
6971
} else {

src/test/resources/test-compile-data/jvm/kotlin-by-example/01_Hello world/0c66b958dea3212426eff8cba77117c6.2.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.12.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fun main() {
22
//sampleStart
3-
// Creates an array of Int of size 5 with values
3+
// Creates an array of Int of size 5 with the values initialized to zero
44
val exampleArray = IntArray(5)
55
println(exampleArray.joinToString())
66
// 0, 0, 0, 0, 0
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
fun main() {
22
//sampleStart
3-
var x = 5 // `Int` type is inferred
3+
// Declares the variable x and initializes it with the value of 5
4+
var x: Int = 5
5+
// Reassigns a new value of 6 to the variable x
46
x += 1
7+
// 6
58
//sampleEnd
6-
println("x = $x")
9+
println(x)
710
}
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1+
fun main() {
12
//sampleStart
2-
val PI = 3.14
3-
var x = 0
4-
5-
fun incrementX() {
6-
x += 1
7-
}
3+
// Declares the variable x with the value of 5;`Int` type is inferred
4+
val x = 5
5+
// 5
86
//sampleEnd
9-
10-
fun main() {
11-
println("x = $x; PI = $PI")
12-
incrementX()
13-
println("incrementX()")
14-
println("x = $x; PI = $PI")
7+
println(x)
158
}
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
class Rectangle(val height: Double, val length: Double) {
2-
val perimeter = (height + length) * 2
3-
}
41
fun main() {
52
//sampleStart
6-
val rectangle = Rectangle(5.0, 2.0)
7-
println("The perimeter is ${rectangle.perimeter}")
3+
// Initializes the variable x at the moment of declaration; type is not required
4+
val x = 5
5+
// Declares the variable c without initialization; type is required
6+
val c: Int
7+
// Initializes the variable c after declaration
8+
c = 3
9+
// 5
10+
// 3
811
//sampleEnd
12+
println(x)
13+
println(c)
914
}
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
fun main() {
21
//sampleStart
3-
var a = 1
4-
// simple name in template:
5-
val s1 = "a is $a"
6-
7-
a = 2
8-
// arbitrary expression in template:
9-
val s2 = "${s1.replace("is", "was")}, but now is $a"
2+
val PI = 3.14
3+
var x = 0
4+
5+
fun incrementX() {
6+
x += 1
7+
}
8+
// x = 0; PI = 3.14
9+
// incrementX()
10+
// x = 1; PI = 3.14
1011
//sampleEnd
11-
println(s2)
12+
13+
fun main() {
14+
println("x = $x; PI = $PI")
15+
incrementX()
16+
println("incrementX()")
17+
println("x = $x; PI = $PI")
1218
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
//sampleStart
2-
fun maxOf(a: Int, b: Int): Int {
3-
if (a > b) {
4-
return a
5-
} else {
6-
return b
7-
}
1+
class Rectangle(val height: Double, val length: Double) {
2+
val perimeter = (height + length) * 2
83
}
9-
//sampleEnd
10-
114
fun main() {
12-
println("max of 0 and 42 is ${maxOf(0, 42)}")
5+
val rectangle = Rectangle(5.0, 2.0)
6+
println("The perimeter is ${rectangle.perimeter}")
137
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
fun main() {
12
//sampleStart
2-
fun maxOf(a: Int, b: Int) = if (a > b) a else b
3+
var a = 1
4+
// simple name in template:
5+
val s1 = "a is $a"
6+
7+
a = 2
8+
// arbitrary expression in template:
9+
val s2 = "${s1.replace("is", "was")}, but now is $a"
310
//sampleEnd
4-
5-
fun main() {
6-
println("max of 0 and 42 is ${maxOf(0, 42)}")
11+
println(s2)
712
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
fun main() {
21
//sampleStart
3-
val items = listOf("apple", "banana", "kiwifruit")
4-
for (item in items) {
5-
println(item)
2+
fun maxOf(a: Int, b: Int): Int {
3+
if (a > b) {
4+
return a
5+
} else {
6+
return b
67
}
8+
}
79
//sampleEnd
10+
11+
fun main() {
12+
println("max of 0 and 42 is ${maxOf(0, 42)}")
813
}

0 commit comments

Comments
 (0)