adoc/element/codeblock_test.go

88 lines
1.5 KiB
Go
Raw Normal View History

2022-03-15 15:16:15 +01:00
package element_test
2022-03-10 06:10:36 +01:00
import (
"strings"
"testing"
"ewintr.nl/adoc"
2022-03-15 15:16:15 +01:00
"ewintr.nl/adoc/element"
"ewintr.nl/adoc/parser"
2022-03-10 06:10:36 +01:00
"ewintr.nl/go-kit/test"
)
func TestCodeBlock(t *testing.T) {
for _, tc := range []struct {
name string
input string
exp *adoc.ADoc
}{
{
name: "empty",
input: `----
----`,
exp: &adoc.ADoc{
Attributes: map[string]string{},
2022-03-15 15:16:15 +01:00
Content: []element.Element{element.CodeBlock{}},
2022-03-10 06:10:36 +01:00
},
},
{
name: "with newlines",
input: `----
code
more
----`,
exp: &adoc.ADoc{
Attributes: map[string]string{},
2022-03-15 15:16:15 +01:00
Content: []element.Element{element.CodeBlock{
element.Word("code"),
element.WhiteSpace("\n\n"),
element.Word("more"),
element.WhiteSpace("\n"),
2022-03-10 06:10:36 +01:00
}},
},
},
2022-03-29 06:53:36 +02:00
{
name: "with newline at end",
input: `----
code
----
`,
exp: &adoc.ADoc{
Attributes: map[string]string{},
Content: []element.Element{element.CodeBlock{
element.Word("code"),
element.WhiteSpace("\n"),
}},
},
},
2022-03-10 06:10:36 +01:00
{
name: "missing end",
input: `----
code
more
`,
exp: &adoc.ADoc{
Attributes: map[string]string{},
2022-03-15 15:16:15 +01:00
Content: []element.Element{
element.Paragraph{[]element.Element{
element.Word("----"),
element.WhiteSpace("\n"),
element.Word("code"),
}},
element.Paragraph{[]element.Element{
element.Word("more"),
element.WhiteSpace("\n"),
}},
2022-03-10 06:10:36 +01:00
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
2022-03-15 15:16:15 +01:00
par := parser.New(strings.NewReader(tc.input))
2022-03-10 06:10:36 +01:00
test.Equals(t, tc.exp, par.Parse())
})
}
}