
We want to provide more flexibility for users to make changes to their configurations while the debug session is running. This could be accomplished by creating a custom request, but that were require a new UI as well, and every client of dlv dap to provide its own UI for this. By using the evaluate context, users can use the already existing debug console to change their configurations. This change includes a refactor of the terminal code in order to share the code with the dap package. This change provides a very similar to UI as the terminal package, but there are different configuration options that are DAP specific. We plan to use this same mechanism to expose a few other commands including "sources" to help users debug an ineffective substitutePath configuration.
102 lines
2.0 KiB
Go
102 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSplitQuotedFields(t *testing.T) {
|
|
in := `field'A' 'fieldB' fie'l\'d'C fieldD 'another field' fieldE`
|
|
tgt := []string{"fieldA", "fieldB", "fiel'dC", "fieldD", "another field", "fieldE"}
|
|
out := SplitQuotedFields(in, '\'')
|
|
|
|
if len(tgt) != len(out) {
|
|
t.Fatalf("expected %#v, got %#v (len mismatch)", tgt, out)
|
|
}
|
|
|
|
for i := range tgt {
|
|
if tgt[i] != out[i] {
|
|
t.Fatalf(" expected %#v, got %#v (mismatch at %d)", tgt, out, i)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSplitDoubleQuotedFields(t *testing.T) {
|
|
in := `field"A" "fieldB" fie"l'd"C "field\"D" "yet another field"`
|
|
tgt := []string{"fieldA", "fieldB", "fiel'dC", "field\"D", "yet another field"}
|
|
out := SplitQuotedFields(in, '"')
|
|
|
|
if len(tgt) != len(out) {
|
|
t.Fatalf("expected %#v, got %#v (len mismatch)", tgt, out)
|
|
}
|
|
|
|
for i := range tgt {
|
|
if tgt[i] != out[i] {
|
|
t.Fatalf(" expected %#v, got %#v (mismatch at %d)", tgt, out, i)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestConfigureListByName(t *testing.T) {
|
|
type testConfig struct {
|
|
boolArg bool `cfgName:"bool-arg"`
|
|
listArg []string `cfgName:"list-arg"`
|
|
}
|
|
|
|
type args struct {
|
|
sargs *testConfig
|
|
cfgname string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
}{
|
|
{
|
|
name: "basic bool",
|
|
args: args{
|
|
sargs: &testConfig{
|
|
boolArg: true,
|
|
listArg: []string{},
|
|
},
|
|
cfgname: "bool-arg",
|
|
},
|
|
want: "bool-arg true\n",
|
|
},
|
|
{
|
|
name: "list arg",
|
|
args: args{
|
|
sargs: &testConfig{
|
|
boolArg: true,
|
|
listArg: []string{"item 1", "item 2"},
|
|
},
|
|
|
|
cfgname: "list-arg",
|
|
},
|
|
want: "list-arg [item 1 item 2]\n",
|
|
},
|
|
{
|
|
name: "empty",
|
|
args: args{
|
|
sargs: &testConfig{},
|
|
cfgname: "",
|
|
},
|
|
want: "",
|
|
},
|
|
{
|
|
name: "invalid",
|
|
args: args{
|
|
sargs: &testConfig{},
|
|
cfgname: "nonexistent",
|
|
},
|
|
want: "",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := ConfigureListByName(tt.args.sargs, tt.args.cfgname, "cfgName"); got != tt.want {
|
|
t.Errorf("ConfigureListByName() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|