Tests for an empty field name

A field named "" loads, and a bare {} token renders it, but no dot path can
reach it — List hides it and Fake cannot ask for it. {a.} is already rejected
for the same reason, so the two spellings disagree about the same mistake.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
M
2026-08-31 22:07:47 +02:00
committed by lilleman-tw
parent 4b3dd011fc
commit e31e77b8a3
2 changed files with 13 additions and 5 deletions
+6 -5
View File
@@ -656,12 +656,13 @@ func TestDeepPathsUnderOneHeadStayIndependentWhereTheyDiverge(t *testing.T) {
}
func TestEmptyPathSegmentIsRejected(t *testing.T) {
// "{a.}", "{.b}" and "{a..b}" are unfinished paths. A field really named ""
// would otherwise make them resolve, which reads as a typo that worked.
// "{a.}", "{.b}" and "{a..b}" are unfinished paths, and the segment naming
// nothing is reported as that rather than as a missing field. An empty name is
// rejected where it is authored, so no data can make these resolve.
rejected := map[string]string{
"trailing dot": `{"format":"[{a.}]","a":{"format":"x","":["V"]}}`,
"leading dot": `{"format":"[{.b}]","":{"format":"{b}","b":["V"]}}`,
"double dot": `{"format":"[{a..b}]","a":{"format":"x","":{"format":"{b}","b":["V"]}}}`,
"trailing dot": `{"format":"[{a.}]","a":{"format":"x"}}`,
"leading dot": `{"format":"[{.b}]","a":{"format":"{b}","b":["V"]}}`,
"double dot": `{"format":"[{a..b}]","a":{"format":"x"}}`,
}
for name, file := range rejected {
_, err := New([]string{writeData(t, map[string]string{"cat": file})})