Skip to content

Commit e0c42a5

Browse files
committed
Add jvm example
1 parent e820b54 commit e0c42a5

File tree

29 files changed

+647
-51
lines changed

29 files changed

+647
-51
lines changed
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import io.ktor.client.HttpClient
2-
import io.ktor.client.engine.js.Js
3-
import io.ktor.client.request.get
4-
import io.ktor.client.statement.bodyAsText
5-
6-
private val client = HttpClient(Js)
7-
8-
suspend fun fetchDogUsingHttpClient(): Dog {
9-
val resp = client.get("https://dog.ceo/api/breeds/image/random")
10-
var message = ""
11-
var status = ""
12-
JSON.parse<Dog>(resp.bodyAsText()) { key, value ->
13-
when (key) {
14-
"message" -> message = value.toString()
15-
"status" -> status = value.toString()
16-
}
17-
}
18-
return Dog(message, status)
19-
}
20-
21-
data class Dog(val message: String, val status: String)
22-
1+
//import io.ktor.client.HttpClient
2+
//import io.ktor.client.engine.js.Js
3+
//import io.ktor.client.request.get
4+
//import io.ktor.client.statement.bodyAsText
5+
//
6+
//private val client = HttpClient(Js)
7+
//
8+
//suspend fun fetchDogUsingHttpClient(): Dog {
9+
// val resp = client.get("https://dog.ceo/api/breeds/image/random")
10+
// var message = ""
11+
// var status = ""
12+
// JSON.parse<Dog>(resp.bodyAsText()) { key, value ->
13+
// when (key) {
14+
// "message" -> message = value.toString()
15+
// "status" -> status = value.toString()
16+
// }
17+
// }
18+
// return Dog(message, status)
19+
//}
20+
//
21+
//data class Dog(val message: String, val status: String)
22+
//
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.kotest.examples.js
2+
3+
fun bitstring(bits: List<Boolean>): String {
4+
require(bits.isNotEmpty())
5+
return buildString {
6+
repeat(bits.size) {
7+
if (bits[it]) append("1") else append("0")
8+
}
9+
}
10+
}

kotest-javascript/src/jsTest/kotlin/io/kotest/examples/js/BitstringTest.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import io.kotest.assertions.throwables.shouldThrowAny
44
import io.kotest.core.spec.style.DescribeSpec
55
import io.kotest.matchers.shouldBe
66

7-
//class BitstringTest : DescribeSpec() {
8-
// init {
9-
// describe("bit strings") {
10-
// it("should set bits based on booleans 1") {
11-
// bitstring(listOf(true, false, true, false, true)) shouldBe "10101"
12-
// bitstring(listOf(false, false, false, false, false, false, false, true)) shouldBe "00000001"
13-
// }
14-
// it("should error on empty") {
15-
// shouldThrowAny {
16-
// bitstring(listOf())
17-
// }
18-
// }
19-
// }
20-
// }
21-
//}
7+
class BitstringTest : DescribeSpec() {
8+
init {
9+
describe("bit strings") {
10+
it("should set bits based on booleans 1") {
11+
bitstring(listOf(true, false, true, false, true)) shouldBe "10101"
12+
bitstring(listOf(false, false, false, false, false, false, false, true)) shouldBe "00000001"
13+
}
14+
it("should error on empty") {
15+
shouldThrowAny {
16+
bitstring(listOf())
17+
}
18+
}
19+
}
20+
}
21+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package io.kotest.examples.js
22

3-
import fetchDogUsingHttpClient
4-
import io.kotest.core.spec.style.FunSpec
5-
import io.kotest.matchers.string.shouldEndWith
3+
//import fetchDogUsingHttpClient
4+
//import io.kotest.core.spec.style.FunSpec
5+
//import io.kotest.matchers.string.shouldEndWith
66

7-
class DogTest : FunSpec({
8-
test("fetching a dog using JS promises") {
9-
fetchDogUsingHttpClient().message.shouldEndWith(".jpg")
10-
}
11-
})
7+
//class DogTest : FunSpec({
8+
// test("fetching a dog using JS promises") {
9+
// fetchDogUsingHttpClient().message.shouldEndWith(".jpg")
10+
// }
11+
//})

kotest-javascript/src/jsTest/kotlin/io/kotest/examples/js/IgnoredTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.kotest.examples.js
33
import io.kotest.core.spec.style.ShouldSpec
44
import io.kotest.matchers.shouldBe
55

6-
class IgnoredTests : ShouldSpec() {
6+
class `00IgnoredTests` : ShouldSpec() {
77
init {
88
xshould("ignored by x method") {
99
1 shouldBe 2

kotest-jvm/.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
5+
indent_style = space
6+
indent_size = 3
7+
max_line_length = 120
8+
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

kotest-jvm/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.jar
8+
*.war
9+
*.ear
10+
11+
.allure
12+
13+
*.iml
14+
.idea
15+
16+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
17+
hs_err_pid*
18+
out/
19+
20+
build
21+
target
22+
.gradle
23+
24+
allure-results/
25+
26+
# Gradle wrapper
27+
!gradle/wrapper/gradle-wrapper.jar
28+
29+
allure.log
30+
kotest.log
31+
kotest-tests-junit-report.log
32+
kotest-tests-core.log
33+
34+
local.properties
35+
.kotest
36+
/kotest-examples/kotest-examples-javascript/node_modules/
37+
*.gpg.enc
38+
39+
kotest-tests/kotest-tests-js/node_modules/
40+
.DS_Store
41+
.kotlin

kotest-jvm/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# kotest-jvm
2+
3+
Example project showing how to use Kotest for JVM projects.

kotest-jvm/build.gradle.kts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
2+
3+
plugins {
4+
alias(libs.plugins.kotlin)
5+
alias(libs.plugins.kotest)
6+
}
7+
8+
repositories {
9+
mavenCentral()
10+
mavenLocal()
11+
}
12+
13+
kotlin {
14+
15+
compilerOptions {
16+
apiVersion = KotlinVersion.KOTLIN_2_2
17+
languageVersion = KotlinVersion.KOTLIN_2_2
18+
}
19+
20+
sourceSets {
21+
test {
22+
dependencies {
23+
implementation(libs.kotest.framework.engine)
24+
}
25+
}
26+
}
27+
}

kotest-jvm/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.gradle.jvmargs=-Xmx3G -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
2+
kotlin.native.ignoreDisabledTargets=true

0 commit comments

Comments
 (0)