-
Notifications
You must be signed in to change notification settings - Fork 50
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
Changes from 1 commit
978cdae
9b537ee
62aa28e
b8ce187
5714655
c2d53f1
5788a61
969f3f1
86b2c86
879cb18
1ef4c02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -42,5 +44,18 @@ class JvmYamlReadingTest : DescribeSpec({ | |
result shouldBe 123 | ||
} | ||
} | ||
|
||
describe("reading an empty yaml without throwing an error") { | ||
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) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.