From 189bf9820b6d3f416077d0094adaf67da3431048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= Date: Tue, 3 Mar 2026 14:03:57 +0000 Subject: [PATCH] test: parsing inline table --- unstable/parser_test.go | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/unstable/parser_test.go b/unstable/parser_test.go index 47cfca3..e580cb1 100644 --- a/unstable/parser_test.go +++ b/unstable/parser_test.go @@ -412,6 +412,73 @@ func TestParser_AST(t *testing.T) { }, }, }, + { + desc: "inline table with leading comma", + input: "name = { first = \"Tom\"\n, last = \"Werner\" }", + ast: astNode{ + Kind: KeyValue, + Children: []astNode{ + { + Kind: InlineTable, + Children: []astNode{ + { + Kind: KeyValue, + Children: []astNode{ + {Kind: String, Data: []byte(`Tom`)}, + {Kind: Key, Data: []byte(`first`)}, + }, + }, + { + Kind: KeyValue, + Children: []astNode{ + {Kind: String, Data: []byte(`Werner`)}, + {Kind: Key, Data: []byte(`last`)}, + }, + }, + }, + }, + { + Kind: Key, + Data: []byte(`name`), + }, + }, + }, + }, + { + desc: "inline table with leading trailing comma", + input: "name = { first = \"Tom\"\n, }", + ast: astNode{ + Kind: KeyValue, + Children: []astNode{ + { + Kind: InlineTable, + Children: []astNode{ + { + Kind: KeyValue, + Children: []astNode{ + {Kind: String, Data: []byte(`Tom`)}, + {Kind: Key, Data: []byte(`first`)}, + }, + }, + }, + }, + { + Kind: Key, + Data: []byte(`name`), + }, + }, + }, + }, + { + desc: "inline table comma at start is error", + input: "name = { , first = \"Tom\" }", + err: true, + }, + { + desc: "inline table double comma across newline is error", + input: "name = { first = \"Tom\",\n, last = \"Werner\" }", + err: true, + }, } for _, e := range examples {