mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package mark
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/kovetskiy/mark/pkg/mark/stdlib"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCompileMarkdown(t *testing.T) {
|
|
test := assert.New(t)
|
|
|
|
testcases, err := filepath.Glob("testdata/*.md")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for _, filename := range testcases {
|
|
basename := filepath.Base(filename)
|
|
testname := strings.TrimSuffix(basename, ".md")
|
|
htmlname := filepath.Join(filepath.Dir(filename), testname+".html")
|
|
|
|
markdown, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
html, err := os.ReadFile(htmlname)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
lib, err := stdlib.New(nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
actual, _ := CompileMarkdown(markdown, lib, filename, "", false)
|
|
test.EqualValues(string(html), actual, filename+" vs "+htmlname)
|
|
}
|
|
}
|
|
|
|
func TestExtractDocumentLeadingH1(t *testing.T) {
|
|
filename := "testdata/header.md"
|
|
|
|
markdown, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
actual := ExtractDocumentLeadingH1(markdown)
|
|
|
|
assert.Equal(t, "a", actual)
|
|
}
|