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

Loading…
Cancel
Save