more front matter tests

This commit is contained in:
facundoolano 2024-02-10 12:30:09 -03:00
parent c762cbb909
commit 39af355deb

View file

@ -22,16 +22,55 @@ tags: ["software", "web"]
assertEqual(t, yaml["tags"].([]interface{})[1], "web")
}
func TestInvalidFrontMatterDelimiter(t *testing.T) {
// TODO
func TestNonFrontMatterDelimiter(t *testing.T) {
// not identified as front matter, leaving file as is
input := `+++
title: my new post
subtitle: a blog post
+++
<p>Hello World!</p>`
out, yaml, err := extractFrontMatter(strings.NewReader(input))
assertEqual(t, string(out), input)
assertEqual(t, err, nil)
assertEqual(t, len(yaml), 0)
// not first thing in file, leaving as is
input = `#+OPTIONS: toc:nil num:nil
---
title: my new post
subtitle: a blog post
tags: ["software", "web"]
---
<p>Hello World!</p>`
out, yaml, err = extractFrontMatter(strings.NewReader(input))
assertEqual(t, string(out), input)
assertEqual(t, err, nil)
assertEqual(t, len(yaml), 0)
}
func TestInvalidFrontMatterYaml(t *testing.T) {
// TODO
}
input := `---
title: my new post
subtitle: a blog post
tags: ["software", "web"]
`
func TestFrontMatterNotAtTop(t *testing.T) {
// TODO
_, _, err := extractFrontMatter(strings.NewReader(input))
assertEqual(t, err.Error(), "front matter not closed")
input = `---
title
tags: ["software", "web"]
---
<p>Hello World!</p>`
_, _, err = extractFrontMatter(strings.NewReader(input))
msg := strings.Split(err.Error(), ":")[0]
assertEqual(t, msg, "invalid yaml")
}
func TestRenderHtml(t *testing.T) {
@ -45,6 +84,6 @@ func TestRenderOrg(t *testing.T) {
// TODO move to assert package
func assertEqual(t *testing.T, a interface{}, b interface{}) {
if a != b {
t.Fatalf("%s != %s", a, b)
t.Fatalf("%v != %v", a, b)
}
}