2020-11-12 21:02:05 +00:00
package gemtext
import "testing"
type PrefixCase struct {
Prefix string
Link string
Want string
}
func TestAddPrefix ( t * testing . T ) {
cases := [ ] PrefixCase {
PrefixCase { Prefix : "" , Link : "/test/" , Want : "/test" } ,
PrefixCase { Prefix : "https:itwont.work/" , Link : "/test/stuff.gmi" , Want : "https:itwont.work/test/stuff.gmi" } ,
PrefixCase { Prefix : "https:itwont.work/" , Link : "test/stuff.gmi" , Want : "test/stuff.gmi" } ,
PrefixCase { Prefix : "" , Link : "" , Want : "" } ,
PrefixCase { Prefix : "https:itwont.work/" , Link : "" , Want : "" } ,
}
for _ , c := range cases {
got := addPrefix ( c . Prefix , c . Link )
if got != c . Want {
t . Errorf ( "Case %#v, Got %#v" , c , got )
}
}
}
type LineRenderCase struct {
In GemtextObject
Want string
}
func TestRenderHeading ( t * testing . T ) {
cases := [ ] LineRenderCase {
LineRenderCase { In : GemtextObject { Type : HEADING , Level : 1 , Text : "Hello" } , Want : "# Hello" } , // I'm not adding a Literal to these cases.
LineRenderCase { In : GemtextObject { Type : HEADING , Level : 2 , Text : "" } , Want : "## " } ,
LineRenderCase { In : GemtextObject { Type : HEADING , Level : 2 , Text : "Hello" } , Want : "## Hello" } ,
LineRenderCase { In : GemtextObject { Type : HEADING , Level : 3 , Text : "This contains spaces" } , Want : "### This contains spaces" } ,
}
for _ , c := range cases {
got , _ := RenderHeading ( c . In )
if got != c . Want {
t . Errorf ( "Case %#v, Got %#v" , c , got )
}
}
2020-11-14 19:29:55 +00:00
}
func TestRenderHTML ( t * testing . T ) {
2020-11-14 19:51:21 +00:00
out , _ := RenderHTML ( & testdocumenttree )
2020-11-14 19:29:55 +00:00
want := "<h1>Document</h1><p>This is paragraph text & It exists</p><a href=\"https://example.com\">example.com</a><br /><ul><li>List Item 1</li><li>List Item 2</li></ul><pre>this should be preformatted.\n=> https://example.com Not a link\n</pre><ul><li>A single list item</li></ul><pre>one line of pre\n</pre><pre></pre><blockquote>Something\n- someone\n</blockquote>"
if out != want {
t . Errorf ( "Got %#v want %#v" , out , want )
}
2020-11-12 21:02:05 +00:00
}