Skip to content

Commit

Permalink
Use subtests in autotemplate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 10, 2019
1 parent 76ff3be commit 313c04b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/chezmoi/autotemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ 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",
},
wantStr: "email = {{ .email }}\n",
},
{
name: "longest_first",
contentsStr: "name = John Smith\nfirstName = John\n",
data: map[string]interface{}{
"name": "John Smith",
Expand All @@ -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{}{
Expand All @@ -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",
Expand All @@ -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)
}
})
}
}

0 comments on commit 313c04b

Please sign in to comment.