2022-03-15 15:16:15 +01:00
|
|
|
package parser_test
|
2022-03-10 06:10:36 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"ewintr.nl/adoc"
|
2022-03-29 06:53:36 +02:00
|
|
|
"ewintr.nl/adoc/element"
|
2022-03-15 15:16:15 +01:00
|
|
|
"ewintr.nl/adoc/parser"
|
2022-03-10 06:10:36 +01:00
|
|
|
"ewintr.nl/go-kit/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParser(t *testing.T) {
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
input string
|
|
|
|
exp *adoc.ADoc
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty",
|
2022-03-29 06:13:52 +02:00
|
|
|
exp: adoc.New(),
|
2022-03-10 06:10:36 +01:00
|
|
|
},
|
2022-03-29 06:53:36 +02:00
|
|
|
{
|
|
|
|
name: "codeblock paragraph edge",
|
|
|
|
input: `= some title
|
|
|
|
|
|
|
|
----
|
|
|
|
a code block
|
|
|
|
----
|
|
|
|
|
|
|
|
And then some text`,
|
|
|
|
exp: &adoc.ADoc{
|
|
|
|
Title: "some title",
|
|
|
|
Attributes: map[string]string{},
|
|
|
|
Content: []element.Element{
|
|
|
|
element.CodeBlock{
|
|
|
|
element.Word("a"),
|
|
|
|
element.WhiteSpace(" "),
|
|
|
|
element.Word("code"),
|
|
|
|
element.WhiteSpace(" "),
|
|
|
|
element.Word("block"),
|
|
|
|
element.WhiteSpace("\n"),
|
|
|
|
},
|
|
|
|
element.Paragraph{
|
|
|
|
Elements: []element.Element{
|
|
|
|
element.Word("And"),
|
|
|
|
element.WhiteSpace(" "),
|
|
|
|
element.Word("then"),
|
|
|
|
element.WhiteSpace(" "),
|
|
|
|
element.Word("some"),
|
|
|
|
element.WhiteSpace(" "),
|
|
|
|
element.Word("text"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
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())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|