1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestSetOption(t *testing.T) {
17 check func(Options) bool
22 check: func(o Options) bool { return o.SymbolStyle == DynamicSymbols },
28 check: func(o Options) bool { return o.SymbolStyle == "" },
34 check: func(o Options) bool { return o.SymbolStyle == "" },
37 name: "symbolMatcher",
38 value: "caseInsensitive",
39 check: func(o Options) bool { return o.SymbolMatcher == SymbolCaseInsensitive },
42 name: "completionBudget",
44 check: func(o Options) bool { return o.CompletionBudget == 2*time.Second },
49 check: func(o Options) bool { return o.Staticcheck == true },
53 value: map[string]interface{}{"generate": true},
54 check: func(o Options) bool { return o.Codelenses["generate"] },
57 name: "allExperiments",
59 check: func(o Options) bool {
60 return true // just confirm that we handle this setting
65 value: "FullDocumentation",
66 check: func(o Options) bool {
67 return o.HoverKind == FullDocumentation
72 value: "NoDocumentation",
73 check: func(o Options) bool {
74 return o.HoverKind == NoDocumentation
80 check: func(o Options) bool {
81 return o.HoverKind == SingleLine
87 check: func(o Options) bool {
88 return o.HoverKind == Structured
92 name: "ui.documentation.hoverKind",
94 check: func(o Options) bool {
95 return o.HoverKind == Structured
101 check: func(o Options) bool {
102 return o.Matcher == Fuzzy
107 value: "CaseSensitive",
108 check: func(o Options) bool {
109 return o.Matcher == CaseSensitive
114 value: "CaseInsensitive",
115 check: func(o Options) bool {
116 return o.Matcher == CaseInsensitive
121 value: map[string]interface{}{"testing": "true"},
122 check: func(o Options) bool {
123 v, found := o.Env["testing"]
124 return found && v == "true"
129 value: []string{"invalid", "input"},
131 check: func(o Options) bool {
136 name: "directoryFilters",
137 value: []interface{}{"-node_modules", "+project_a"},
138 check: func(o Options) bool {
139 return len(o.DirectoryFilters) == 2
143 name: "directoryFilters",
144 value: []interface{}{"invalid"},
146 check: func(o Options) bool {
147 return len(o.DirectoryFilters) == 0
151 name: "directoryFilters",
152 value: []string{"-invalid", "+type"},
154 check: func(o Options) bool {
155 return len(o.DirectoryFilters) == 0
160 value: map[string]interface{}{
165 check: func(o Options) bool {
166 return !o.Annotations[Nil] && !o.Annotations[Bounds]
171 for _, test := range tests {
173 result := opts.set(test.name, test.value, map[string]struct{}{})
174 if (result.Error != nil) != test.wantError {
175 t.Fatalf("Options.set(%q, %v): result.Error = %v, want error: %t", test.name, test.value, result.Error, test.wantError)
177 // TODO: this could be made much better using cmp.Diff, if that becomes
178 // available in this module.
179 if !test.check(opts) {
180 t.Errorf("Options.set(%q, %v): unexpected result %+v", test.name, test.value, opts)