summaryrefslogtreecommitdiff
path: root/gemini/gemtext/parse_line_test.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-04-29 18:10:50 -0600
committertjpcc <tjp@ctrl-c.club>2023-04-29 18:10:50 -0600
commit3ff04cf88571f8ed1aca78da4efe4929ad583ca6 (patch)
treebb2bc248f4049d3c7833a8d6661d17c91f03e642 /gemini/gemtext/parse_line_test.go
parent9e09825537e4ae91119987f979ec4272d1727a2e (diff)
spartan =: prompt line support in gemtext
Diffstat (limited to 'gemini/gemtext/parse_line_test.go')
-rw-r--r--gemini/gemtext/parse_line_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/gemini/gemtext/parse_line_test.go b/gemini/gemtext/parse_line_test.go
index a07fa3b..82b0c28 100644
--- a/gemini/gemtext/parse_line_test.go
+++ b/gemini/gemtext/parse_line_test.go
@@ -57,6 +57,57 @@ func TestParseLinkLine(t *testing.T) {
}
}
+func TestParsePromptLine(t *testing.T) {
+ tests := []struct {
+ input string
+ url string
+ label string
+ }{
+ {
+ input: "=: gemini.ctrl-c.club/~tjp/ home page\r\n",
+ url: "gemini.ctrl-c.club/~tjp/",
+ label: "home page",
+ },
+ {
+ input: "=: gemi.dev/\n",
+ url: "gemi.dev/",
+ },
+ {
+ input: "=: /gemlog/foobar 2023-01-13 - Foo Bar\n",
+ url: "/gemlog/foobar",
+ label: "2023-01-13 - Foo Bar",
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.input, func(t *testing.T) {
+ line := gemtext.ParseLine([]byte(test.input))
+ if line == nil {
+ t.Fatal("ParseLine() returned nil line")
+ }
+ if string(line.Raw()) != string(test.input) {
+ t.Error("Raw() does not match input")
+ }
+
+ if line.Type() != gemtext.LineTypePrompt{
+ t.Errorf("expected LineTypePrompt, got %d", line.Type())
+ }
+ link, ok := line.(gemtext.PromptLine)
+ if !ok {
+ t.Fatalf("expected a PromptLine, got %T", line)
+ }
+
+ if link.URL() != test.url {
+ t.Errorf("expected url %q, got %q", test.url, link.URL())
+ }
+
+ if link.Label() != test.label {
+ t.Errorf("expected label %q, got %q", test.label, link.Label())
+ }
+ })
+ }
+}
+
func TestParsePreformatToggleLine(t *testing.T) {
tests := []struct {
input string