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:
+6
-5
@@ -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})})
|
||||
|
||||
@@ -120,6 +120,13 @@ func TestNewErrors(t *testing.T) {
|
||||
map[string]string{"a|b": `["1"]`},
|
||||
`category "a|b" contains "|"`,
|
||||
},
|
||||
// An empty name is reachable by no dot path, so List cannot advertise it and
|
||||
// Fake cannot ask for it — {} is the one spelling that reaches it, which is
|
||||
// the same trap {a.} is already rejected for.
|
||||
"empty field name": {
|
||||
map[string]string{"a": `{"format":"[{}]","":"VALUE"}`},
|
||||
`field "" is empty`,
|
||||
},
|
||||
"folder name with a paren": {
|
||||
map[string]string{"a(b/cat": `["1"]`},
|
||||
`folder "a(b" contains "("`,
|
||||
|
||||
Reference in New Issue
Block a user