This repository has been archived on 2020-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
go-gemtext/parser_test.go

181 lines
5.4 KiB
Go
Raw Normal View History

2020-11-12 10:22:43 +00:00
package gemtext
import "testing"
type LineCase struct {
Str string
Preformatted bool
Want GemtextObject
}
2020-11-12 10:55:29 +00:00
// These tests suck.
2020-11-12 10:22:43 +00:00
func TestParseLine(t *testing.T) {
cases := []LineCase{
LineCase{Str: "```", Preformatted: false, Want: GemtextObject{Type: PREFORMATTED_TOGGLE, Literal: "```"}},
LineCase{
Str: "This is a test of a normal text line.",
Preformatted: false,
Want: GemtextObject{
Type: TEXT,
Literal: "This is a test of a normal text line.",
Text: "This is a test of a normal text line."},
},
LineCase{
Str: "This is a test of a normal text line.",
Preformatted: true,
Want: GemtextObject{
Type: PREFORMATTED_TEXT,
Literal: "This is a test of a normal text line.",
Text: "This is a test of a normal text line."},
},
LineCase{
Str: "# heading 1",
Preformatted: false,
Want: GemtextObject{
Type: HEADING,
Literal: "# heading 1",
Text: "heading 1",
Level: 1},
},
LineCase{
Str: "## heading 2",
Preformatted: false,
Want: GemtextObject{
Type: HEADING,
Literal: "## heading 2",
Text: "heading 2",
Level: 2},
},
LineCase{
Str: "### heading 3",
Preformatted: false,
Want: GemtextObject{
Type: HEADING,
Literal: "### heading 3",
Text: "heading 3",
Level: 3},
},
2020-11-12 10:55:29 +00:00
LineCase{
Str: "###heading 3",
Preformatted: false,
Want: GemtextObject{
Type: HEADING,
Literal: "###heading 3",
Text: "heading 3",
Level: 3},
},
LineCase{
Str: "### heading 3",
Preformatted: false,
Want: GemtextObject{
Type: HEADING,
Literal: "### heading 3",
Text: "heading 3",
Level: 3},
},
2020-11-12 10:22:43 +00:00
LineCase{
Str: "#### heading 4",
Preformatted: false,
Want: GemtextObject{
Type: TEXT,
Literal: "#### heading 4",
Text: "#### heading 4"},
},
LineCase{
Str: "*list item",
Preformatted: false,
Want: GemtextObject{
Type: LIST,
Literal: "*list item",
Text: "list item"},
},
LineCase{
Str: "* list item",
Preformatted: false,
Want: GemtextObject{
Type: LIST,
Literal: "* list item",
Text: "list item"},
},
2020-11-12 10:55:29 +00:00
LineCase{
Str: "* list item",
Preformatted: false,
Want: GemtextObject{
Type: LIST,
Literal: "* list item",
Text: "list item"},
},
2020-11-12 10:22:43 +00:00
LineCase{
Str: ">quote",
Preformatted: false,
Want: GemtextObject{
Type: QUOTE,
Literal: ">quote",
Text: "quote"},
},
LineCase{
Str: "> quote",
Preformatted: false,
Want: GemtextObject{
Type: QUOTE,
Literal: "> quote",
Text: "quote"},
},
2020-11-12 10:55:29 +00:00
LineCase{
Str: "> quote",
Preformatted: false,
Want: GemtextObject{
Type: QUOTE,
Literal: "> quote",
Text: "quote"},
},
LineCase{
Str: "> quote",
Preformatted: true,
Want: GemtextObject{
Type: PREFORMATTED_TEXT,
Literal: "> quote",
Text: "> quote"},
},
LineCase{
Str: "=> https://example.com link",
Preformatted: true,
Want: GemtextObject{
Type: PREFORMATTED_TEXT,
Literal: "=> https://example.com link",
Text: "=> https://example.com link"},
},
LineCase{
Str: "=> https://example.com link",
Preformatted: false,
Want: GemtextObject{
Type: LINK,
Literal: "=> https://example.com link",
Text: "link",
Path: "https://example.com"},
},
LineCase{
Str: "=>https://example.com link",
Preformatted: false,
Want: GemtextObject{
Type: LINK,
Literal: "=>https://example.com link",
Text: "link",
Path: "https://example.com"},
},
LineCase{
Str: "\n",
Preformatted: false,
Want: GemtextObject{
Type: TEXT,
Literal: "\n",
Text: "\n"},
},
2020-11-12 10:22:43 +00:00
}
for _, c := range cases {
got, _ := ParseLine(c.Str, c.Preformatted)
if got != c.Want {
t.Errorf("case %#v, got %#v", c, got)
}
}
}