105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
|
package gemtext
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
type LineCase struct {
|
||
|
Str string
|
||
|
Preformatted bool
|
||
|
Want GemtextObject
|
||
|
}
|
||
|
// These tests suck. They're not really tests.
|
||
|
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},
|
||
|
},
|
||
|
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"},
|
||
|
},
|
||
|
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"},
|
||
|
},
|
||
|
}
|
||
|
for _, c := range cases {
|
||
|
got, _ := ParseLine(c.Str, c.Preformatted)
|
||
|
if got != c.Want {
|
||
|
t.Errorf("case %#v, got %#v", c, got)
|
||
|
}
|
||
|
}
|
||
|
}
|