package formatter_test import ( "strings" "testing" "ewintr.nl/adoc/element" "ewintr.nl/adoc/formatter" "ewintr.nl/adoc/parser" "ewintr.nl/go-kit/test" ) func TestHTML(t *testing.T) { input := `= A Title Some document With some text.` exp := `
Some document
With some text.
` doc := parser.New(strings.NewReader(input)).Parse() test.Equals(t, exp, formatter.NewHTML().Format(doc)) } func TestHTMLFragment(t *testing.T) { for _, tc := range []struct { name string input element.Element exp string }{ { name: "whitespace", input: element.WhiteSpace("\n"), exp: " ", }, { name: "word", input: element.Word("word"), exp: "word", }, { name: "word with html", input: element.Word("a word
\n", }, { name: "strong", input: element.Strong{ element.Word("something"), element.WhiteSpace(" "), element.Word("strong"), }, exp: "something strong", }, { name: "nested", input: element.Paragraph{ Elements: []element.Element{ element.Word("normal"), element.WhiteSpace(" "), element.Word("text"), element.Strong{ element.WhiteSpace(" "), element.Word("and"), element.WhiteSpace(" "), element.Word("strong"), }, element.WhiteSpace(" "), element.Word("too"), }, }, exp: "normal text and strong too
\n", }, { name: "emphasis", input: element.Emphasis{ element.Word("yes"), }, exp: "yes", }, { name: "code", input: element.Code{ element.Word("simple"), }, exp: "simple
",
},
{
name: "link",
input: element.Link{
URL: "http://example.com",
Title: "an example",
},
exp: `an example`,
},
{
name: "list",
input: element.List{
element.ListItem{
element.Word("item"),
element.WhiteSpace(" "),
element.Word("1"),
},
element.ListItem{
element.Word("item"),
element.WhiteSpace(" "),
element.Word("2"),
},
},
exp: `with
"), element.WhiteSpace("\t"), element.Word("formatting"), }, exp: `some text
<p>with</p> formatting
`,
},
{
name: "subtitle",
input: element.SubTitle("a subtitle"),
exp: "