Last active
December 7, 2020 07:08
-
-
Save abtris/e6ba014d1e74afe58fc093bd7a3e87cd to your computer and use it in GitHub Desktop.
VSCode Go snippets
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
{ | |
"go main function": { | |
"prefix": "main", | |
"body": [ | |
"package main", | |
"", | |
"func main() {\n\t$0\n}" | |
], | |
"description": "Main func" | |
}, | |
"go simple test": { | |
"prefix": "test", | |
"body": [ | |
"func Test${1:Name}(t *testing.T) {\t", | |
"\texpected := 0", | |
"\treal :=$0", | |
"\tif real != expected {", | |
"\t\tt.Errorf(\"Expected %v and real %v)\", expected, real)", | |
"\t}", | |
"}" | |
], | |
"description": "Simple test skeleton" | |
}, | |
"go simple bench": { | |
"prefix": "bench", | |
"body": [ | |
"func Benchmark${1:Name}(b *testing.B) {\n\tfor n := 0; n < b.N; n++ {\n\t\t$0\n\t}\n}" | |
], | |
"description": "Simple benchmark skeleton" | |
}, | |
"go table test": { | |
"prefix": "ttest", | |
"body": [ | |
"func Test${1:Name}(t *testing.T) {", | |
"\ttests := []struct {", | |
"\t\tname string", | |
"\t\tx string", | |
"\t\ty []string", | |
"\t\tresult bool", | |
"}{", | |
"\t\t{name: \"simple\", x:\"test\", y: []string{\"test\", \"nil\"}, result: true}", | |
"\t}", | |
"\tfor _, test := range tests {", | |
"\t\tt.Run(test.name, func(t *testing.T) {", | |
"\t\t\tresult, _ := ExampleFunc(test.x, test.y)", | |
"\t\t\tif result != test.result {", | |
"\t\t\t\tt.Errorf(\"Expected %v and real %v)\", test.result, result)", | |
"\t\t\t}", | |
"\t\t})", | |
"\t}", | |
"}" | |
], | |
"description": "Table test skeleton" | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment