Skip to content

Commit

Permalink
TomlTable.write() throws NoSuchElementException is children is empty, f…
Browse files Browse the repository at this point in the history
…ixes #226 (#227)
  • Loading branch information
thomasgalvin authored Jun 2, 2023
1 parent 822f3e0 commit 853a3dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class TomlTable(
// Todo: Option to explicitly define super tables?
// Todo: Support dotted key-value pairs (i.e. a.b.c.d = 7)

val firstChild = children.first()
val firstChild = children.firstOrNull() ?: return

if (isExplicit(firstChild) && type == TableType.PRIMITIVE) {
emitter.writeHeader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ArrayEncoderTest {
expectedToml = "a = [ ]"
)
}

@Test
fun simpleArrayTest() {
@Serializable
Expand Down Expand Up @@ -128,4 +128,18 @@ class ArrayEncoderTest {
expectedToml = "a = { b = [ 1, 2, 3 ] }"
)
}

@Test
fun emptyArrayInTableTest(){
@Serializable
data class EmbeddedData(val data: String = "embedded data")

@Serializable
data class EmptyListData(val content: List<EmbeddedData> = listOf() )

assertEncodedEquals(
value = EmptyListData(),
expectedToml = ""
)
}
}

0 comments on commit 853a3dc

Please sign in to comment.