Created
October 5, 2016 22:02
-
-
Save namsral/04ee7c39064e2e53d1000c1a56d07d6f to your computer and use it in GitHub Desktop.
Go table-driven tests snippets for vim ultisnips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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