adoc/parser/parser_test.go

65 lines
1.2 KiB
Go
Raw Permalink Normal View History

2022-03-15 15:16:15 +01:00
package parser_test
2022-03-10 06:10:36 +01:00
import (
"strings"
"testing"
2024-09-15 12:07:22 +02:00
"go-mod.ewintr.nl/adoc/document"
"go-mod.ewintr.nl/adoc/element"
"go-mod.ewintr.nl/adoc/parser"
"go-mod.ewintr.nl/go-kit/test"
2022-03-10 06:10:36 +01:00
)
func TestParser(t *testing.T) {
for _, tc := range []struct {
name string
input string
2022-06-11 09:30:22 +02:00
exp *document.Document
2022-03-10 06:10:36 +01:00
}{
{
name: "empty",
2022-06-11 09:30:22 +02:00
exp: document.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`,
2022-06-11 09:30:22 +02:00
exp: &document.Document{
2022-03-29 06:53:36 +02:00
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())
})
}
}