summaryrefslogtreecommitdiff
path: root/gemini/gemtext/parse_line_test.go
diff options
context:
space:
mode:
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