Skip to content

Commit

Permalink
add test case for #325
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Dec 4, 2024
1 parent 865e83d commit 7786913
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions parser/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import (
"github.com/gomarkdown/markdown/ast"
)

func astToString(node ast.Node) string {
var buf bytes.Buffer
ast.Print(&buf, node)
return buf.String()
}

// Inside HTML, no Markdown is parsed.
func TestHtmlP(t *testing.T) {
input := "<p>*not emph*</p>\n"
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
var buf bytes.Buffer
ast.Print(&buf, doc)
got := buf.String()
got := astToString(doc)
exp := "HTMLBlock '<p>*not emph*</p>'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
Expand All @@ -27,9 +31,7 @@ func TestSVG(t *testing.T) {
input := "<svg><rect> *no emph* </rect></svg>\n"
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
var buf bytes.Buffer
ast.Print(&buf, doc)
got := buf.String()
got := astToString(doc)
exp := "HTMLBlock '<svg><rect> *no emph* </rect></svg>'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
Expand All @@ -51,9 +53,7 @@ func TestCodeBlocIssue320(t *testing.T) {
input := "```go main.go,readonly\npackage main\n```"
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
var buf bytes.Buffer
ast.Print(&buf, doc)
got := buf.String()
got := astToString(doc)
exp := "CodeBlock:go main.go,readonly 'package main\\n'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
Expand All @@ -66,9 +66,7 @@ func TestRect(t *testing.T) {
input := "<rect> *emph* </rect>\n"
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
var buf bytes.Buffer
ast.Print(&buf, doc)
got := buf.String()
got := astToString(doc)
exp := "Paragraph\n Text\n HTMLSpan '<rect>'\n Text\n Emph\n Text 'emph'\n Text\n HTMLSpan '</rect>'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
Expand All @@ -86,3 +84,26 @@ func TestInfiniteLoopFix(t *testing.T) {
}
//ast.Print(os.Stdout, doc)
}

// TODO: fix parsing for this test case without breaking other test cases
// https://github.com/gomarkdown/markdown/issues/325
// this can be fixed by removing p.fenceCodeBlock() call in Parser.quote()
// but would break other test cases
func TestBug325(t *testing.T) {
input := `> ~~~
> // comment
> ~~~
~~~`
p := NewWithExtensions(CommonExtensions)
doc := p.Parse([]byte(input))
got := astToString(doc)
// TODO: currently it sees the last `~~~` as a code block end
// should see `> ~~~` as a code block end
exp := "BlockQuote\n CodeBlock: '> // comment\\n> ~~~\\n\\n'\n"
//exp := "BlockQuote\n CodeBlock: '// comment\\n'\nParagraph\n Text '~~~'\n"
if got != exp {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nGot [%#v]\n",
input, exp, got)
}
}

0 comments on commit 7786913

Please sign in to comment.