MCPcopy Index your code
hub / github.com/cli/cli / TestPrintFlagsHTMLShowsDefaultValues

Function TestPrintFlagsHTMLShowsDefaultValues

internal/docs/markdown_test.go:136–246  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

134}
135
136func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) {
137
138 type TestOptions struct {
139 Limit int
140 Template string
141 Fork bool
142 NoArchive bool
143 Topic []string
144 }
145 opts := TestOptions{}
146
147 // Int flag should show it
148 c := &cobra.Command{}
149 c.Flags().IntVar(&opts.Limit, "limit", 30, "Some limit")
150 flags := c.NonInheritedFlags()
151 buf := new(bytes.Buffer)
152 flags.SetOutput(buf)
153
154 if err := printFlagsHTML(buf, flags); err != nil {
155 t.Fatalf("printFlagsHTML failed: %s", err.Error())
156 }
157 output := buf.String()
158
159 checkStringContains(t, output, "(default 30)")
160
161 // Bool flag should hide it if default is false
162 c = &cobra.Command{}
163 c.Flags().BoolVar(&opts.Fork, "fork", false, "Show only forks")
164
165 flags = c.NonInheritedFlags()
166 buf = new(bytes.Buffer)
167 flags.SetOutput(buf)
168
169 if err := printFlagsHTML(buf, flags); err != nil {
170 t.Fatalf("printFlagsHTML failed: %s", err.Error())
171 }
172 output = buf.String()
173
174 checkStringOmits(t, output, "(default ")
175
176 // Bool flag should show it if default is true
177 c = &cobra.Command{}
178 c.Flags().BoolVar(&opts.NoArchive, "no-archived", true, "Hide archived")
179 flags = c.NonInheritedFlags()
180 buf = new(bytes.Buffer)
181 flags.SetOutput(buf)
182
183 if err := printFlagsHTML(buf, flags); err != nil {
184 t.Fatalf("printFlagsHTML failed: %s", err.Error())
185 }
186 output = buf.String()
187
188 checkStringContains(t, output, "(default true)")
189
190 // String flag should show it if default is not an empty string
191 c = &cobra.Command{}
192 c.Flags().StringVar(&opts.Template, "template", "T1", "Some template")
193 flags = c.NonInheritedFlags()

Callers

nothing calls this directly

Calls 5

printFlagsHTMLFunction · 0.85
checkStringContainsFunction · 0.85
checkStringOmitsFunction · 0.85
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected