mark/pkg/mark/markdown_test.go

56 lines
1.1 KiB
Go
Raw Normal View History

2021-02-02 17:12:08 +03:00
package mark
import (
2023-01-03 18:54:04 +01:00
"os"
2021-02-02 17:12:08 +03:00
"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")
2023-01-03 18:54:04 +01:00
markdown, err := os.ReadFile(filename)
2021-02-02 17:12:08 +03:00
if err != nil {
panic(err)
}
2023-01-03 18:54:04 +01:00
html, err := os.ReadFile(htmlname)
2021-02-02 17:12:08 +03:00
if err != nil {
panic(err)
}
lib, err := stdlib.New(nil)
if err != nil {
panic(err)
}
actual, _ := CompileMarkdown(markdown, lib, filename, "", 1.0, false)
2021-02-02 17:12:08 +03:00
test.EqualValues(string(html), actual, filename+" vs "+htmlname)
}
}
func TestExtractDocumentLeadingH1(t *testing.T) {
filename := "testdata/header.md"
2023-01-03 18:54:04 +01:00
markdown, err := os.ReadFile(filename)
if err != nil {
panic(err)
}
actual := ExtractDocumentLeadingH1(markdown)
assert.Equal(t, "a", actual)
}