157 lines
2.8 KiB
Go
157 lines
2.8 KiB
Go
package format_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"ewintr.nl/adoc/element"
|
|
"ewintr.nl/adoc/format"
|
|
"ewintr.nl/adoc/parser"
|
|
"ewintr.nl/go-kit/test"
|
|
)
|
|
|
|
func TestAsciiDoc(t *testing.T) {
|
|
input := `= A Title
|
|
|
|
Some document
|
|
|
|
With some text.
|
|
|
|
`
|
|
|
|
doc := parser.New(strings.NewReader(input)).Parse()
|
|
test.Equals(t, input, format.AsciiDoc(doc))
|
|
}
|
|
|
|
func TestAsciiDocFragment(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: "pararaphs",
|
|
input: element.Paragraph{
|
|
Elements: []element.Element{
|
|
element.Word("a"),
|
|
element.WhiteSpace(" "),
|
|
element.Word("word"),
|
|
},
|
|
},
|
|
exp: "a word\n\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.WhiteSpace(" "),
|
|
element.Strong{
|
|
element.WhiteSpace(" "),
|
|
element.Word("and"),
|
|
element.WhiteSpace(" "),
|
|
element.Word("strong"),
|
|
},
|
|
element.WhiteSpace(" "),
|
|
element.Word("too"),
|
|
},
|
|
},
|
|
exp: "normal text * and strong* too\n\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: `http://example.com[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: `* item 1
|
|
* item 2
|
|
|
|
`,
|
|
},
|
|
{
|
|
name: "code block",
|
|
input: element.CodeBlock{
|
|
element.Word("some"),
|
|
element.WhiteSpace(" "),
|
|
element.Word("text"),
|
|
element.WhiteSpace("\n"),
|
|
element.Word("<p>with</p>"),
|
|
element.WhiteSpace("\t"),
|
|
element.Word("formatting"),
|
|
},
|
|
exp: `----
|
|
some text
|
|
<p>with</p> formatting
|
|
----
|
|
|
|
`,
|
|
},
|
|
{
|
|
name: "subtitle",
|
|
input: element.SubTitle("a subtitle"),
|
|
exp: "== a subtitle\n\n",
|
|
},
|
|
{
|
|
name: "subsubtitle",
|
|
input: element.SubSubTitle("a subsubtitle"),
|
|
exp: "=== a subsubtitle\n\n",
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
test.Equals(t, tc.exp, format.AsciiDocFragment(tc.input))
|
|
})
|
|
}
|
|
}
|