Home

blog @449255bd0573331da000752186baad9297d77e98 - refs - log -
-
https://git.jolheiser.com/blog.git
My nonexistent blog
blog / blog_test.go
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package blog

import (
	"net/url"
	"testing"
	"time"

	"github.com/alecthomas/assert"
)

func TestParseArticle(t *testing.T) {
	var (
		raw = `+++
title = "Honk"
subtitle = "Bonk"
summary = """This
is
a
summary"""
time = 2024-02-16
tags = ["bocchi", "rocks"]
		
[author]
name = "Bocchi"
job = "Guitarist"
email = "bocchi@rock.s"

[[author.links]]
name = "website"
url = "https://example.com/bocchi"
+++

# Hello world

Beep boop`
		meta = ArticleMeta{
			Title:    "Honk",
			Subtitle: "Bonk",
			Summary: `This
is
a
summary`,
			Time: func() time.Time {
				t, _ := time.ParseInLocation("2006-01-02", "2024-02-16", time.Local)
				return t
			}(),
			Author: Author{
				Name:  "Bocchi",
				Job:   "Guitarist",
				Email: "bocchi@rock.s",
				Links: []Link{
					{
						Name: "website",
						URL: func() LinkURL {
							u, _ := url.Parse("https://example.com/bocchi")
							return LinkURL(*u)
						}(),
					},
				},
			},
			Tags: []string{"bocchi", "rocks"},
		}
		body = `<h1 id="hello-world">Hello world</h1>
<p>Beep boop</p>
`
	)

	article, err := parseArticle(raw)
	assert.NoError(t, err)
	assert.Equal(t, meta, article.ArticleMeta)
	assert.Equal(t, body, article.Content)
}