refactoring tests to make this easier

main
Nick Dumas 1 year ago
parent 0b377a0500
commit 25f949fafd

@ -6,7 +6,7 @@ import (
"code.ndumas.com/ndumas/wikilink-parser"
)
func Test_ObsidianWikilinks_LinksIntext(t *testing.T) {
func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) {
tcs := []struct {
name string
in string
@ -14,7 +14,7 @@ func Test_ObsidianWikilinks_LinksIntext(t *testing.T) {
}{
{
name: "wikilink",
in: "this is a [[wikilink]]",
in: "[[wikilink]]",
expected: []wikilink.Lexeme{
{Typ: wikilink.LexText, Val: "this is a "},
{Typ: wikilink.LexOpenLink, Val: "[["},
@ -25,7 +25,7 @@ func Test_ObsidianWikilinks_LinksIntext(t *testing.T) {
},
{
name: "wikilink|display name",
in: "this is a [[wikilink|display name]]",
in: "is a [[wikilink|display name]]",
expected: []wikilink.Lexeme{
{Typ: wikilink.LexText, Val: "this is a "},
{Typ: wikilink.LexOpenLink, Val: "[["},
@ -457,8 +457,21 @@ func Test_ObsidianWikilinks_Basic(t *testing.T) {
}
for _, tc := range tcs {
tc := tc
t.Run(tc.name, func(t *testing.T) {
mut, test := mutateTestCase(tc, "", "")
t.Run(mut.name, test)
}
}
type tc struct {
name string
in string
expected []wikilink.Lexeme
}
func mutateTestCase(tc tc, prefix, suffix string) (tc, func(t *testing.T)) {
tc.in = prefix + tc.in
tc.in = tc.in + suffix
return tc, func(t *testing.T) {
// t.Parallel()
l := wikilink.Lex("testLexer", tc.in)
defer l.L.Sync()
@ -484,6 +497,5 @@ func Test_ObsidianWikilinks_Basic(t *testing.T) {
return
}
}
})
}
}

Loading…
Cancel
Save