Skip to content

Commit

Permalink
Fix Set decoding and bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
valderman committed Dec 21, 2021
1 parent eb7b836 commit ba76e20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repositories {
}

dependencies {
implementation("cc.ekblad:4koma:0.4.0")
implementation("cc.ekblad:4koma:0.4.1")
}
```

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/cc/ekblad/toml/transcoding/TomlDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,9 @@ private val stringKType: KType = String::class.createType()

private fun <T : Any> TomlDecoder.toList(value: TomlValue.List, target: KType): T =
when (requireKClass(target.classifier)) {
// List also covers the MutableList case
// Set/List also covers the MutableSet/MutableList cases
List::class -> decodeList(value.elements, target.arguments.single().type ?: anyKType) as T
Set::class -> decodeList(value.elements, target.arguments.single().type ?: anyKType).toSet() as T
Collection::class -> decodeList(value.elements, target.arguments.single().type ?: anyKType) as T
Iterable::class -> decodeList(value.elements, target.arguments.single().type ?: anyKType).asIterable() as T
Any::class -> decodeList(value.elements, anyKType) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ class BuiltinDecoderTests : StringTest {
}
}

@Test
fun `can decode to Set`() {
assertEquals(emptySet<String>(), TomlValue.List().decode())
assertEquals(mutableSetOf<String>(), TomlValue.List().decode())
}

@Test
fun `can decode booleans`() {
assertEquals(TomlValue.Bool(true).decode(), true)
Expand Down

0 comments on commit ba76e20

Please sign in to comment.