GitRoot
craft your forge, build your project, grow your community freely
1// SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
2//
3// SPDX-License-Identifier: EUPL-1.2
4
5package main
6
7import (
8 "bytes"
9 "testing"
10)
11
12func TestSimpleMetadata(t *testing.T) {
13 res := mdToHTML([]byte("---\ncoucou: hello\n---\n#Title"), nil)
14 want := []byte("<dl><dt>coucou</dt><dd>hello</dd></dl>\n\n<p>#Title</p>\n")
15 if !bytes.Equal(res, want) {
16 t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
17 }
18}
19
20func TestMetadataNoValue(t *testing.T) {
21 res := mdToHTML([]byte("---\ncoucou:\n---\n#Title"), nil)
22 want := []byte("<dl><dt>coucou</dt><dd></dd></dl>\n\n<p>#Title</p>\n")
23 if !bytes.Equal(res, want) {
24 t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
25 }
26}
27
28func TestBreakPage(t *testing.T) {
29 res := mdToHTML([]byte("# Title\n\nHello world!\n\n---\n\nKiss"), nil)
30 want := []byte("<h1 id=\"title\">Title</h1>\n\n<p>Hello world!</p>\n\n<hr>\n\n<p>Kiss</p>\n")
31 if !bytes.Equal(res, want) {
32 t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
33 }
34}
35
36func TestBreakPageAndMeta(t *testing.T) {
37 res := mdToHTML([]byte("---\ncoucou:\n---\n# Title\n\nHello world!\n\n---\n\nKiss"), nil)
38 want := []byte("<dl><dt>coucou</dt><dd></dd></dl>\n\n<h1 id=\"title\">Title</h1>\n\n<p>Hello world!</p>\n\n<hr>\n\n<p>Kiss</p>\n")
39 if !bytes.Equal(res, want) {
40 t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
41 }
42}