Skip to content

Commit 834755c

Browse files
mattheusvstamblerre
authored andcommitted
internal/lsp: add tests to set configuration options
Added some tests to hoverKind, matcher, env and directoryFilters of configuration options. I'm also add a validation on `env`configuration, to initialize the map if is nil to avoid the risk of inserting the values in a nil map. Please let me know if this validation is unnecessary. Fixes golang/go#34244 Change-Id: I387ad0a393d981d070002c7e3736acad7b2191bf GitHub-Last-Rev: 4fe3547 GitHub-Pull-Request: #261 Reviewed-on: https://go-review.googlesource.com/c/tools/+/278072 Trust: Robert Findley <[email protected]> Trust: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent bdbb3c9 commit 834755c

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

internal/lsp/source/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ func (o *Options) set(name string, value interface{}) OptionResult {
665665
result.errorf("invalid type %T, expect map", value)
666666
break
667667
}
668+
if o.Env == nil {
669+
o.Env = make(map[string]string)
670+
}
668671
for k, v := range menv {
669672
o.Env[k] = fmt.Sprint(v)
670673
}

internal/lsp/source/options_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,94 @@ func TestSetOption(t *testing.T) {
6060
return true // just confirm that we handle this setting
6161
},
6262
},
63+
{
64+
name: "hoverKind",
65+
value: "FullDocumentation",
66+
check: func(o Options) bool {
67+
return o.HoverKind == FullDocumentation
68+
},
69+
},
70+
{
71+
name: "hoverKind",
72+
value: "NoDocumentation",
73+
check: func(o Options) bool {
74+
return o.HoverKind == NoDocumentation
75+
},
76+
},
77+
{
78+
name: "hoverKind",
79+
value: "SingleLine",
80+
check: func(o Options) bool {
81+
return o.HoverKind == SingleLine
82+
},
83+
},
84+
{
85+
name: "hoverKind",
86+
value: "Structured",
87+
check: func(o Options) bool {
88+
return o.HoverKind == Structured
89+
},
90+
},
91+
{
92+
name: "matcher",
93+
value: "Fuzzy",
94+
check: func(o Options) bool {
95+
return o.Matcher == Fuzzy
96+
},
97+
},
98+
{
99+
name: "matcher",
100+
value: "CaseSensitive",
101+
check: func(o Options) bool {
102+
return o.Matcher == CaseSensitive
103+
},
104+
},
105+
{
106+
name: "matcher",
107+
value: "CaseInsensitive",
108+
check: func(o Options) bool {
109+
return o.Matcher == CaseInsensitive
110+
},
111+
},
112+
{
113+
name: "env",
114+
value: map[string]interface{}{"testing": "true"},
115+
check: func(o Options) bool {
116+
v, found := o.Env["testing"]
117+
return found && v == "true"
118+
},
119+
},
120+
{
121+
name: "env",
122+
value: []string{"invalid", "input"},
123+
wantError: true,
124+
check: func(o Options) bool {
125+
return o.Env == nil
126+
},
127+
},
128+
{
129+
name: "directoryFilters",
130+
value: []interface{}{"-node_modules", "+project_a"},
131+
check: func(o Options) bool {
132+
return len(o.DirectoryFilters) == 2
133+
},
134+
},
135+
{
136+
name: "directoryFilters",
137+
value: []interface{}{"invalid"},
138+
wantError: true,
139+
check: func(o Options) bool {
140+
return len(o.DirectoryFilters) == 0
141+
},
142+
},
143+
{
144+
name: "directoryFilters",
145+
value: []string{"-invalid", "+type"},
146+
wantError: true,
147+
check: func(o Options) bool {
148+
return len(o.DirectoryFilters) == 0
149+
},
150+
},
63151
}
64152

65153
for _, test := range tests {

0 commit comments

Comments
 (0)