Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Configuration Support for Ignoring Empty Document #286

Closed
wants to merge 11 commits into from
15 changes: 15 additions & 0 deletions src/jvmTest/kotlin/com/charleskorn/kaml/JvmYamlReadingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package com.charleskorn.kaml

import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.assertions.throwables.shouldThrowExactly
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe
import kotlinx.serialization.builtins.serializer
Expand All @@ -42,5 +44,18 @@ class JvmYamlReadingTest : DescribeSpec({
result shouldBe 123
}
}

describe("reading an empty yaml without throwing an error") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes aren't specific to the JVM, but this file is for tests that only apply to the JVM. Could you please move them to the commonTest source set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it but the problem is that the common Kotlin version of YAML only has the default variable. If there were an expected function decodeFromStream or so it would work..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The common Kotlin version has a decodeFromString method that could be used in the tests.

val input = ""
val bytes = ByteArrayInputStream(input.toByteArray(Charsets.UTF_8))

it("expect throwing an error because it's an empty document") {
shouldThrowExactly<EmptyYamlDocumentException> { Yaml.default.decodeFromStream<String>(bytes) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add tests to cover a couple of other scenarios as well. For example, reading lists, maps and Kotlin classes.

}

it("expect ignoring empty document because of configuration") {
shouldNotThrowAny { Yaml(configuration = YamlConfiguration(allowReadingEmptyDocument = true)).decodeFromStream<String>(bytes) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this scenario (reading a non-nullable string), what would you expect to be returned from decodeFromStream? Can we make an assertion that shows the expected behaviour?

}
}
}
})