From 4c4dba9ba1e91ab44fcd21c50c6df62a19cfd9e1 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Fri, 25 Aug 2023 14:52:36 -0600 Subject: gemtext -> atom converter * add GemsubToAtom converter function * add Server.Handler method and implementations fixes #1 --- gemini/gemtext/sub_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 gemini/gemtext/sub_test.go (limited to 'gemini/gemtext/sub_test.go') diff --git a/gemini/gemtext/sub_test.go b/gemini/gemtext/sub_test.go new file mode 100644 index 0000000..8bba682 --- /dev/null +++ b/gemini/gemtext/sub_test.go @@ -0,0 +1,60 @@ +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: ` + + + gemini://sombodys.site/a/page + + This is a gemlog page + with a subtitle after empty lines + 2023-08-25T12:00:00Z + + ./first-post.gmi + + This is my first post + 2023-08-25T12:00:00Z + + +`[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) + } + xml := GemsubToAtom(doc, *loc) + if xml != test.output { + t.Fatal("mismatched output") + } + }) + } +} -- cgit v1.2.3