fix(parser): reset dotted-key and array records per array-of-tables element
Assisted-by: GLM 5.3
This commit is contained in:
@@ -498,6 +498,36 @@ func TestRejectsInlineTableExtension(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A new element of an array of tables starts a fresh scope: sub-table headers,
|
||||
// nested arrays of tables, and dotted-key paths recorded for the previous
|
||||
// element must not block the same paths in the next one.
|
||||
func TestArrayOfTablesFreshScopePerElement(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"nested array of tables": "[[a]]\n[[a.b]]\nx = 1\n[[a]]\n[a.b]\ny = 2\n",
|
||||
"dotted key": "[[a]]\nb.c = 1\n[[a]]\n[a.b]\nd = 2\n",
|
||||
}
|
||||
for name, doc := range cases {
|
||||
tree, err := Parse([]byte(doc))
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
elements := tree["a"].([]map[string]any)
|
||||
if len(elements) != 2 {
|
||||
t.Errorf("%s: len(a) = %d, want 2", name, len(elements))
|
||||
}
|
||||
}
|
||||
// Within one element the redefinition rules keep applying.
|
||||
for name, doc := range map[string]string{
|
||||
"header over dotted in one element": "[[a]]\nb.c = 1\n[a.b]\nd = 2\n",
|
||||
"table over nested array": "[[a]]\n[[a.b]]\n[a.b]\nx = 1\n",
|
||||
} {
|
||||
if _, err := Parse([]byte(doc)); err == nil {
|
||||
t.Errorf("%s: expected an error, got none", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRejectsSpecInvalid(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"single-digit hour": "a = 2023-10-01T1:32:00Z\n",
|
||||
|
||||
Reference in New Issue
Block a user