start writing some basic tests
This commit is contained in:
parent
e1e6b20bec
commit
3155f9bc47
|
@ -0,0 +1,104 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue