Add a runnable Go example
This commit is contained in:
parent
bab81953d7
commit
5075f3a11a
7 changed files with 125 additions and 1 deletions
|
|
@ -290,7 +290,7 @@ If you just want to try out vimspector without changing your vim config, there
|
|||
are example projects for a number of languages in `support/test`, including:
|
||||
|
||||
* Python (`support/test/python/simple_python`)
|
||||
* Go (`support/test/go/hello_world`)
|
||||
* Go (`support/test/go/hello_world` and `support/test/go/name-starts-with-vowel`)
|
||||
* Nodejs (`support/test/node/simple`)
|
||||
* Chrome (`support/test/chrome/`)
|
||||
* etc.
|
||||
|
|
|
|||
29
support/test/go/name-starts-with-vowel/.vimspector.json
Normal file
29
support/test/go/name-starts-with-vowel/.vimspector.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"configurations": {
|
||||
"run-cmd": {
|
||||
"adapter": "vscode-go",
|
||||
"configuration": {
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/cmd/namestartswithvowel/main.go",
|
||||
"mode": "debug",
|
||||
"dlvToolPath": "$HOME/go/bin/dlv",
|
||||
"dlvLoadConfig": {
|
||||
"maxArrayValues": 1000,
|
||||
"maxStringLen": 1000
|
||||
}
|
||||
}
|
||||
},
|
||||
"test-current-file": {
|
||||
"adapter": "vscode-go",
|
||||
"configuration": {
|
||||
"request": "launch",
|
||||
"mode": "test",
|
||||
"program": "${fileDirname}",
|
||||
"cwd": "${fileDirname}",
|
||||
"dlvToolPath": "$GOPATH/bin/dlv",
|
||||
"env": {},
|
||||
"args": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
support/test/go/name-starts-with-vowel/README.md
Normal file
33
support/test/go/name-starts-with-vowel/README.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Purpose
|
||||
|
||||
This example comes with two example vimspector configs for the Go programming language.
|
||||
|
||||
1) `run-cmd` will launch the main programme under `cmd/namestartswithvowel`.
|
||||
1) `test-current-file` will run the tests in the current file in debug mode.
|
||||
|
||||
## Example use-cases
|
||||
|
||||
### run-cmd
|
||||
|
||||
* Open `cmd/namestartswithvowel/main.go`
|
||||
* Add a breakpoint somewhere within the programme
|
||||
* Start the debugger (`:call vimspector#Continue()` or your relevant keymapping)
|
||||
* Select the first launch configuration (`1: run-cmd`)
|
||||
|
||||
### test-current-file
|
||||
|
||||
* Open `internal/vowels/vowels_test.go`
|
||||
* Add a breakpoint somewhere within the test
|
||||
* Start the debugger (`:call vimspector#Continue()` or your relevant keymapping)
|
||||
* Select the second launch configuration (`2: test-current-file`)
|
||||
|
||||
## Additional Configuration
|
||||
|
||||
There are two additional configuration options specified under `run-cmd`; these parameters configure the maximum string/array size to be shown while debugging.
|
||||
|
||||
```
|
||||
"dlvLoadConfig": {
|
||||
"maxArrayValues": 1000,
|
||||
"maxStringLen": 1000
|
||||
}
|
||||
```
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"example.com/internal/vowels"
|
||||
)
|
||||
|
||||
func main() {
|
||||
names := []string{"Simon", "Bob", "Jennifer", "Amy", "Duke", "Elizabeth"}
|
||||
|
||||
for _, n := range names {
|
||||
if vowels.NameStartsWithVowel(n) {
|
||||
fmt.Printf("%s starts with a vowel!\n", n)
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("%s does not start with a vowel!\n", n)
|
||||
}
|
||||
}
|
||||
3
support/test/go/name-starts-with-vowel/go.mod
Normal file
3
support/test/go/name-starts-with-vowel/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module example.com
|
||||
|
||||
go 1.16
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package vowels
|
||||
|
||||
import "strings"
|
||||
|
||||
func NameStartsWithVowel(name string) bool {
|
||||
s := strings.Split(strings.ToLower(name), "")
|
||||
|
||||
return s[0] == "a" || s[0] == "e" || s[0] == "i" || s[0] == "o" || s[0] == "u"
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package vowels
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNameStartsWithVowel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
input string
|
||||
expectedOutput bool
|
||||
}{
|
||||
{
|
||||
input: "Simon",
|
||||
expectedOutput: false,
|
||||
},
|
||||
{
|
||||
input: "Andy",
|
||||
expectedOutput: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
t.Run(fmt.Sprintf("%s should product %t", tt.input, tt.expectedOutput), func(t *testing.T) {
|
||||
out := NameStartsWithVowel(tt.input)
|
||||
if out != tt.expectedOutput {
|
||||
t.Errorf("%s produced %t, when %t was expected", tt.input, out, tt.expectedOutput)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue