MCPcopy Create free account
hub / github.com/cli/cli / assertPipesAreInCodeBlocks

Function assertPipesAreInCodeBlocks

pkg/cmd/root/help_test.go:104–126  ·  view source on GitHub ↗

If not in a code block or a code span, kramdown treats pipes ("|") as table column separators, even if there's no table header, or left/right table row borders (i.e. lines starting and ending with a pipe). We need to assert there's no pipe in the text unless it's in a code-block or code-span. (See

(t *testing.T, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

102//
103// (See https://github.com/cli/cli/issues/10348)
104func assertPipesAreInCodeBlocks(t *testing.T, cmd *cobra.Command) {
105 md := goldmark.New()
106 reader := text.NewReader([]byte(cmd.Long))
107 doc := md.Parser().Parse(reader)
108
109 var checkNode func(node ast.Node)
110 checkNode = func(node ast.Node) {
111 if node.Kind() == ast.KindCodeSpan || node.Kind() == ast.KindCodeBlock {
112 return
113 }
114
115 if node.Kind() == ast.KindText {
116 text := string(node.(*ast.Text).Segment.Value(reader.Source()))
117 require.NotContains(t, text, "|", `found pipe ("|") in plain text in %q docs`, cmd.CommandPath())
118 }
119
120 for child := node.FirstChild(); child != nil; child = child.NextSibling() {
121 checkNode(child)
122 }
123 }
124
125 checkNode(doc)
126}
127
128func TestWriteHelp_aliasResolution(t *testing.T) {
129 newRoot := func() (*cobra.Command, *iostreams.IOStreams) {

Callers 1

Calls 1

ValueMethod · 0.80

Tested by

no test coverage detected