summaryrefslogtreecommitdiff
path: root/gemini/gemtext/sub_test.go
blob: f080705c8dac5a7a70f3b76148ad7eb1221a3f07 (plain)
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
package gemtext

import (
	"bytes"
	"net/url"
	"testing"
)

func TestGemsubToAtom(t *testing.T) {
	tests := []struct {
		url    string
		input  string
		output string
	}{
		{
			url: "gemini://sombodys.site/a/page",
			input: `
# This is a gemlog page


## with a subtitle after empty lines

=> ./first-post.gmi 2023-08-25 - This is my first post
`[1:],
			output: `
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>gemini://sombodys.site/a/page</id>
  <link href="gemini://sombodys.site/a/page"/>
  <title>This is a gemlog page</title>
  <subtitle>with a subtitle after empty lines</subtitle>
  <updated>2023-08-25T12:00:00Z</updated>
  <entry>
    <id>./first-post.gmi</id>
    <link rel="alternate" href="./first-post.gmi"/>
    <title>This is my first post</title>
    <updated>2023-08-25T12:00:00Z</updated>
  </entry>
</feed>
`[1:],
		},
	}

	for _, test := range tests {
		t.Run(test.url, func(t *testing.T) {
			doc, err := Parse(bytes.NewBufferString(test.input))
			if err != nil {
				t.Fatal(err)
			}
			loc, err := url.Parse(test.url)
			if err != nil {
				t.Fatal(err)
			}
			out := &bytes.Buffer{}
			if err := GmisubToAtom(doc, *loc, out); err != nil {
				t.Fatal(err)
			}
			if out.String() != test.output {
				t.Fatal("mismatched output")
			}
		})
	}
}