|
|
@ -1,6 +1,7 @@ |
|
|
|
package gemini_test |
|
|
|
|
|
|
|
import ( |
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"git.r23s.eu/wojciech/gm2html/gemini" |
|
|
@ -101,3 +102,101 @@ func TestParseQuoteLine(t *testing.T) { |
|
|
|
assert.Equal(t, test.content, l.Content(), test.line) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestFileParser(t *testing.T) { |
|
|
|
f := `# heading 1 |
|
|
|
## heading 2 |
|
|
|
### heading 3 |
|
|
|
> quote |
|
|
|
>quote |
|
|
|
* listitem |
|
|
|
* list item |
|
|
|
=> link |
|
|
|
=> https://google.com
|
|
|
|
=>https://example.com Example link
|
|
|
|
` + "```" + ` |
|
|
|
preformatted line 1 |
|
|
|
preformatted line 2 |
|
|
|
` + "```" + ` |
|
|
|
|
|
|
|
↑ that was an empty line |
|
|
|
now some regular text lines ` |
|
|
|
|
|
|
|
r := strings.NewReader(f) |
|
|
|
|
|
|
|
fp := gemini.NewFileParser(r) |
|
|
|
|
|
|
|
tts := []struct { |
|
|
|
t interface{} |
|
|
|
content string |
|
|
|
extra func(o interface{}) |
|
|
|
}{ |
|
|
|
{ |
|
|
|
gemini.HeadingLine{}, "heading 1", |
|
|
|
func(l interface{}) { |
|
|
|
assert.Equal(t, 1, l.(gemini.HeadingLine).Level(), "Incorrect heading level: %+v", l) |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
gemini.HeadingLine{}, "heading 2", |
|
|
|
func(l interface{}) { |
|
|
|
assert.Equal(t, 2, l.(gemini.HeadingLine).Level(), "Incorrect heading level: %+v", l) |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
gemini.HeadingLine{}, "heading 3", |
|
|
|
func(l interface{}) { |
|
|
|
assert.Equal(t, 3, l.(gemini.HeadingLine).Level(), "Incorrect heading level: %+v", l) |
|
|
|
}, |
|
|
|
}, |
|
|
|
{gemini.QuoteLine{}, "quote", nil}, |
|
|
|
{gemini.QuoteLine{}, "quote", nil}, |
|
|
|
{gemini.ListItemLine{}, "listitem", nil}, |
|
|
|
{gemini.ListItemLine{}, "list item", nil}, |
|
|
|
{ |
|
|
|
gemini.LinkLine{}, "=> link", |
|
|
|
func(l interface{}) { |
|
|
|
link := l.(gemini.LinkLine) |
|
|
|
assert.Equal(t, "link", link.Href()) |
|
|
|
assert.Equal(t, "link", link.Title()) |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
gemini.LinkLine{}, "=> https://google.com", |
|
|
|
func(l interface{}) { |
|
|
|
link := l.(gemini.LinkLine) |
|
|
|
assert.Equal(t, "https://google.com", link.Href()) |
|
|
|
assert.Equal(t, "https://google.com", link.Title()) |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
gemini.LinkLine{}, "=>https://example.com Example link", |
|
|
|
func(l interface{}) { |
|
|
|
link := l.(gemini.LinkLine) |
|
|
|
assert.Equal(t, "https://example.com", link.Href()) |
|
|
|
assert.Equal(t, "Example link", link.Title()) |
|
|
|
}, |
|
|
|
}, |
|
|
|
{gemini.PreformattingToggleLine{}, "", nil}, |
|
|
|
{gemini.PreformattedTextLine{}, "preformatted line 1", nil}, |
|
|
|
{gemini.PreformattedTextLine{}, " preformatted line 2 ", nil}, |
|
|
|
{gemini.PreformattingToggleLine{}, "", nil}, |
|
|
|
{gemini.TextLine{}, "", nil}, |
|
|
|
{gemini.TextLine{}, "↑ that was an empty line", nil}, |
|
|
|
{gemini.TextLine{}, "now some regular text lines", nil}, |
|
|
|
{nil, "", nil}, |
|
|
|
} |
|
|
|
|
|
|
|
for _, tt := range tts { |
|
|
|
line, err := fp.Next() |
|
|
|
assert.Nil(t, err) |
|
|
|
assert.IsType(t, tt.t, line) |
|
|
|
if tt.t != nil { |
|
|
|
assert.NotNil(t, line) |
|
|
|
assert.Equal(t, tt.content, line.Content()) |
|
|
|
} |
|
|
|
if tt.extra != nil { |
|
|
|
tt.extra(line) |
|
|
|
} |
|
|
|
} |
|
|
|
} |