Skip to content

Commit

Permalink
Add support for empty inline table (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
BOOMeranGG authored Sep 4, 2023
1 parent 8db0064 commit 59d3269
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public class TomlInlineTable internal constructor(
.trimCurlyBraces()
.trim()
.also {
if (it.isEmpty()) {
return listOf(TomlStubEmptyNode(lineNo))
}
if (it.endsWith(",")) {
throw ParseException(
"Trailing commas are not permitted in inline tables: [$this] ", lineNo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,44 @@ class InlineTableDecoderTest {
decoded
)
}

@Serializable
data class Point(val x: Int? = null, val y: Int? = null)

@Serializable
data class Position(val point: Point)

@Serializable
data class PositionWrapper(
val id: Int,
val position: Position,
val description: String
)

@Test
fun testEmptyInlineTable() {
val test1 = """
point = { }
""".trimIndent()
val test2 = """
[point]
""".trimIndent()

val result1 = Toml.decodeFromString<Position>(test1)
val result2 = Toml.decodeFromString<Position>(test2)
assertEquals(result2, result1)
}

@Test
fun testNestedEmptyInlineTable() {
val test = """
id = 15
description = "abc"
[position]
point = {}
""".trimIndent()

Toml.decodeFromString<PositionWrapper>(test)
}
}

0 comments on commit 59d3269

Please sign in to comment.