Skip to content

Commit

Permalink
Fixed Sets of Enums #181
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Dec 1, 2020
1 parent 2cdaa8c commit 61a3824
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SetDecoder : NullHandlingDecoder<Set<*>> {
val t = type.arguments[0].type!!

fun <T> decode(node: ArrayNode, decoder: Decoder<T>): ConfigResult<Set<T>> {
return node.elements.map { decoder.decode(it, type, context) }.sequence()
return node.elements.map { decoder.decode(it, t, context) }.sequence()
.mapInvalid { ConfigFailure.CollectionElementErrors(node, it) }
.map { it.toSet() }
}
Expand All @@ -36,7 +36,7 @@ class SetDecoder : NullHandlingDecoder<Set<*>> {
val tokens = node.value.split(",").map {
StringNode(it.trim(), node.pos)
}
return tokens.map { decoder.decode(it, type, context) }.sequence()
return tokens.map { decoder.decode(it, t, context) }.sequence()
.mapInvalid { ConfigFailure.CollectionElementErrors(node, it) }
.map { it.toSet() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.core.spec.style.StringSpec

class SetDecoderTest : StringSpec({

"Set decoded from yml file" {
data class Test(val a: Set<Long>, val b: Set<String>)

Expand Down
8 changes: 8 additions & 0 deletions hoplite-yaml/src/test/resources/set_objects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a: 1,2,3,3,3
b:
- 1
- 2
- 1
- 2
- 1
- 2
2 changes: 1 addition & 1 deletion hoplite-yaml/src/test/resources/sets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ b:
- 1
- 2
- 1
- 2
- 2

0 comments on commit 61a3824

Please sign in to comment.