From 0fe9ec0c90bfe82f637f1897e47fec07f90805ec Mon Sep 17 00:00:00 2001 From: tjpcc Date: Thu, 31 Aug 2023 20:16:16 -0600 Subject: move gemtext->atom conversion into package atomconv like the other converters --- gemini/gemtext/sub_test.go | 138 --------------------------------------------- 1 file changed, 138 deletions(-) delete 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 deleted file mode 100644 index 9e0fcc8..0000000 --- a/gemini/gemtext/sub_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package gemtext - -import ( - "bytes" - "context" - "fmt" - "io" - "net/url" - "testing" - - "tildegit.org/tjp/sliderule" - "tildegit.org/tjp/sliderule/gemini" - "tildegit.org/tjp/sliderule/internal/types" -) - -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) - } - out := &bytes.Buffer{} - if err := GmisubToAtom(doc, *loc, out); err != nil { - t.Fatal(err) - } - if out.String() != test.output { - t.Fatal("mismatched output") - } - }) - } -} - -func TestAutoAtom(t *testing.T) { - rout := &sliderule.Router{} - - rout.Route("/foo.gmi", types.HandlerFunc(func(ctx context.Context, request *types.Request) *types.Response { - return gemini.Success("text/gemini", bytes.NewBufferString(` -# This is my gemini page - -## a subtitle - -=> ./first-post.gmi 2023-05-17 - My first post -=> ./second-post.gmi 2023-06-02 second-ever post -`[1:])) - })) - - rout.Route("/bar.gmi", types.HandlerFunc(func(ctx context.Context, request *types.Request) *types.Response { - return gemini.Success("text/gemini", bytes.NewBufferString(` -# Another homepage - -=> ./first-post.gmi 2023-05-17 - first post -=> ./second-post.gmi 2023-06-02 second post -`[1:])) - })) - - h := AutoAtom(rout.Handler()) - - response := h.Handle(context.Background(), &types.Request{URL: &url.URL{ - Scheme: "gemini", - Host: "127.0.0.1", - Path: "/foo.gmi.atom", - }}) - if response.Status != gemini.StatusSuccess { - t.Fatal("bad response code") - } - - result, err := io.ReadAll(response.Body) - if err != nil { - t.Fatal(err) - } - - target := ` - - - gemini://127.0.0.1/foo.gmi.atom - - This is my gemini page - a subtitle - 2023-06-02T12:00:00Z - - ./first-post.gmi - - My first post - 2023-05-17T12:00:00Z - - - ./second-post.gmi - - second-ever post - 2023-06-02T12:00:00Z - - -`[1:] - if string(result) != target { - fmt.Println(target) - fmt.Println(string(result)) - t.Fatal("response body") - } -} -- cgit v1.2.3