goldmark/renderer/renderer_test.go
Brad Erickson 579c70f79b improve: create missing RendererFunc error message
Improve the development debugging process by better handling a
missing Node Kind RendererFunc. This:
panic: runtime error: index out of range [22] with length 20
Becomes:
panic: RendererFunc not found for kind: KindName
2020-12-27 11:27:41 -08:00

31 lines
569 B
Go

package renderer_test
import (
"bytes"
"testing"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/renderer"
)
type customLink struct {
ast.Link
}
var kindCustomLink = ast.NewNodeKind("customLink")
// Kind implements Node.Kind.
func (n *customLink) Kind() ast.NodeKind {
return kindCustomLink
}
func TestMissingRendererFunc(t *testing.T) {
r := renderer.NewRenderer()
buf := bytes.NewBuffer([]byte{})
err := r.Render(buf, []byte{}, &customLink{})
if err.Error() != "RendererFunc not found for kind: customLink" {
t.Log(err)
t.FailNow()
}
}