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	"testing"
 9)
10
11func TestSimpleMetadata(t *testing.T) {
12	res, meta := mdToHTML("index.md", []byte("---\ncoucou: hello\n---\n#Title"), nil)
13	want := "<dl><dt>coucou</dt><dd>hello</dd></dl>\n\n<p>#Title</p>\n"
14	if res != want {
15		t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
16	}
17	if val, ok := meta["coucou"]; !ok || val != "hello" {
18		t.Errorf("meta coucou should be hello but was %s", val)
19	}
20}
21
22func TestMetadataNoValue(t *testing.T) {
23	res, _ := mdToHTML("index.md", []byte("---\ncoucou:\n---\n#Title"), nil)
24	want := "<dl><dt>coucou</dt><dd></dd></dl>\n\n<p>#Title</p>\n"
25	if res != want {
26		t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
27	}
28}
29
30func TestBreakPage(t *testing.T) {
31	res, _ := mdToHTML("index.md", []byte("# Title\n\nHello world!\n\n---\n\nKiss"), nil)
32	want := "<h1 id=\"title\">Title</h1>\n\n<p>Hello world!</p>\n\n<hr>\n\n<p>Kiss</p>\n"
33	if res != want {
34		t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
35	}
36}
37
38func TestBreakPageAndMeta(t *testing.T) {
39	res, _ := mdToHTML("index.md", []byte("---\ncoucou:\n---\n# Title\n\nHello world!\n\n---\n\nKiss"), nil)
40	want := "<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"
41	if res != want {
42		t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
43	}
44}
45
46func TestLink(t *testing.T) {
47	res, _ := mdToHTML("/issues/1.md", []byte("[other](../2.md)"), nil)
48	want := "<p><a href=\"/2.html\">other</a></p>\n"
49	if res != want {
50		t.Errorf("---\n%s\n--- want ---\n%s\n---", res, want)
51	}
52}