Add inline templates to the CLI and library #4
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -333,6 +334,15 @@ func TestClassify(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUsageReferencesResolve(t *testing.T) {
|
||||||
|
for _, token := range regexp.MustCompile(`\{/[^}]+\}`).FindAllString(usage, -1) {
|
||||||
|
code, out, errb := runOut("--seed", "1", token)
|
||||||
|
if code != 0 || strings.TrimSpace(out) == "" {
|
||||||
|
t.Errorf("usage advertises %s: run = %d, %q, stderr %q", token, code, out, errb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRunShapeMisuseBeforeLoad(t *testing.T) {
|
func TestRunShapeMisuseBeforeLoad(t *testing.T) {
|
||||||
code, _, errb := runOut("--no-shipped-data", "[abc]")
|
code, _, errb := runOut("--no-shipped-data", "[abc]")
|
||||||
if code != 2 || !strings.Contains(errb, "[abc]") || strings.Contains(errb, "--data-path") {
|
if code != 2 || !strings.Contains(errb, "[abc]") || strings.Contains(errb, "--data-path") {
|
||||||
|
|||||||
+9
-5
@@ -83,12 +83,16 @@ func TestFieldlessTokenHint(t *testing.T) {
|
|||||||
t.Fatalf("FakeTemplate(bare token) = %v, want a hint naming {/sv_SE.person.last}", err)
|
t.Fatalf("FakeTemplate(bare token) = %v, want a hint naming {/sv_SE.person.last}", err)
|
||||||
}
|
}
|
||||||
_, err = f.FakeTemplate(`{"format":"{x}","repeat":2}`)
|
_, err = f.FakeTemplate(`{"format":"{x}","repeat":2}`)
|
||||||
if err == nil || strings.Contains(err.Error(), "bare string") {
|
if err == nil || !strings.Contains(err.Error(), `this template has none — write {/x}`) {
|
||||||
t.Errorf("FakeTemplate(fieldless object) = %v, want an error that does not call it a bare string", err)
|
t.Errorf("FakeTemplate(fieldless object) = %v, want the hint without calling it a bare string", err)
|
||||||
}
|
}
|
||||||
_, err = f.FakeTemplate(`{ /sv_SE.person.last }`)
|
// A hint is only a drop-in where the name is the whole token: {/x} inside a
|
||||||
|
// transform or an alternation renders a different value, so none is offered.
|
||||||
|
for _, input := range []string{`{ /sv_SE.person.last }`, "{lowercase(x)}", "{x|y}"} {
|
||||||
|
_, err := f.FakeTemplate(input)
|
||||||
if err == nil || strings.Contains(err.Error(), "write {") {
|
if err == nil || strings.Contains(err.Error(), "write {") {
|
||||||
t.Errorf("FakeTemplate(malformed token) = %v, want no hint naming a spelling that fails too", err)
|
t.Errorf("FakeTemplate(%q) = %v, want no hint naming a spelling that means something else", input, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +109,7 @@ func TestFakeTemplateErrors(t *testing.T) {
|
|||||||
{`name: {..nope}`, "write {/nope}"},
|
{`name: {..nope}`, "write {/nope}"},
|
||||||
{`{"format":"x"}`, "is a string"},
|
{`{"format":"x"}`, "is a string"},
|
||||||
{`{/misc.country} {/misc.country.alpha2}`, "renders a level"},
|
{`{/misc.country} {/misc.country.alpha2}`, "renders a level"},
|
||||||
{`{"format":"{/misc.country.alpha2} {x}","x":"{/misc.country}"}`, "renders"},
|
{`{"format":"{/misc.country.alpha2} {x}","x":"{/misc.country}"}`, "reads a path into"},
|
||||||
} {
|
} {
|
||||||
_, err := f.FakeTemplate(c.input)
|
_, err := f.FakeTemplate(c.input)
|
||||||
if err == nil || !strings.Contains(err.Error(), c.want) {
|
if err == nil || !strings.Contains(err.Error(), c.want) {
|
||||||
|
|||||||
Reference in New Issue
Block a user