From 3fd16ba5a8ea1ffeb7ac976856863fafe5b92653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Tar=C4=B1k=20Yurt?= Date: Sat, 8 Sep 2018 15:16:29 +0300 Subject: [PATCH] snippet: Add table testing boilerplate snippet --- gosnippets/UltiSnips/go.snippets | 22 ++++++++++++++++++++++ gosnippets/minisnip/_go_tt | 17 +++++++++++++++++ gosnippets/snippets/go.snip | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 gosnippets/minisnip/_go_tt diff --git a/gosnippets/UltiSnips/go.snippets b/gosnippets/UltiSnips/go.snippets index 87a7b376be..0a9b7ae41e 100644 --- a/gosnippets/UltiSnips/go.snippets +++ b/gosnippets/UltiSnips/go.snippets @@ -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")} diff --git a/gosnippets/minisnip/_go_tt b/gosnippets/minisnip/_go_tt new file mode 100644 index 0000000000..602e017d30 --- /dev/null +++ b/gosnippets/minisnip/_go_tt @@ -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) + } + + }) +} diff --git a/gosnippets/snippets/go.snip b/gosnippets/snippets/go.snip index 7a22cd248f..3235fb4693 100644 --- a/gosnippets/snippets/go.snip +++ b/gosnippets/snippets/go.snip @@ -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(...)