Skip to content

Instantly share code, notes, and snippets.

@namsral namsral/go.snippets
Created Oct 5, 2016

Embed
What would you like to do?
Go table-driven tests snippets for vim ultisnips
snippet tt "table-driven tests"
func Test${1:Func}(t *testing.T) {
testCases := []struct {
${2:input} ${3:Type}
want ${4:Type}
}{
{$2: ${5:""}, want: ${6:""}},${0: // comment}
}
for _, tc := range testCases {
if got := $1(tc.$2); got != tc.want {
t.Errorf("$1(%s) = %s; want %s", tc.$2, got, tc.want)
}
}
}
endsnippet
snippet tts "table-drive tests using subtests"
func Test${1:Func}(t *testing.T) {
testCases := []struct {
${2:input} ${3:Type}
want ${4:Type}
}{
{$2: ${5:""}, want: ${6:""}},${0: // comment}
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%q", tc.$2), func(t *testing.T) {
if got := $1(tc.$2); got != tc.want {
t.Errorf("got %s; want %s", got, tc.want)
}
})
}
}
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.