Address stability nits: doc grammar, scalar-JSON note, bracket-rule rationale
Tests / vet + fmt + tests (pull_request) Successful in 56s
Tests / vet + fmt + tests (pull_request) Successful in 56s
This commit is contained in:
@@ -383,6 +383,8 @@ tokens add cost in proportion to the output.
|
|||||||
a path. A name may not contain a brace or a bracket, so a path can never collide
|
a path. A name may not contain a brace or a bracket, so a path can never collide
|
||||||
with either spelling, and the `[` of a JSON array is gated on valid JSON so a
|
with either spelling, and the `[` of a JSON array is gated on valid JSON so a
|
||||||
stray copied bracket never swallows an argument. No `--template` flag is needed.
|
stray copied bracket never swallows an argument. No `--template` flag is needed.
|
||||||
|
Reserving both brackets — though only a leading `[` could collide — keeps one
|
||||||
|
simple name rule instead of a leading-position special case.
|
||||||
- **The shipped data is embedded, not discovered.** A directory a machine happens
|
- **The shipped data is embedded, not discovered.** A directory a machine happens
|
||||||
to have would make `--seed 42` machine-dependent. Data still lives in `data/`
|
to have would make `--seed 42` machine-dependent. Data still lives in `data/`
|
||||||
as JSON; `--data-path` layers over it.
|
as JSON; `--data-path` layers over it.
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ func TestIsTemplate(t *testing.T) {
|
|||||||
for arg, want := range map[string]bool{
|
for arg, want := range map[string]bool{
|
||||||
"sv_SE.person": false,
|
"sv_SE.person": false,
|
||||||
"person.last": false,
|
"person.last": false,
|
||||||
"[abc]": false, // a [ can open a real category name; not JSON
|
"[abc]": false, // a [ that is not valid JSON is not a template
|
||||||
"[abc].field": false,
|
"[abc].field": false,
|
||||||
"name: {x}": true, // a { token: a path can never carry a brace
|
"name: {x}": true, // a { token: a path can never carry a brace
|
||||||
`{"format":"x"}`: true,
|
`{"format":"x"}`: true,
|
||||||
|
|||||||
@@ -123,9 +123,10 @@ func (t *template) compileFormat() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compileInput compiles an inline template: a JSON value, or a bare format string
|
// compileInput compiles an inline template: a JSON value, or a bare format string
|
||||||
// when the input is not JSON. A format string is a template with no fields, so a
|
// when the input is not JSON. A JSON string literal and a bare string compile
|
||||||
// string that is itself valid JSON (a JSON string literal) and a bare string
|
// alike (both are a template with no fields); the other JSON scalars — a number,
|
||||||
// compile alike.
|
// bool or null — are no template, so they are rejected here, as a data file that
|
||||||
|
// was one would be at load.
|
||||||
func compileInput(input string) (node, error) {
|
func compileInput(input string) (node, error) {
|
||||||
var raw any
|
var raw any
|
||||||
if err := json.Unmarshal([]byte(input), &raw); err != nil {
|
if err := json.Unmarshal([]byte(input), &raw); err != nil {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ type Template struct {
|
|||||||
n node
|
n node
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fake renders the template with one draws.
|
// Fake renders the template with one draw.
|
||||||
func (t *Template) Fake() string {
|
func (t *Template) Fake() string {
|
||||||
t.g.mu.Lock()
|
t.g.mu.Lock()
|
||||||
defer t.g.mu.Unlock()
|
defer t.g.mu.Unlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user