diff --git a/lib/chezmoi/autotemplate_test.go b/lib/chezmoi/autotemplate_test.go index c0f7efc74fe..cde4c9ff958 100644 --- a/lib/chezmoi/autotemplate_test.go +++ b/lib/chezmoi/autotemplate_test.go @@ -4,11 +4,13 @@ import "testing" func TestAutoTemplate(t *testing.T) { for _, tc := range []struct { + name string contentsStr string data map[string]interface{} wantStr string }{ { + name: "simple", contentsStr: "email = hello@example.com\n", data: map[string]interface{}{ "email": "hello@example.com", @@ -16,6 +18,7 @@ func TestAutoTemplate(t *testing.T) { wantStr: "email = {{ .email }}\n", }, { + name: "longest_first", contentsStr: "name = John Smith\nfirstName = John\n", data: map[string]interface{}{ "name": "John Smith", @@ -24,6 +27,7 @@ func TestAutoTemplate(t *testing.T) { wantStr: "name = {{ .name }}\nfirstName = {{ .firstName }}\n", }, { + name: "nested_values", contentsStr: "email = hello@example.com\n", data: map[string]interface{}{ "personal": map[string]interface{}{ @@ -33,6 +37,7 @@ func TestAutoTemplate(t *testing.T) { wantStr: "email = {{ .personal.email }}\n", }, { + name: "only_replace_words", contentsStr: "darwinian evolution", data: map[string]interface{}{ "os": "darwin", @@ -51,10 +56,12 @@ func TestAutoTemplate(t *testing.T) { }, */ } { - got := autoTemplate([]byte(tc.contentsStr), tc.data) - gotStr := string(got) - if gotStr != tc.wantStr { - t.Errorf("autoTemplate([]byte(%q), %v) == %q, want %q", tc.contentsStr, tc.data, gotStr, tc.wantStr) - } + t.Run(tc.name, func(t *testing.T) { + got := autoTemplate([]byte(tc.contentsStr), tc.data) + gotStr := string(got) + if gotStr != tc.wantStr { + t.Errorf("autoTemplate([]byte(%q), %v) == %q, want %q", tc.contentsStr, tc.data, gotStr, tc.wantStr) + } + }) } }