Skip to content

Commit

Permalink
snippet: Add table testing boilerplate snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyurt committed Sep 11, 2018
1 parent 5b9058e commit 3fd16ba
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gosnippets/UltiSnips/go.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,28 @@ func Test${1:Function}(t *testing.T) {
}
endsnippet

# test table snippet
snippet tt
var tests = []struct {
name string
expected string
given string
}{
{"${1}", "${2}", "${3}",},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T){
actual := ${0:${VISUAL}}(tt.given)
if actual != tt.expected {
t.Errorf("$0(%s): expected %s, actual %s", tt.given, tt.expected, actual)
}

})
}
endsnippet


snippet hf "http.HandlerFunc" !b
func ${1:handler}(w http.ResponseWriter, r *http.Request) {
${0:fmt.Fprintf(w, "hello world")}
Expand Down
17 changes: 17 additions & 0 deletions gosnippets/minisnip/_go_tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var tests = []struct {
name string
expected string
given string
}{
{"", "", "",},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T){
actual := {{++}}(tt.given)
if actual != tt.expected {
t.Errorf("{{+~\~1+}}(%s): expected %s, actual %s", tt.given, tt.expected, actual)
}

})
}
19 changes: 19 additions & 0 deletions gosnippets/snippets/go.snip
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,25 @@ abbr func TestXYZ(t *testing.T) { ... }
func Test${1:Function}(t *testing.T) {
${0}
}
# test table snippet
snippet tt
abbr var test = {...}{...} for {t.Run(){...}}
var tests = []struct {
name string
expected string
given string
}{
{"${2}", "${3}", "${4}",},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T){
actual := ${1:Function}(tt.given)
if actual != tt.expected {
t.Errorf("given(%s): expected %s, actual %s", tt.given, tt.expected, actual)
}
})
}
# test server
snippet tsrv
abbr ts := httptest.NewServer(...)
Expand Down

0 comments on commit 3fd16ba

Please sign in to comment.