From 0e88302069798ac5f53d8c6773155485f95a7962 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Tue, 3 Sep 2024 17:13:28 +0200 Subject: [PATCH] Basic table rendering --- dynamic/go.mod | 1 + dynamic/go.sum | 3 + go.mod | 1 + go.sum | 3 + pf/go.mod | 1 + pf/go.sum | 3 + pf/tests/go.mod | 1 + pf/tests/go.sum | 3 + pkg/tests/go.mod | 1 + pkg/tests/go.sum | 3 + pkg/tfgen/parse/extension.go | 109 +++++++++++++++++++----------- pkg/tfgen/parse/extension_test.go | 42 ++++++++---- 12 files changed, 117 insertions(+), 54 deletions(-) diff --git a/dynamic/go.mod b/dynamic/go.mod index f5baff1c72..6472010233 100644 --- a/dynamic/go.mod +++ b/dynamic/go.mod @@ -25,6 +25,7 @@ require ( ) require ( + github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/teekennedy/goldmark-markdown v0.3.0 // indirect github.com/yuin/goldmark v1.7.4 // indirect github.com/yuin/goldmark-meta v1.1.0 // indirect diff --git a/dynamic/go.sum b/dynamic/go.sum index d2e5809d52..aa76286abe 100644 --- a/dynamic/go.sum +++ b/dynamic/go.sum @@ -676,6 +676,7 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -719,6 +720,8 @@ github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAm github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/openbao/openbao/api v0.0.0-20240326035453-c075f0ef2c7e h1:LIQFfqW6BA5E2ycx8NNDgyKh0exFubHePM5pF3knogo= diff --git a/go.mod b/go.mod index f47b560335..4463397908 100644 --- a/go.mod +++ b/go.mod @@ -34,6 +34,7 @@ require ( github.com/mitchellh/hashstructure v1.0.0 github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/reflectwalk v1.0.2 + github.com/olekukonko/tablewriter v0.0.5 github.com/pkg/errors v0.9.1 github.com/pulumi/inflector v0.1.1 github.com/pulumi/providertest v0.0.14 diff --git a/go.sum b/go.sum index ee4ef443bd..f6076b09a0 100644 --- a/go.sum +++ b/go.sum @@ -1764,6 +1764,7 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -1825,6 +1826,8 @@ github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= diff --git a/pf/go.mod b/pf/go.mod index f23e791f13..1f0c4c75a3 100644 --- a/pf/go.mod +++ b/pf/go.mod @@ -64,6 +64,7 @@ require ( github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect github.com/nightlyone/lockfile v1.0.0 // indirect + github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pgavlin/fx v0.1.6 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect diff --git a/pf/go.sum b/pf/go.sum index 2dc1dd4586..cb43889384 100644 --- a/pf/go.sum +++ b/pf/go.sum @@ -1768,6 +1768,7 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -1829,6 +1830,8 @@ github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= diff --git a/pf/tests/go.mod b/pf/tests/go.mod index c6084af700..bf91d2f55e 100644 --- a/pf/tests/go.mod +++ b/pf/tests/go.mod @@ -58,6 +58,7 @@ require ( github.com/muesli/termenv v0.15.2 // indirect github.com/nightlyone/lockfile v1.0.0 // indirect github.com/nxadm/tail v1.4.11 // indirect + github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pgavlin/fx v0.1.6 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect diff --git a/pf/tests/go.sum b/pf/tests/go.sum index b3a03db880..5d0861ef9a 100644 --- a/pf/tests/go.sum +++ b/pf/tests/go.sum @@ -1838,6 +1838,7 @@ github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2J github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -1904,6 +1905,8 @@ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= diff --git a/pkg/tests/go.mod b/pkg/tests/go.mod index 2ae89c9776..1d92acadbc 100644 --- a/pkg/tests/go.mod +++ b/pkg/tests/go.mod @@ -77,6 +77,7 @@ require ( github.com/muesli/termenv v0.15.2 // indirect github.com/nightlyone/lockfile v1.0.0 // indirect github.com/nxadm/tail v1.4.11 // indirect + github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pgavlin/fx v0.1.6 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/posener/complete v1.2.3 // indirect diff --git a/pkg/tests/go.sum b/pkg/tests/go.sum index 39a7c537ba..f6be1fb007 100644 --- a/pkg/tests/go.sum +++ b/pkg/tests/go.sum @@ -1822,6 +1822,7 @@ github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2J github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -1888,6 +1889,8 @@ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= diff --git a/pkg/tfgen/parse/extension.go b/pkg/tfgen/parse/extension.go index 152655c264..03813d15de 100644 --- a/pkg/tfgen/parse/extension.go +++ b/pkg/tfgen/parse/extension.go @@ -16,7 +16,9 @@ package parse import ( "bytes" + "fmt" + "github.com/olekukonko/tablewriter" "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" markdown "github.com/teekennedy/goldmark-markdown" "github.com/yuin/goldmark" @@ -41,12 +43,29 @@ var TFRegistryExtension goldmark.Extender = tfRegistryExtension{} type tfRegistryExtension struct{} func (s tfRegistryExtension) Extend(md goldmark.Markdown) { + md.SetRenderer(markdown.NewRenderer()) extension.GFM.Extend(md) // GitHub Flavored Markdown section.Extension.Extend(md) // AST defined sections meta.Extension.Extend(md) // Support for YAML metadata blocks md.Parser().AddOptions(parser.WithASTTransformers( util.Prioritized(recognizeHeaderAfterHTML{}, 902), )) + md.Renderer().AddOptions(renderer.WithNodeRenderers( + util.Prioritized(tableRenderer{md.Renderer()}, 499), + util.Prioritized(renderType{ + kind: ast.KindString, + f: func( + writer util.BufWriter, + _ []byte, n ast.Node, entering bool, + ) (ast.WalkStatus, error) { + if !entering { + return ast.WalkContinue, nil + } + _, err := writer.Write(n.(*ast.String).Value) + return ast.WalkContinue, err + }, + }, 100), + )) } // recognizeHeaderAfterHTML allows us to work around a difference in how TF's registry parses @@ -90,41 +109,6 @@ func WalkNode[T ast.Node](node ast.Node, f func(T)) { contract.AssertNoErrorf(err, "impossible: ast.Walk never returns an error") } -func RenderMarkdown() renderer.Renderer { - // [markdown.NewRenderer] does not produce a renderer that can render [ast.String], - // so we augment the [renderer.Renderer] with that type. - - gm := goldmark.New( - goldmark.WithExtensions(TFRegistryExtension), - goldmark.WithRenderer(markdown.NewRenderer()), - ) - - gm.Renderer().AddOptions(renderer.WithNodeRenderers( - util.Prioritized(renderType{ - kind: ast.KindString, - f: func( - writer util.BufWriter, - _ []byte, n ast.Node, entering bool, - ) (ast.WalkStatus, error) { - if !entering { - return ast.WalkContinue, nil - } - _, err := writer.Write(n.(*ast.String).Value) - return ast.WalkContinue, err - }, - }, 100), - // [markdown] does not know how to render tables,[^1] so they are - // rendered as HTML. We don't want that, as that causes HTML to - // show up in our rendered SDK docs. - // - // [^1]: https://github.com/teekennedy/goldmark-markdown/issues/19 - util.Prioritized(tableRenderer{gm.Renderer()}, 499), - util.Prioritized(tableRenderer{gm.Renderer()}, 501), - )) - - return gm.Renderer() -} - type renderType struct { kind ast.NodeKind f renderer.NodeRendererFunc @@ -150,12 +134,57 @@ func (t tableRenderer) RegisterFuncs(r renderer.NodeRendererFuncRegisterer) { r.Register(extast.KindTable, t.render) r.Register(extast.KindTableHeader, panicOnRender) r.Register(extast.KindTableRow, panicOnRender) - r.Register(extast.KindTableCell, panicOnRender) + r.Register(extast.KindTableCell, + func(writer util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) { + return ast.WalkContinue, nil + }) } func (t tableRenderer) render(writer util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) { - panic("TEST") - return ast.WalkSkipChildren, nil + writer.WriteRune('\n') + var inHeader bool + header := make([]string, 0, len(n.(*extast.Table).Alignments)) + var rows [][]string + err := ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) { + switch n := n.(type) { + case *extast.Table: + return ast.WalkContinue, nil + case *extast.TableHeader: + inHeader = entering + return ast.WalkContinue, nil + case *extast.TableRow: + if entering { + rows = append(rows, make([]string, 0, len(n.Alignments))) + } + return ast.WalkContinue, nil + case *extast.TableCell: + if entering { + var cell bytes.Buffer + err := t.r.Render(&cell, source, n) + if err != nil { + return ast.WalkStop, err + } + if inHeader { + header = append(header, string(n.Text(source))) + } else { + rows[len(rows)-1] = append(rows[len(rows)-1], string(n.Text(source))) + } + } + return ast.WalkSkipChildren, nil + default: + return ast.WalkStop, fmt.Errorf("unexpected node in a table: %s", n.Kind().String()) + } + }) + table := tablewriter.NewWriter(writer) + table.SetHeader(header) + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) + table.SetCenterSeparator("|") + table.SetAutoFormatHeaders(false) + table.SetAutoMergeCells(false) + table.SetAutoWrapText(false) + table.SetReflowDuringAutoWrap(false) + table.AppendBulk(rows) + table.Render() + + return ast.WalkSkipChildren, err } - -type renderMarkdown struct{ *markdown.Renderer } diff --git a/pkg/tfgen/parse/extension_test.go b/pkg/tfgen/parse/extension_test.go index 43d40c559f..2a0ba86985 100644 --- a/pkg/tfgen/parse/extension_test.go +++ b/pkg/tfgen/parse/extension_test.go @@ -28,26 +28,40 @@ import ( func TestRenderTable(t *testing.T) { t.Parallel() - md := `# hi + tests := []struct { + name string + input string + expected autogold.Value + }{ + { + name: "basic", + input: `# hi | t1 | t2 | |---|---| | r1c1 | r1c2 | | r2c1 | r2c2 | -` +`, + expected: autogold.Expect(`# hi - var out bytes.Buffer - err := goldmark.New( - goldmark.WithExtensions(parse.TFRegistryExtension), - goldmark.WithRenderer(parse.RenderMarkdown()), - ).Convert([]byte(md), &out) - require.NoError(t, err) - - autogold.Expect(`# hi - -| t1 | t2 | -|---|---| +| t1 | t2 | +|------|------| | r1c1 | r1c2 | | r2c1 | r2c2 | -`).Equal(t, out.String()) +`), + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + var out bytes.Buffer + err := goldmark.New( + goldmark.WithExtensions(parse.TFRegistryExtension), + ).Convert([]byte(tt.input), &out) + require.NoError(t, err) + + tt.expected.Equal(t, out.String()) + }) + } }