mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Added test for BaseBlock.Text retrieval
This commit is contained in:
parent
e44645afbb
commit
e367755421
1 changed files with 48 additions and 0 deletions
|
|
@ -1,8 +1,11 @@
|
||||||
package ast
|
package ast
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yuin/goldmark/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemoveChildren(t *testing.T) {
|
func TestRemoveChildren(t *testing.T) {
|
||||||
|
|
@ -73,3 +76,48 @@ func node(n Node, children ...Node) Node {
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBaseBlock_Text(t *testing.T) {
|
||||||
|
source := []byte(`# Heading
|
||||||
|
|
||||||
|
code block here
|
||||||
|
and also here
|
||||||
|
|
||||||
|
A paragraph
|
||||||
|
|
||||||
|
` + "```" + `somelang
|
||||||
|
fenced code block
|
||||||
|
` + "```" + `
|
||||||
|
|
||||||
|
The end`)
|
||||||
|
|
||||||
|
t.Run("fetch text from code block", func(t *testing.T) {
|
||||||
|
block := NewCodeBlock()
|
||||||
|
block.lines = text.NewSegments()
|
||||||
|
block.lines.Append(text.Segment{Start: 15, Stop: 31})
|
||||||
|
block.lines.Append(text.Segment{Start: 32, Stop: 46})
|
||||||
|
|
||||||
|
expected := []byte("code block here\nand also here\n")
|
||||||
|
if !bytes.Equal(expected, block.Text(source)) {
|
||||||
|
t.Errorf("Expected: %q, got: %q", string(expected), string(block.Text(source)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("fetch text from fenced code block", func(t *testing.T) {
|
||||||
|
block := NewFencedCodeBlock(&Text{
|
||||||
|
Segment: text.Segment{Start: 63, Stop: 71},
|
||||||
|
})
|
||||||
|
block.lines = text.NewSegments()
|
||||||
|
block.lines.Append(text.Segment{Start: 72, Stop: 90})
|
||||||
|
|
||||||
|
expectedLang := []byte("somelang")
|
||||||
|
if !bytes.Equal(expectedLang, block.Language(source)) {
|
||||||
|
t.Errorf("Expected: %q, got: %q", string(expectedLang), string(block.Language(source)))
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := []byte("fenced code block\n")
|
||||||
|
if !bytes.Equal(expected, block.Text(source)) {
|
||||||
|
t.Errorf("Expected: %q, got: %q", string(expected), string(block.Text(source)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue